Skip to content

Commit 648e3f2

Browse files
committed
Improve code quality
1 parent 1809314 commit 648e3f2

File tree

1 file changed

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

1 file changed

+7
-11
lines changed

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

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ public class Main : IPlugin, ISettingProvider, IPluginI18n
2323
private Dictionary<string, string> KeywordTitleMappings = new Dictionary<string, string>();
2424

2525
private const string SE_SHUTDOWN_NAME = "SeShutdownPrivilege";
26+
// SHTDN_REASON_MAJOR_OTHER indicates a generic shutdown reason that isn't categorized under hardware failure, software updates, or other predefined reasons.
27+
// SHTDN_REASON_FLAG_PLANNED marks the shutdown as planned rather than an unexpected shutdown or failure
28+
private const SHUTDOWN_REASON REASON = SHUTDOWN_REASON.SHTDN_REASON_MAJOR_OTHER | SHUTDOWN_REASON.SHTDN_REASON_FLAG_PLANNED;
2629

2730
public Control CreateSettingPanel()
2831
{
@@ -163,13 +166,9 @@ private List<Result> Commands()
163166
context.API.GetTranslation("flowlauncher_plugin_sys_shutdown_computer"),
164167
MessageBoxButton.YesNo, MessageBoxImage.Warning);
165168

166-
// SHTDN_REASON_MAJOR_OTHER indicates a generic shutdown reason that isn't categorized under hardware failure,
167-
// software updates, or other predefined reasons.
168-
// SHTDN_REASON_FLAG_PLANNED marks the shutdown as planned rather than an unexpected shutdown or failure
169169
if (result == MessageBoxResult.Yes)
170170
if (EnableShutdownPrivilege())
171-
PInvoke.ExitWindowsEx(EXIT_WINDOWS_FLAGS.EWX_SHUTDOWN | EXIT_WINDOWS_FLAGS.EWX_POWEROFF,
172-
SHUTDOWN_REASON.SHTDN_REASON_MAJOR_OTHER | SHUTDOWN_REASON.SHTDN_REASON_FLAG_PLANNED);
171+
PInvoke.ExitWindowsEx(EXIT_WINDOWS_FLAGS.EWX_SHUTDOWN | EXIT_WINDOWS_FLAGS.EWX_POWEROFF, REASON);
173172
else
174173
Process.Start("shutdown", "/s /t 0");
175174

@@ -191,8 +190,7 @@ private List<Result> Commands()
191190

192191
if (result == MessageBoxResult.Yes)
193192
if (EnableShutdownPrivilege())
194-
PInvoke.ExitWindowsEx(EXIT_WINDOWS_FLAGS.EWX_REBOOT,
195-
SHUTDOWN_REASON.SHTDN_REASON_MAJOR_OTHER | SHUTDOWN_REASON.SHTDN_REASON_FLAG_PLANNED);
193+
PInvoke.ExitWindowsEx(EXIT_WINDOWS_FLAGS.EWX_REBOOT, REASON);
196194
else
197195
Process.Start("shutdown", "/r /t 0");
198196

@@ -214,8 +212,7 @@ private List<Result> Commands()
214212

215213
if (result == MessageBoxResult.Yes)
216214
if (EnableShutdownPrivilege())
217-
PInvoke.ExitWindowsEx(EXIT_WINDOWS_FLAGS.EWX_REBOOT | EXIT_WINDOWS_FLAGS.EWX_BOOTOPTIONS,
218-
SHUTDOWN_REASON.SHTDN_REASON_MAJOR_OTHER | SHUTDOWN_REASON.SHTDN_REASON_FLAG_PLANNED);
215+
PInvoke.ExitWindowsEx(EXIT_WINDOWS_FLAGS.EWX_REBOOT | EXIT_WINDOWS_FLAGS.EWX_BOOTOPTIONS, REASON);
219216
else
220217
Process.Start("shutdown", "/r /o /t 0");
221218

@@ -236,8 +233,7 @@ private List<Result> Commands()
236233
MessageBoxButton.YesNo, MessageBoxImage.Warning);
237234

238235
if (result == MessageBoxResult.Yes)
239-
PInvoke.ExitWindowsEx(EXIT_WINDOWS_FLAGS.EWX_LOGOFF,
240-
SHUTDOWN_REASON.SHTDN_REASON_MAJOR_OTHER | SHUTDOWN_REASON.SHTDN_REASON_FLAG_PLANNED);
236+
PInvoke.ExitWindowsEx(EXIT_WINDOWS_FLAGS.EWX_LOGOFF, REASON);
241237

242238
return true;
243239
}

0 commit comments

Comments
 (0)