Skip to content

Commit 59100a2

Browse files
Jack251970jjw24
authored andcommitted
Merge pull request #4025 from Flow-Launcher/hide_window_before_sleep
Save settings before shutdown/restart to prevent data loss
1 parent c7ab067 commit 59100a2

File tree

1 file changed

+15
-12
lines changed
  • Plugins/Flow.Launcher.Plugin.Sys

1 file changed

+15
-12
lines changed

Plugins/Flow.Launcher.Plugin.Sys/Main.cs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -210,13 +210,16 @@ private static List<Result> Commands(Query query)
210210
Localize.flowlauncher_plugin_sys_dlgtext_shutdown_computer(),
211211
Localize.flowlauncher_plugin_sys_shutdown_computer(),
212212
MessageBoxButton.YesNo, MessageBoxImage.Warning);
213-
214213
if (result == MessageBoxResult.Yes)
214+
{
215+
// Save settings before shutdown to avoid data loss
216+
Context.API.SaveAppAllSettings();
217+
215218
if (EnableShutdownPrivilege())
216219
PInvoke.ExitWindowsEx(EXIT_WINDOWS_FLAGS.EWX_SHUTDOWN | EXIT_WINDOWS_FLAGS.EWX_POWEROFF, REASON);
217220
else
218221
Process.Start("shutdown", "/s /t 0");
219-
222+
}
220223
return true;
221224
}
222225
},
@@ -231,13 +234,16 @@ private static List<Result> Commands(Query query)
231234
Localize.flowlauncher_plugin_sys_dlgtext_restart_computer(),
232235
Localize.flowlauncher_plugin_sys_restart_computer(),
233236
MessageBoxButton.YesNo, MessageBoxImage.Warning);
234-
235237
if (result == MessageBoxResult.Yes)
238+
{
239+
// Save settings before restart to avoid data loss
240+
Context.API.SaveAppAllSettings();
241+
236242
if (EnableShutdownPrivilege())
237243
PInvoke.ExitWindowsEx(EXIT_WINDOWS_FLAGS.EWX_REBOOT, REASON);
238244
else
239245
Process.Start("shutdown", "/r /t 0");
240-
246+
}
241247
return true;
242248
}
243249
},
@@ -252,13 +258,16 @@ private static List<Result> Commands(Query query)
252258
Localize.flowlauncher_plugin_sys_dlgtext_restart_computer_advanced(),
253259
Localize.flowlauncher_plugin_sys_restart_computer(),
254260
MessageBoxButton.YesNo, MessageBoxImage.Warning);
255-
256261
if (result == MessageBoxResult.Yes)
262+
{
263+
// Save settings before advanced restart to avoid data loss
264+
Context.API.SaveAppAllSettings();
265+
257266
if (EnableShutdownPrivilege())
258267
PInvoke.ExitWindowsEx(EXIT_WINDOWS_FLAGS.EWX_REBOOT | EXIT_WINDOWS_FLAGS.EWX_BOOTOPTIONS, REASON);
259268
else
260269
Process.Start("shutdown", "/r /o /t 0");
261-
270+
}
262271
return true;
263272
}
264273
},
@@ -273,10 +282,8 @@ private static List<Result> Commands(Query query)
273282
Localize.flowlauncher_plugin_sys_dlgtext_logoff_computer(),
274283
Localize.flowlauncher_plugin_sys_log_off(),
275284
MessageBoxButton.YesNo, MessageBoxImage.Warning);
276-
277285
if (result == MessageBoxResult.Yes)
278286
PInvoke.ExitWindowsEx(EXIT_WINDOWS_FLAGS.EWX_LOGOFF, REASON);
279-
280287
return true;
281288
}
282289
},
@@ -342,7 +349,6 @@ private static List<Result> Commands(Query query)
342349
Localize.flowlauncher_plugin_sys_dlgtitle_error(),
343350
MessageBoxButton.OK, MessageBoxImage.Error);
344351
}
345-
346352
return true;
347353
}
348354
},
@@ -416,13 +422,11 @@ private static List<Result> Commands(Query query)
416422
{
417423
// Hide the window first then show msg after done because sometimes the reload could take a while, so not to make user think it's frozen.
418424
Context.API.HideMainWindow();
419-
420425
_ = Context.API.ReloadAllPluginData().ContinueWith(_ =>
421426
Context.API.ShowMsg(
422427
Localize.flowlauncher_plugin_sys_dlgtitle_success(),
423428
Localize.flowlauncher_plugin_sys_dlgtext_all_applicableplugins_reloaded()),
424429
TaskScheduler.Current);
425-
426430
return true;
427431
}
428432
},
@@ -502,7 +506,6 @@ private static List<Result> Commands(Query query)
502506
else
503507
{
504508
Context.API.ChangeQuery($"{query.ActionKeyword}{Plugin.Query.ActionKeywordSeparator}{ThemeSelector.Keyword}{Plugin.Query.ActionKeywordSeparator}");
505-
506509
}
507510
return false;
508511
}

0 commit comments

Comments
 (0)