Merge pull request #4025 from Flow-Launcher/hide_window_before_sleep

Save settings before shutdown/restart to prevent data loss
This commit is contained in:
Jack Ye 2025-10-04 19:52:26 +08:00 committed by GitHub
commit 8c98aedac2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -210,13 +210,16 @@ namespace Flow.Launcher.Plugin.Sys
Localize.flowlauncher_plugin_sys_dlgtext_shutdown_computer(),
Localize.flowlauncher_plugin_sys_shutdown_computer(),
MessageBoxButton.YesNo, MessageBoxImage.Warning);
if (result == MessageBoxResult.Yes)
{
// Save settings before shutdown to avoid data loss
Context.API.SaveAppAllSettings();
if (EnableShutdownPrivilege())
PInvoke.ExitWindowsEx(EXIT_WINDOWS_FLAGS.EWX_SHUTDOWN | EXIT_WINDOWS_FLAGS.EWX_POWEROFF, REASON);
else
Process.Start("shutdown", "/s /t 0");
}
return true;
}
},
@ -231,13 +234,16 @@ namespace Flow.Launcher.Plugin.Sys
Localize.flowlauncher_plugin_sys_dlgtext_restart_computer(),
Localize.flowlauncher_plugin_sys_restart_computer(),
MessageBoxButton.YesNo, MessageBoxImage.Warning);
if (result == MessageBoxResult.Yes)
{
// Save settings before restart to avoid data loss
Context.API.SaveAppAllSettings();
if (EnableShutdownPrivilege())
PInvoke.ExitWindowsEx(EXIT_WINDOWS_FLAGS.EWX_REBOOT, REASON);
else
Process.Start("shutdown", "/r /t 0");
}
return true;
}
},
@ -252,13 +258,16 @@ namespace Flow.Launcher.Plugin.Sys
Localize.flowlauncher_plugin_sys_dlgtext_restart_computer_advanced(),
Localize.flowlauncher_plugin_sys_restart_computer(),
MessageBoxButton.YesNo, MessageBoxImage.Warning);
if (result == MessageBoxResult.Yes)
{
// Save settings before advanced restart to avoid data loss
Context.API.SaveAppAllSettings();
if (EnableShutdownPrivilege())
PInvoke.ExitWindowsEx(EXIT_WINDOWS_FLAGS.EWX_REBOOT | EXIT_WINDOWS_FLAGS.EWX_BOOTOPTIONS, REASON);
else
Process.Start("shutdown", "/r /o /t 0");
}
return true;
}
},
@ -273,10 +282,8 @@ namespace Flow.Launcher.Plugin.Sys
Localize.flowlauncher_plugin_sys_dlgtext_logoff_computer(),
Localize.flowlauncher_plugin_sys_log_off(),
MessageBoxButton.YesNo, MessageBoxImage.Warning);
if (result == MessageBoxResult.Yes)
PInvoke.ExitWindowsEx(EXIT_WINDOWS_FLAGS.EWX_LOGOFF, REASON);
return true;
}
},
@ -342,7 +349,6 @@ namespace Flow.Launcher.Plugin.Sys
Localize.flowlauncher_plugin_sys_dlgtitle_error(),
MessageBoxButton.OK, MessageBoxImage.Error);
}
return true;
}
},
@ -416,13 +422,11 @@ namespace Flow.Launcher.Plugin.Sys
{
// 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.
Context.API.HideMainWindow();
_ = Context.API.ReloadAllPluginData().ContinueWith(_ =>
Context.API.ShowMsg(
Localize.flowlauncher_plugin_sys_dlgtitle_success(),
Localize.flowlauncher_plugin_sys_dlgtext_all_applicableplugins_reloaded()),
TaskScheduler.Current);
return true;
}
},
@ -502,7 +506,6 @@ namespace Flow.Launcher.Plugin.Sys
else
{
Context.API.ChangeQuery($"{query.ActionKeyword}{Plugin.Query.ActionKeywordSeparator}{ThemeSelector.Keyword}{Plugin.Query.ActionKeywordSeparator}");
}
return false;
}