From f6f8e4c4ebad7b5ad7bbb26f608305fd6b4eeaa7 Mon Sep 17 00:00:00 2001 From: Heiko <61519853+htcfreek@users.noreply.github.com> Date: Tue, 25 Jan 2022 18:20:04 +0100 Subject: [PATCH] [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 --- .github/actions/spell-check/expect.txt | 2 ++ installer/PowerToysSetup/Product.wxs | 2 ++ .../Images/firmwareSettings.dark.png | Bin 0 -> 1151 bytes .../Images/firmwareSettings.light.png | Bin 0 -> 1182 bytes .../Main.cs | 25 +++++++++++++++ ...crosoft.PowerToys.Run.Plugin.System.csproj | 6 ++++ .../Properties/Resources.Designer.cs | 29 +++++++++++++++++- .../Properties/Resources.resx | 14 ++++++++- .../Win32/NativeMethods.cs | 23 ++++++++++++++ 9 files changed, 99 insertions(+), 2 deletions(-) create mode 100644 src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System/Images/firmwareSettings.dark.png create mode 100644 src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System/Images/firmwareSettings.light.png diff --git a/.github/actions/spell-check/expect.txt b/.github/actions/spell-check/expect.txt index dd6126fd24..4e1346076f 100644 --- a/.github/actions/spell-check/expect.txt +++ b/.github/actions/spell-check/expect.txt @@ -142,6 +142,7 @@ bigbar bigobj binaryformatter binlog +bios bitmapimage BITMAPINFO BITMAPINFOHEADER @@ -2016,6 +2017,7 @@ UAL uap udit Udp +uefi UIA Uid uint diff --git a/installer/PowerToysSetup/Product.wxs b/installer/PowerToysSetup/Product.wxs index ab300b34b6..a45b4341e2 100644 --- a/installer/PowerToysSetup/Product.wxs +++ b/installer/PowerToysSetup/Product.wxs @@ -1524,6 +1524,8 @@ + + diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System/Images/firmwareSettings.dark.png b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System/Images/firmwareSettings.dark.png new file mode 100644 index 0000000000000000000000000000000000000000..15a7a98f0620a06085f568deb5df169a75e883e6 GIT binary patch literal 1151 zcmV-_1c3XAP)DvVE0G|=0+G2o$uH-gbAR(YzwhsL zerIw`6a2|daQ&Ma0RFWH8y;wQAfW{sA(YU7iGTiod0=>W_!A}@$mMdaG9B{*!#=2u zwIcJiyg!02GjBJZ*Nn|jD{BMrbn<=<>R?`A-om?hip<;UbxF-0V52<3A7}$MD*ukP zBEtsg1WP^4dwB1L`k0GfJj14x0~!3yD7p23hy`GZA4aG)k|ncz1`vMR3{t9PqeuWK z-;R*pS_GxcBOvnF<2bpY08n1mcJbTC`*}!$vwXB?53~k)41jfUn?(U|)_;SLwMxJ^ zVQGB#l3L={#d#qLfGiPANL8GcG!(5O;|aQjGakhTVE)ZL+QXGCJ zFl!$(>uR5VXfZSk`iOE1OxX{N^P#WMTWF;KLX)7=ab6h{00j3`v5f8jMN>+NdKXfx zyPEFy(!8RW2h`U^Jem(dTZ0Mi?_Cdo7JjJiH0=8Wc!#1rMfGO6_C?M6If-89_B+E^Op0T#tXXe`-=9>co zuDkem>+n4_;6M51SFI60t)-nVA)tH*uJvK_Z}855`ywI?TEN2HF8Fg$AMRQ3)(iwO;D=S4iHx5oU}L zx2JIfzzYiji2Pfnju3hU?;+#Az_=un5DJSSgtH z&`ThAg`k(h%;+J-ZkP#)5eia5GzCUIrBD=Pc1x2oN+C1K%)Srymc!x9oH=)9-?}&( zKK40h_Mi3JYps3unZ7Zjy!4H7`^WSI{MR1rd7$Tk4p*QTLLDw($K5YF51eGlPQmoB zbc587!dz&;?eH1A4)xIHTk46SkA0tljj#;tUjy6N-*GCHDjw)( zu%7xuu)XDcsH4bypQ3Tw7SWCXCs-Q{awSt1J@igkkfC-aDics=kk{H7sLO2>qQ?%F zjoV6qs~zLlka!UsIAw9p0hk$#pH((lD*>FN?-kI}3#|mW68VI5 z$8mxbH=VDFfb7bo5TJ*zN-3b9!Q(dSw%M)X!suB`T+k#Q$Oa zaqkDmuaA@mx+$PY?5OfUkpOqSLGakoXywi-N!+av8jnGD!xh1>AE`fu-*bi|O_#zl)=xl|5 z;HL2GYwEGE0^SeL6#5hVTqY=`0FBrOzk+f95_t4p44Yw1FwW;s!fx=)wHp3_NpNqO zSB5KKpkQU3yb+#j@OxlfdzNxrtcBl>Q7_0CrqFj`TKN4$5O4$a$1o4_34USvDgrdX z(`mC3zp(s$IXnj@=Ob_)Dgqp%4hktM zgFGAxKYT(x9i9clC0p*}<^}jWJT(4SLX7{|*09p}@8OQ&2+&wRW;9A;s+2u6UIgwc zzKo)A8vhDh0)K@8$59*edLXtl+5P^|GarGuQ&`GAXf%ETG{S(bz6s2MSZZACfSchg z+!MrnLwz~C44Xn@KUZVox--R`xRmR|;5Mrrl?B+L4()zY<`=_6-U)i*X)vjM2l)I} zh>7X_m*L)b!F+fg_QFG%cEb{2r+zRDto25-lK*u^zY05f7pKYMTS1ftEqY{;?I?n-6z_-?OfMHaXo!&4cVNbcXvU za_wRg8%lbyu%tTIyNzBCz6f1>%e!_zqq zowtD7tGkUQUO&dQC)BRJ$l5WqSsN30Kg@=s;3|8lv-|*YTlK!^D4}<*gN}|8od}4A zd6+v5?&%)d`r!d6I?TPz^9FdxvycB!EQFRv>{K}r#e1Bdk})D4r#&jixOQhc2dki~ z$LUTzP}JXWF~)rl_@=h#6?4NkZdX5OQV4KNKPf$B*1`ls)JZ-mQwcD^4WDbn1iyvQ wX?o^wWk~8ANVNzT#_b76zQiRHjCv3J3)+$yKrFD7TmS$707*qoM6N<$f+K}8IsgCw literal 0 HcmV?d00001 diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System/Main.cs b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System/Main.cs index adc3e4b2e9..b1139d4374 100644 --- a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System/Main.cs +++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System/Main.cs @@ -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 AdditionalOptions => new List() { 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 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; } diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System/Microsoft.PowerToys.Run.Plugin.System.csproj b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System/Microsoft.PowerToys.Run.Plugin.System.csproj index 4115690563..63a36015ff 100644 --- a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System/Microsoft.PowerToys.Run.Plugin.System.csproj +++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System/Microsoft.PowerToys.Run.Plugin.System.csproj @@ -123,6 +123,12 @@ PreserveNewest + + PreserveNewest + + + PreserveNewest + diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System/Properties/Resources.Designer.cs b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System/Properties/Resources.Designer.cs index 7813a05c27..d93c36e037 100644 --- a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System/Properties/Resources.Designer.cs +++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System/Properties/Resources.Designer.cs @@ -70,7 +70,7 @@ namespace Microsoft.PowerToys.Run.Plugin.System.Properties { } /// - /// Looks up a localized string similar to Please Confirm. + /// Looks up a localized string similar to Please confirm.. /// internal static string Microsoft_plugin_sys_confirmation { get { @@ -276,6 +276,33 @@ namespace Microsoft.PowerToys.Run.Plugin.System.Properties { } } + /// + /// Looks up a localized string similar to UEFI Firmware Settings. + /// + internal static string Microsoft_plugin_sys_uefi { + get { + return ResourceManager.GetString("Microsoft_plugin_sys_uefi", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to You are about to reboot this computer into UEFI Firmware Settings menu, are you sure?. + /// + internal static string Microsoft_plugin_sys_uefi_confirmation { + get { + return ResourceManager.GetString("Microsoft_plugin_sys_uefi_confirmation", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Reboot computer into UEFI Firmware Settings (Requires administrative permissions.). + /// + internal static string Microsoft_plugin_sys_uefi_description { + get { + return ResourceManager.GetString("Microsoft_plugin_sys_uefi_description", resourceCulture); + } + } + /// /// Looks up a localized string similar to Use localized system commands instead of English ones. /// diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System/Properties/Resources.resx b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System/Properties/Resources.resx index 17432f8ead..410a359da2 100644 --- a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System/Properties/Resources.resx +++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System/Properties/Resources.resx @@ -121,7 +121,7 @@ Show a dialog to confirm system commands - Please Confirm + Please confirm. Request confirmation @@ -212,6 +212,18 @@ Put computer to sleep This should align to the action in Windows of a making your computer go to sleep. + + UEFI Firmware Settings + This should align to the action in Windows Recovery Environment that restart into uefi settings. + + + You are about to reboot this computer into UEFI Firmware Settings menu, are you sure? + This should align to the action in Windows Recovery Environment that restart into uefi settings. + + + Reboot computer into UEFI Firmware Settings (Requires administrative permissions.) + This should align to the action in Windows Recovery Environment that restart into uefi settings. + Use localized system commands instead of English ones diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System/Win32/NativeMethods.cs b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System/Win32/NativeMethods.cs index dc1aa75f02..a7c64749e4 100644 --- a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System/Win32/NativeMethods.cs +++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System/Win32/NativeMethods.cs @@ -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, + } + + /// + /// Detects the type of system firmware which is equal to the boot type by calling the method . + /// + /// Firmware type like Uefi or Bios. + internal static FirmwareTypes GetSystemFirmwareType() + { + uint firmwareType = 0; + _ = GetFirmwareType(ref firmwareType); + return (FirmwareTypes)firmwareType; + } } }