diff --git a/lib/features/system_tray/controller/system_tray_controller.dart b/lib/features/system_tray/controller/system_tray_controller.dart index 16704ec2..40557a04 100644 --- a/lib/features/system_tray/controller/system_tray_controller.dart +++ b/lib/features/system_tray/controller/system_tray_controller.dart @@ -50,12 +50,10 @@ class SystemTrayController extends _$SystemTrayController Future _updateTray() async { final t = ref.watch(translationsProvider); - final isVisible = await windowManager.isVisible(); final trayMenu = Menu( items: [ - MenuItem.checkbox( + MenuItem( label: t.tray.dashboard, - checked: isVisible, onClick: handleClickShowApp, ), if (mode != null) ...[ @@ -85,6 +83,11 @@ class SystemTrayController extends _$SystemTrayController await trayManager.setContextMenu(trayMenu); } + @override + Future onTrayIconMouseDown() async { + await windowManager.show(); + } + @override Future onTrayIconRightMouseDown() async { super.onTrayIconRightMouseDown(); @@ -92,11 +95,8 @@ class SystemTrayController extends _$SystemTrayController } Future handleClickShowApp(MenuItem menuItem) async { - if (menuItem.checked == true) { - await windowManager.close(); - } else { - await windowManager.show(); - } + if (await windowManager.isVisible()) return; + await windowManager.show(); } Future handleClickModeItem( diff --git a/lib/services/window_manager_service.dart b/lib/services/window_manager_service.dart index 0cf888a5..01794f1c 100644 --- a/lib/services/window_manager_service.dart +++ b/lib/services/window_manager_service.dart @@ -11,9 +11,15 @@ class WindowManagerService with WindowListener { center: true, ); await windowManager.waitUntilReadyToShow(windowOptions); + await windowManager.setPreventClose(true); windowManager.addListener(this); } + @override + Future onWindowClose() async { + await windowManager.hide(); + } + void dispose() { windowManager.removeListener(this); }