fix: close app on exit and add option to hide window
This commit is contained in:
parent
7950f1ec26
commit
8dfd60df19
2 changed files with 14 additions and 11 deletions
|
@ -46,7 +46,6 @@ class _AppState extends State<App> with WindowListener, TrayListener {
|
|||
|
||||
Future<void> initWindowManager() async {
|
||||
windowManager.addListener(this);
|
||||
await windowManager.setPreventClose(true);
|
||||
}
|
||||
|
||||
Future<void> initTrayManager() async {
|
||||
|
@ -154,11 +153,6 @@ class _AppState extends State<App> with WindowListener, TrayListener {
|
|||
};
|
||||
}
|
||||
|
||||
@override
|
||||
void onWindowClose() async {
|
||||
await windowManager.hide();
|
||||
}
|
||||
|
||||
@override
|
||||
void onWindowResize() {
|
||||
WindowListenerService.instance.onWindowResize().ignore();
|
||||
|
@ -187,11 +181,16 @@ class _AppState extends State<App> with WindowListener, TrayListener {
|
|||
|
||||
@override
|
||||
void onTrayMenuItemClick(MenuItem menuItem) {
|
||||
if (menuItem.key == 'show_window') {
|
||||
windowManager.show();
|
||||
} else if (menuItem.key == 'exit_app') {
|
||||
windowManager.setPreventClose(false);
|
||||
windowManager.close();
|
||||
switch (menuItem.key) {
|
||||
case 'hide_window':
|
||||
windowManager.hide();
|
||||
break;
|
||||
case 'show_window':
|
||||
windowManager.show();
|
||||
break;
|
||||
case 'exit_app':
|
||||
windowManager.close();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,6 +43,10 @@ Future<void> initSystemTray() async {
|
|||
await trayManager.setIcon(path);
|
||||
Menu menu = Menu(
|
||||
items: [
|
||||
MenuItem(
|
||||
key: 'hide_window',
|
||||
label: 'Hide Window',
|
||||
),
|
||||
MenuItem(
|
||||
key: 'show_window',
|
||||
label: 'Show Window',
|
||||
|
|
Loading…
Reference in a new issue