mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-01-18 14:41:21 +08:00
[PT Run] System plugin: Add UEFI command (#15629)
* Add uefi command * small fixes * spell check * spell check * fixes * text improvement * fix typo * add icon * unit tests * fix icon * restore changes in UnitTests
This commit is contained in:
parent
5880f3855b
commit
f6f8e4c4eb
2
.github/actions/spell-check/expect.txt
vendored
2
.github/actions/spell-check/expect.txt
vendored
@ -142,6 +142,7 @@ bigbar
|
||||
bigobj
|
||||
binaryformatter
|
||||
binlog
|
||||
bios
|
||||
bitmapimage
|
||||
BITMAPINFO
|
||||
BITMAPINFOHEADER
|
||||
@ -2016,6 +2017,7 @@ UAL
|
||||
uap
|
||||
udit
|
||||
Udp
|
||||
uefi
|
||||
UIA
|
||||
Uid
|
||||
uint
|
||||
|
@ -1524,6 +1524,8 @@
|
||||
<File Id="SystemShutdownLightIcon" Source="$(var.BinX64Dir)modules\launcher\Plugins\System\Images\shutdown.light.png" />
|
||||
<File Id="SystemSleepDarkIcon" Source="$(var.BinX64Dir)modules\launcher\Plugins\System\Images\sleep.dark.png" />
|
||||
<File Id="SystemSleepLightIcon" Source="$(var.BinX64Dir)modules\launcher\Plugins\System\Images\sleep.light.png" />
|
||||
<File Id="SystemFirmwareSettingsDarkIcon" Source="$(var.BinX64Dir)modules\launcher\Plugins\System\Images\firmwareSettings.dark.png" />
|
||||
<File Id="SystemFirmwareSettingsLightIcon" Source="$(var.BinX64Dir)modules\launcher\Plugins\System\Images\firmwareSettings.light.png" />
|
||||
</Component>
|
||||
|
||||
<!-- WindowsSettings Plugin -->
|
||||
|
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
Binary file not shown.
After Width: | Height: | Size: 1.2 KiB |
@ -43,6 +43,8 @@ namespace Microsoft.PowerToys.Run.Plugin.System
|
||||
private bool _confirmSystemCommands;
|
||||
private bool _localizeSystemCommands;
|
||||
|
||||
private bool isBootedInUefiMode = NativeMethods.GetSystemFirmwareType() == NativeMethods.FirmwareTypes.Uefi;
|
||||
|
||||
public IEnumerable<PluginAdditionalOption> AdditionalOptions => new List<PluginAdditionalOption>()
|
||||
{
|
||||
new PluginAdditionalOption()
|
||||
@ -64,6 +66,13 @@ namespace Microsoft.PowerToys.Run.Plugin.System
|
||||
_context = context;
|
||||
_context.API.ThemeChanged += OnThemeChanged;
|
||||
UpdateIconTheme(_context.API.GetCurrentTheme());
|
||||
|
||||
// Log info if the system hasn't boot in uefi mode.
|
||||
// (Because this is only going into the log we can ignore the fact that normally UEFI and BIOS are written upper case. No need to convert the enumeration value to upper case.)
|
||||
if (!isBootedInUefiMode)
|
||||
{
|
||||
Wox.Plugin.Logger.Log.Info($"The UEFI command will not show to the user. The system has not booted in UEFI mode or the system does not have an UEFI firmware! (Detected type: {NativeMethods.GetSystemFirmwareType()})", typeof(Main));
|
||||
}
|
||||
}
|
||||
|
||||
public List<Result> Query(Query query)
|
||||
@ -185,6 +194,22 @@ namespace Microsoft.PowerToys.Run.Plugin.System
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
// UEFI command/result. It is only available on systems booted in UEFI mode.
|
||||
if (isBootedInUefiMode)
|
||||
{
|
||||
results.Add(new Result
|
||||
{
|
||||
Title = Resources.ResourceManager.GetString(nameof(Resources.Microsoft_plugin_sys_uefi), culture),
|
||||
SubTitle = Resources.ResourceManager.GetString(nameof(Resources.Microsoft_plugin_sys_uefi_description), culture),
|
||||
IcoPath = $"Images\\firmwareSettings.{IconTheme}.png",
|
||||
Action = c =>
|
||||
{
|
||||
return ExecuteCommand(Resources.Microsoft_plugin_sys_uefi_confirmation, () => Helper.OpenInShell("shutdown", "/r /fw /t 0", null, true));
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
|
@ -123,6 +123,12 @@
|
||||
<None Update="Images\sleep.dark.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Images\firmwareSettings.light.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Images\firmwareSettings.dark.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -70,7 +70,7 @@ namespace Microsoft.PowerToys.Run.Plugin.System.Properties {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Please Confirm.
|
||||
/// Looks up a localized string similar to Please confirm..
|
||||
/// </summary>
|
||||
internal static string Microsoft_plugin_sys_confirmation {
|
||||
get {
|
||||
@ -276,6 +276,33 @@ namespace Microsoft.PowerToys.Run.Plugin.System.Properties {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to UEFI Firmware Settings.
|
||||
/// </summary>
|
||||
internal static string Microsoft_plugin_sys_uefi {
|
||||
get {
|
||||
return ResourceManager.GetString("Microsoft_plugin_sys_uefi", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to You are about to reboot this computer into UEFI Firmware Settings menu, are you sure?.
|
||||
/// </summary>
|
||||
internal static string Microsoft_plugin_sys_uefi_confirmation {
|
||||
get {
|
||||
return ResourceManager.GetString("Microsoft_plugin_sys_uefi_confirmation", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Reboot computer into UEFI Firmware Settings (Requires administrative permissions.).
|
||||
/// </summary>
|
||||
internal static string Microsoft_plugin_sys_uefi_description {
|
||||
get {
|
||||
return ResourceManager.GetString("Microsoft_plugin_sys_uefi_description", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Use localized system commands instead of English ones.
|
||||
/// </summary>
|
||||
|
@ -121,7 +121,7 @@
|
||||
<value>Show a dialog to confirm system commands</value>
|
||||
</data>
|
||||
<data name="Microsoft_plugin_sys_confirmation" xml:space="preserve">
|
||||
<value>Please Confirm</value>
|
||||
<value>Please confirm.</value>
|
||||
<comment>Request confirmation</comment>
|
||||
</data>
|
||||
<data name="Microsoft_plugin_sys_emptyrecyclebin" xml:space="preserve">
|
||||
@ -212,6 +212,18 @@
|
||||
<value>Put computer to sleep</value>
|
||||
<comment>This should align to the action in Windows of a making your computer go to sleep.</comment>
|
||||
</data>
|
||||
<data name="Microsoft_plugin_sys_uefi" xml:space="preserve">
|
||||
<value>UEFI Firmware Settings</value>
|
||||
<comment>This should align to the action in Windows Recovery Environment that restart into uefi settings.</comment>
|
||||
</data>
|
||||
<data name="Microsoft_plugin_sys_uefi_confirmation" xml:space="preserve">
|
||||
<value>You are about to reboot this computer into UEFI Firmware Settings menu, are you sure?</value>
|
||||
<comment>This should align to the action in Windows Recovery Environment that restart into uefi settings.</comment>
|
||||
</data>
|
||||
<data name="Microsoft_plugin_sys_uefi_description" xml:space="preserve">
|
||||
<value>Reboot computer into UEFI Firmware Settings (Requires administrative permissions.)</value>
|
||||
<comment>This should align to the action in Windows Recovery Environment that restart into uefi settings.</comment>
|
||||
</data>
|
||||
<data name="Use_localized_system_commands" xml:space="preserve">
|
||||
<value>Use localized system commands instead of English ones</value>
|
||||
</data>
|
||||
|
@ -21,11 +21,34 @@ namespace Microsoft.PowerToys.Run.Plugin.System.Win32
|
||||
[DllImport("Powrprof.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
|
||||
internal static extern bool SetSuspendState(bool hibernate, bool forceCritical, bool disableWakeEvent);
|
||||
|
||||
[DllImport("kernel32.dll")]
|
||||
internal static extern bool GetFirmwareType(ref uint FirmwareType);
|
||||
|
||||
// http://www.pinvoke.net/default.aspx/Enums/HRESULT.html
|
||||
public enum HRESULT : uint
|
||||
{
|
||||
S_FALSE = 0x0001,
|
||||
S_OK = 0x0000,
|
||||
}
|
||||
|
||||
// https://docs.microsoft.com/en-us/windows/win32/api/winnt/ne-winnt-firmware_type
|
||||
public enum FirmwareTypes
|
||||
{
|
||||
Unknown = 0,
|
||||
Bios,
|
||||
Uefi,
|
||||
Max,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Detects the type of system firmware which is equal to the boot type by calling the method <see cref="NativeMethods.GetFirmwareType(ref uint)"/>.
|
||||
/// </summary>
|
||||
/// <returns>Firmware type like Uefi or Bios.</returns>
|
||||
internal static FirmwareTypes GetSystemFirmwareType()
|
||||
{
|
||||
uint firmwareType = 0;
|
||||
_ = GetFirmwareType(ref firmwareType);
|
||||
return (FirmwareTypes)firmwareType;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user