Skip to content
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions Plugins/Flow.Launcher.Plugin.Sys/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,12 @@
{
try
{
if (!PInvoke.OpenProcessToken(Process.GetCurrentProcess().SafeHandle, TOKEN_ACCESS_MASK.TOKEN_ADJUST_PRIVILEGES | TOKEN_ACCESS_MASK.TOKEN_QUERY, out var tokenHandle))

Check warning on line 162 in Plugins/Flow.Launcher.Plugin.Sys/Main.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`PInvoke` is not a recognized word. (unrecognized-spelling)
{
return false;
}

if (!PInvoke.LookupPrivilegeValue(null, PInvoke.SE_SHUTDOWN_NAME, out var luid))

Check warning on line 167 in Plugins/Flow.Launcher.Plugin.Sys/Main.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`PInvoke` is not a recognized word. (unrecognized-spelling)

Check warning on line 167 in Plugins/Flow.Launcher.Plugin.Sys/Main.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`PInvoke` is not a recognized word. (unrecognized-spelling)
{
return false;
}
Expand All @@ -175,7 +175,7 @@
Privileges = new() { e0 = new LUID_AND_ATTRIBUTES { Luid = luid, Attributes = TOKEN_PRIVILEGES_ATTRIBUTES.SE_PRIVILEGE_ENABLED } }
};

if (!PInvoke.AdjustTokenPrivileges(tokenHandle, false, &privileges, 0, null, null))

Check warning on line 178 in Plugins/Flow.Launcher.Plugin.Sys/Main.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`PInvoke` is not a recognized word. (unrecognized-spelling)
{
return false;
}
Expand Down Expand Up @@ -210,13 +210,16 @@
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;
}
},
Expand All @@ -231,13 +234,16 @@
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;
}
},
Expand All @@ -252,13 +258,16 @@
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 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;
}
},
Expand All @@ -273,10 +282,8 @@
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;
}
},
Expand Down Expand Up @@ -316,7 +323,7 @@
new Result
{
Title = "Index Option",
IcoPath = "Images\\indexoption.png",

Check warning on line 326 in Plugins/Flow.Launcher.Plugin.Sys/Main.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`indexoption` is not a recognized word. (unrecognized-spelling)
Glyph = new GlyphInfo (FontFamily:"/Resources/#Segoe Fluent Icons", Glyph:"\xe773"),
Action = c =>
{
Expand All @@ -342,14 +349,13 @@
Localize.flowlauncher_plugin_sys_dlgtitle_error(),
MessageBoxButton.OK, MessageBoxImage.Error);
}

return true;
}
},
new Result
{
Title = "Open Recycle Bin",
IcoPath = "Images\\openrecyclebin.png",

Check warning on line 358 in Plugins/Flow.Launcher.Plugin.Sys/Main.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`openrecyclebin` is not a recognized word. (unrecognized-spelling)
Glyph = new GlyphInfo (FontFamily:"/Resources/#Segoe Fluent Icons", Glyph:"\xe74d"),
CopyText = recycleBinFolder,
Action = c =>
Expand Down Expand Up @@ -378,7 +384,7 @@
Action = c =>
{
Context.API.SaveAppAllSettings();
Context.API.ShowMsg(Localize.flowlauncher_plugin_sys_dlgtitle_success(),

Check warning on line 387 in Plugins/Flow.Launcher.Plugin.Sys/Main.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`dlgtitle` is not a recognized word. (unrecognized-spelling)
Localize.flowlauncher_plugin_sys_dlgtext_all_settings_saved());
return true;
}
Expand Down Expand Up @@ -416,13 +422,11 @@
{
// 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(),

Check warning on line 427 in Plugins/Flow.Launcher.Plugin.Sys/Main.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`dlgtitle` is not a recognized word. (unrecognized-spelling)
Localize.flowlauncher_plugin_sys_dlgtext_all_applicableplugins_reloaded()),
TaskScheduler.Current);

return true;
}
},
Expand Down Expand Up @@ -502,7 +506,6 @@
else
{
Context.API.ChangeQuery($"{query.ActionKeyword}{Plugin.Query.ActionKeywordSeparator}{ThemeSelector.Keyword}{Plugin.Query.ActionKeywordSeparator}");

}
return false;
}
Expand Down
Loading