Skip to content

Commit 1675705

Browse files
committed
Move settings save to post-confirmation for actions
Previously, `Context.API.SaveAppAllSettings()` was called unconditionally before user confirmation for shutdown, restart, and advanced restart actions. This change ensures settings are only saved if the user confirms the action by clicking "Yes" in the confirmation dialog. For all three functionalities: - Moved the settings save call inside the `if (result == MessageBoxResult.Yes)` block. - Retained the existing logic for executing the respective system commands, with checks for `EnableShutdownPrivilege()` to determine whether to use `PInvoke.ExitWindowsEx` or the `shutdown` command. This change prevents unnecessary settings saves when the user cancels the action.
1 parent e376da4 commit 1675705

File tree

1 file changed

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

1 file changed

+15
-15
lines changed

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -210,16 +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-
214-
// Save settings before shutdown to avoid data loss
215-
Context.API.SaveAppAllSettings();
216-
217213
if (result == MessageBoxResult.Yes)
214+
{
215+
// Save settings before shutdown to avoid data loss
216+
Context.API.SaveAppAllSettings();
217+
218218
if (EnableShutdownPrivilege())
219219
PInvoke.ExitWindowsEx(EXIT_WINDOWS_FLAGS.EWX_SHUTDOWN | EXIT_WINDOWS_FLAGS.EWX_POWEROFF, REASON);
220220
else
221221
Process.Start("shutdown", "/s /t 0");
222-
222+
}
223223
return true;
224224
}
225225
},
@@ -234,16 +234,16 @@ private static List<Result> Commands(Query query)
234234
Localize.flowlauncher_plugin_sys_dlgtext_restart_computer(),
235235
Localize.flowlauncher_plugin_sys_restart_computer(),
236236
MessageBoxButton.YesNo, MessageBoxImage.Warning);
237-
238-
// Save settings before restart to avoid data loss
239-
Context.API.SaveAppAllSettings();
240-
241237
if (result == MessageBoxResult.Yes)
238+
{
239+
// Save settings before restart to avoid data loss
240+
Context.API.SaveAppAllSettings();
241+
242242
if (EnableShutdownPrivilege())
243243
PInvoke.ExitWindowsEx(EXIT_WINDOWS_FLAGS.EWX_REBOOT, REASON);
244244
else
245245
Process.Start("shutdown", "/r /t 0");
246-
246+
}
247247
return true;
248248
}
249249
},
@@ -258,16 +258,16 @@ private static List<Result> Commands(Query query)
258258
Localize.flowlauncher_plugin_sys_dlgtext_restart_computer_advanced(),
259259
Localize.flowlauncher_plugin_sys_restart_computer(),
260260
MessageBoxButton.YesNo, MessageBoxImage.Warning);
261-
262-
// Save settings before restart to avoid data loss
263-
Context.API.SaveAppAllSettings();
264-
265261
if (result == MessageBoxResult.Yes)
262+
{
263+
// Save settings before restart to avoid data loss
264+
Context.API.SaveAppAllSettings();
265+
266266
if (EnableShutdownPrivilege())
267267
PInvoke.ExitWindowsEx(EXIT_WINDOWS_FLAGS.EWX_REBOOT | EXIT_WINDOWS_FLAGS.EWX_BOOTOPTIONS, REASON);
268268
else
269269
Process.Start("shutdown", "/r /o /t 0");
270-
270+
}
271271
return true;
272272
}
273273
},

0 commit comments

Comments
 (0)