Skip to content

Commit de7ebd5

Browse files
Honour the close setting when quitting from the tray canonical#3919
Previously, the tray menu action "Quit" caused a function to immediately destroy the window. Now the usual process of closing window is taking place. Signed-off-by: Artem <[email protected]>
1 parent dbf3c7c commit de7ebd5

File tree

2 files changed

+35
-27
lines changed

2 files changed

+35
-27
lines changed

src/client/gui/lib/main.dart

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,18 @@ class _AppState extends ConsumerState<App> with WindowListener {
166166
final daemonAvailable = ref.read(daemonAvailableProvider);
167167
final vmsRunning =
168168
ref.read(vmStatusesProvider).values.contains(Status.RUNNING);
169-
if (!daemonAvailable || !vmsRunning) windowManager.destroy();
169+
final closeJob = ref.read(guiSettingProvider(onAppCloseKey));
170+
171+
// nothing to do
172+
if (!daemonAvailable || !vmsRunning || closeJob == 'nothing') {
173+
windowManager.destroy();
174+
return;
175+
}
176+
177+
// checking the need to restore the window
178+
if (!await windowManager.isVisible() || await windowManager.isMinimized()) {
179+
windowManager.showAndRestore();
180+
}
170181

171182
stopAllInstances() {
172183
final notificationsNotifier = ref.read(notificationsProvider.notifier);
@@ -181,31 +192,28 @@ class _AppState extends ConsumerState<App> with WindowListener {
181192
);
182193
}
183194

184-
switch (ref.read(guiSettingProvider(onAppCloseKey))) {
185-
case 'nothing':
186-
windowManager.destroy();
187-
case 'stop':
188-
stopAllInstances();
189-
default:
190-
showDialog(
191-
context: context,
192-
barrierDismissible: false,
193-
builder: (context) => BeforeQuitDialog(
194-
onStop: (remember) {
195-
ref
196-
.read(guiSettingProvider(onAppCloseKey).notifier)
197-
.set(remember ? 'stop' : 'ask');
198-
stopAllInstances();
199-
Navigator.pop(context);
200-
},
201-
onKeep: (remember) {
202-
ref
203-
.read(guiSettingProvider(onAppCloseKey).notifier)
204-
.set(remember ? 'nothing' : 'ask');
205-
windowManager.destroy();
206-
},
207-
),
208-
);
195+
if (closeJob == 'ask') {
196+
showDialog(
197+
context: context,
198+
barrierDismissible: false,
199+
builder: (context) => BeforeQuitDialog(
200+
onStop: (remember) {
201+
ref
202+
.read(guiSettingProvider(onAppCloseKey).notifier)
203+
.set(remember ? 'stop' : 'ask');
204+
stopAllInstances();
205+
Navigator.pop(context);
206+
},
207+
onKeep: (remember) {
208+
ref
209+
.read(guiSettingProvider(onAppCloseKey).notifier)
210+
.set(remember ? 'nothing' : 'ask');
211+
windowManager.destroy();
212+
},
213+
),
214+
);
215+
} else {
216+
stopAllInstances();
209217
}
210218
}
211219
}

src/client/gui/lib/tray_menu.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ Future<void> setupTrayMenu(ProviderContainer providerContainer) async {
9595
await TrayMenu.instance.addLabel(
9696
'quit',
9797
label: 'Quit',
98-
callback: (_, __) => windowManager.destroy(),
98+
callback: (_, __) => windowManager.close(),
9999
);
100100

101101
await TrayMenu.instance.show(await _iconFilePath());

0 commit comments

Comments
 (0)