mirror of
https://github.com/wanghongenpin/proxypin.git
synced 2026-05-16 15:56:51 +08:00
feat: add minimize to tray functionality (#711)
This commit is contained in:
@@ -104,10 +104,7 @@ class AppConfiguration {
|
||||
double panelRatio = 0.3;
|
||||
|
||||
/// 关闭窗口时最小化到系统托盘
|
||||
bool minimizeToTray = false;
|
||||
|
||||
/// 首次关闭时是否已经提示过最小化到托盘
|
||||
bool? minimizeToTrayPromptShown;
|
||||
bool? minimizeToTray;
|
||||
|
||||
AppConfiguration._();
|
||||
|
||||
@@ -206,12 +203,9 @@ class AppConfiguration {
|
||||
_theme.color = config['themeColor'] ?? "Blue";
|
||||
|
||||
upgradeNoticeV27 = config['upgradeNoticeV27'] ?? true;
|
||||
_language = config['language'] == null
|
||||
? null
|
||||
: Locale.fromSubtags(
|
||||
languageCode: config['language'],
|
||||
scriptCode: config['languageScript']
|
||||
);
|
||||
_language = config['language'] == null
|
||||
? null
|
||||
: Locale.fromSubtags(languageCode: config['language'], scriptCode: config['languageScript']);
|
||||
pipEnabled.value = config['pipEnabled'] ?? true;
|
||||
pipIcon.value = config['pipIcon'] ?? false;
|
||||
headerExpanded = config['headerExpanded'] ?? true;
|
||||
@@ -228,8 +222,7 @@ class AppConfiguration {
|
||||
if (config['panelRatio'] != null) {
|
||||
panelRatio = config['panelRatio'];
|
||||
}
|
||||
minimizeToTray = config['minimizeToTray'] ?? false;
|
||||
minimizeToTrayPromptShown = config['minimizeToTrayPromptShown'];
|
||||
minimizeToTray = config['minimizeToTray'];
|
||||
} catch (e) {
|
||||
logger.e(e);
|
||||
}
|
||||
@@ -275,7 +268,6 @@ class AppConfiguration {
|
||||
"windowPosition": windowPosition == null ? null : {"dx": windowPosition?.dx, "dy": windowPosition?.dy},
|
||||
if (Platforms.isDesktop()) 'panelRatio': panelRatio,
|
||||
if (Platforms.isDesktop()) 'minimizeToTray': minimizeToTray,
|
||||
if (Platforms.isDesktop() && minimizeToTrayPromptShown != null) 'minimizeToTrayPromptShown': minimizeToTrayPromptShown,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ class _PreferenceState extends State<Preference> {
|
||||
subtitle: Text(localizations.minimizeToTraySubtitle, style: subtitleStyle),
|
||||
trailing: SwitchWidget(
|
||||
scale: 0.75,
|
||||
value: appConfiguration.minimizeToTray,
|
||||
value: appConfiguration.minimizeToTray ?? false,
|
||||
onChanged: (value) {
|
||||
appConfiguration.minimizeToTray = value;
|
||||
appConfiguration.flushConfig();
|
||||
|
||||
@@ -106,14 +106,14 @@ class _SocketLaunchState extends State<SocketLaunch> with WindowListener, Widget
|
||||
|
||||
Future<void> _handleWindowClose() async {
|
||||
final appConfiguration = AppConfiguration.current;
|
||||
if (Platforms.isDesktop() && appConfiguration?.minimizeToTray == true) {
|
||||
if (appConfiguration?.minimizeToTrayPromptShown == null) {
|
||||
if (Platforms.isDesktop() && appConfiguration?.minimizeToTray == null || appConfiguration?.minimizeToTray == true) {
|
||||
if (appConfiguration?.minimizeToTray == null) {
|
||||
final minimize = await _showTrayClosePrompt();
|
||||
if (!mounted) {
|
||||
return;
|
||||
}
|
||||
|
||||
appConfiguration?.minimizeToTrayPromptShown = true;
|
||||
appConfiguration?.minimizeToTray = minimize;
|
||||
await appConfiguration?.flushConfig();
|
||||
|
||||
if (!minimize) {
|
||||
@@ -129,6 +129,7 @@ class _SocketLaunchState extends State<SocketLaunch> with WindowListener, Widget
|
||||
logger.e('show to tray failed, fallback to exit', error: e);
|
||||
}
|
||||
}
|
||||
|
||||
await appExit();
|
||||
}
|
||||
|
||||
@@ -139,9 +140,7 @@ class _SocketLaunchState extends State<SocketLaunch> with WindowListener, Widget
|
||||
builder: (ctx) {
|
||||
return AlertDialog(
|
||||
title: Text(localizations.minimizeToTrayTitle),
|
||||
content: SizedBox(
|
||||
width: 320,
|
||||
child: Text(maxLines: 3, localizations.trayClosePromptContent)),
|
||||
content: SizedBox(width: 320, child: Text(maxLines: 3, localizations.trayClosePromptContent)),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(ctx).pop(false),
|
||||
@@ -181,7 +180,10 @@ class _SocketLaunchState extends State<SocketLaunch> with WindowListener, Widget
|
||||
|
||||
@override
|
||||
Future<AppExitResponse> didRequestAppExit() async {
|
||||
await appExit();
|
||||
bool isPreventClose = await windowManager.isPreventClose();
|
||||
if (!isPreventClose || Platform.isMacOS) {
|
||||
await appExit();
|
||||
}
|
||||
return super.didRequestAppExit();
|
||||
}
|
||||
|
||||
|
||||
@@ -48,6 +48,7 @@ class DesktopSupport {
|
||||
await windowManager.focus();
|
||||
});
|
||||
|
||||
windowManager.addListener(WindowChangeListener(appConfiguration));
|
||||
registerMethodHandler();
|
||||
} catch (e) {
|
||||
logger.e("Error during desktop initialization: $e");
|
||||
|
||||
Reference in New Issue
Block a user