Skip to content

Commit 9c77a59

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 9c77a59

File tree

2 files changed

+38
-27
lines changed

2 files changed

+38
-27
lines changed

src/client/gui/lib/main.dart

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,21 @@ 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 ||
173+
!vmsRunning ||
174+
closeJob == 'nothing') {
175+
windowManager.destroy();
176+
return;
177+
}
178+
179+
// checking the need to restore the window
180+
if (!await windowManager.isVisible() ||
181+
await windowManager.isMinimized()) {
182+
windowManager.showAndRestore();
183+
}
170184

171185
stopAllInstances() {
172186
final notificationsNotifier = ref.read(notificationsProvider.notifier);
@@ -181,31 +195,28 @@ class _AppState extends ConsumerState<App> with WindowListener {
181195
);
182196
}
183197

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-
);
198+
if (closeJob == 'ask') {
199+
showDialog(
200+
context: context,
201+
barrierDismissible: false,
202+
builder: (context) => BeforeQuitDialog(
203+
onStop: (remember) {
204+
ref
205+
.read(guiSettingProvider(onAppCloseKey).notifier)
206+
.set(remember ? 'stop' : 'ask');
207+
stopAllInstances();
208+
Navigator.pop(context);
209+
},
210+
onKeep: (remember) {
211+
ref
212+
.read(guiSettingProvider(onAppCloseKey).notifier)
213+
.set(remember ? 'nothing' : 'ask');
214+
windowManager.destroy();
215+
},
216+
),
217+
);
218+
} else {
219+
stopAllInstances();
209220
}
210221
}
211222
}

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)