diff --git a/.github/actions/spell-check/expect.txt b/.github/actions/spell-check/expect.txt index 6da7058333..f8c62326bb 100644 --- a/.github/actions/spell-check/expect.txt +++ b/.github/actions/spell-check/expect.txt @@ -475,7 +475,6 @@ EFile ekus emmintrin Emoji -emptyrecyclebin ENABLEDELAYEDEXPANSION enabledisable ENABLEDPOPUP @@ -1610,6 +1609,7 @@ shellex SHELLEXECUTEINFO SHELLEXECUTEINFOW shellscalingapi +shemptyrecyclebina SHFILEINFO SHGFI Shl diff --git a/doc/devdocs/modules/launcher/plugins/system.md b/doc/devdocs/modules/launcher/plugins/system.md index 6307686f51..dcf6c3d9f8 100644 --- a/doc/devdocs/modules/launcher/plugins/system.md +++ b/doc/devdocs/modules/launcher/plugins/system.md @@ -13,7 +13,7 @@ Available commands: * Lock * Sleep * Hibernate -* Empty Recycle Bin +* Open / Empty Recycle Bin * UEFI Firmware Settings (Only available on systems, that boot in UEFI mode.) * IP / MAC / Address => Show informations about network connections. @@ -42,6 +42,7 @@ Available commands: ### [`ResultHelper.cs`](/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System/Components/ResultHelper.cs) - The [`ResultHelper`](/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System/Components/ResultHelper.cs) class contains methods for working with the results and some of the result features (tool tip, copy to clipboard, execute command). +- **Recycle Bin command:** The context menu action to empty the Recycle Bin is executed as an async task to not block PowerToys Run. (While the task is running the static class variable `executingEmptyRecycleBinTask` is set to true, to block multiple executions at the same time) ### [`NetworkConnectionProperties.cs`](/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System/Components/NetworkConnectionProperties.cs) - The [`NetworkConnectionProperties`](/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System/Components/NetworkConnectionProperties.cs) class contains methods to get the properties of a network interface/connection. diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System.UnitTests/ImageTests.cs b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System.UnitTests/ImageTests.cs index 9541971a58..1f55793d3a 100644 --- a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System.UnitTests/ImageTests.cs +++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System.UnitTests/ImageTests.cs @@ -26,7 +26,7 @@ namespace Microsoft.PowerToys.Run.Plugin.System.UnitTests [DataRow("lock", "Images\\lock.dark.png")] [DataRow("sleep", "Images\\sleep.dark.png")] [DataRow("hibernate", "Images\\sleep.dark.png")] - [DataRow("empty recycle", "Images\\recyclebin.dark.png")] + [DataRow("recycle bin", "Images\\recyclebin.dark.png")] [DataRow("uefi firmware settings", "Images\\firmwareSettings.dark.png")] [DataRow("ip v4 addr", "Images\\networkAdapter.dark.png", true)] [DataRow("ip v6 addr", "Images\\networkAdapter.dark.png", true)] @@ -53,7 +53,7 @@ namespace Microsoft.PowerToys.Run.Plugin.System.UnitTests [DataRow("lock", "Images\\lock.light.png")] [DataRow("sleep", "Images\\sleep.light.png")] [DataRow("hibernate", "Images\\sleep.light.png")] - [DataRow("empty recycle", "Images\\recyclebin.light.png")] + [DataRow("recycle bin", "Images\\recyclebin.light.png")] [DataRow("uefi firmware settings", "Images\\firmwareSettings.light.png")] [DataRow("ipv4 addr", "Images\\networkAdapter.light.png", true)] [DataRow("ipv6 addr", "Images\\networkAdapter.light.png", true)] diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System.UnitTests/QueryTests.cs b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System.UnitTests/QueryTests.cs index b474b31666..a0bf470827 100644 --- a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System.UnitTests/QueryTests.cs +++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System.UnitTests/QueryTests.cs @@ -27,7 +27,8 @@ namespace Microsoft.PowerToys.Run.Plugin.System.UnitTests [DataRow("lock", "Lock computer")] [DataRow("sleep", "Put computer to sleep")] [DataRow("hibernate", "Hibernate computer")] - [DataRow("empty recycle", "Empty Recycle Bin")] + [DataRow("recycle b", "Open the Recycle Bin")] + [DataRow("empty recycle", "Open the Recycle Bin")] public void EnvironmentIndependentQueryResults(string typedString, string expectedResult) { // Setup diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System/Components/Commands.cs b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System/Components/Commands.cs index bed3cad550..7e337c2bf5 100644 --- a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System/Components/Commands.cs +++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System/Components/Commands.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.Globalization; +using System.Runtime; using System.Windows; using System.Windows.Interop; using Microsoft.PowerToys.Run.Plugin.System.Properties; @@ -107,25 +108,13 @@ namespace Microsoft.PowerToys.Run.Plugin.System.Components }, new Result { - Title = Resources.ResourceManager.GetString("Microsoft_plugin_sys_emptyrecyclebin", culture), - SubTitle = Resources.ResourceManager.GetString("Microsoft_plugin_sys_emptyrecyclebin_description", culture), + Title = Resources.ResourceManager.GetString("Microsoft_plugin_sys_RecycleBin", culture), + SubTitle = Resources.ResourceManager.GetString("Microsoft_plugin_sys_RecycleBin_description", culture), IcoPath = $"Images\\recyclebin.{iconTheme}.png", + ContextData = new SystemPluginContext { Type = ResultContextType.RecycleBinCommand, SearchTag = Resources.ResourceManager.GetString("Microsoft_plugin_sys_RecycleBin_searchTag", culture) }, Action = c => { - // http://www.pinvoke.net/default.aspx/shell32/SHEmptyRecycleBin.html - // FYI, couldn't find documentation for this but if the recycle bin is already empty, it will return -2147418113 (0x8000FFFF (E_UNEXPECTED)) - // 0 for nothing - var result = NativeMethods.SHEmptyRecycleBin(new WindowInteropHelper(Application.Current.MainWindow).Handle, 0); - if (result != (uint)HRESULT.S_OK && result != 0x8000FFFF) - { - var name = "Plugin: " + Resources.Microsoft_plugin_sys_plugin_name; - var message = $"Error emptying recycle bin, error code: {result}\n" + - "please refer to https://msdn.microsoft.com/en-us/library/windows/desktop/aa378137"; - Log.Error(message, typeof(Commands)); - _ = MessageBox.Show(message, name); - } - - return true; + return Helper.OpenInShell("explorer.exe", "shell:RecycleBinFolder"); }, }, }); diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System/Components/ResultHelper.cs b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System/Components/ResultHelper.cs index 009bd94bf5..b769e61796 100644 --- a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System/Components/ResultHelper.cs +++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System/Components/ResultHelper.cs @@ -4,16 +4,21 @@ using System; using System.Collections.Generic; +using System.Threading.Tasks; using System.Windows; using System.Windows.Input; +using System.Windows.Navigation; using Microsoft.PowerToys.Run.Plugin.System.Properties; using Wox.Plugin; +using Wox.Plugin.Common.Win32; using Wox.Plugin.Logger; namespace Microsoft.PowerToys.Run.Plugin.System.Components { internal static class ResultHelper { + private static bool executingEmptyRecycleBinTask; + internal static bool ExecuteCommand(bool confirm, string confirmationMessage, Action command) { if (confirm) @@ -49,7 +54,18 @@ namespace Microsoft.PowerToys.Run.Plugin.System.Components } } - internal static List GetContextMenuForResult(Result result) + internal static async void EmptyRecycleBinAsync(bool settingEmptyRBSuccesMsg) + { + if (executingEmptyRecycleBinTask) + { + _ = MessageBox.Show(Resources.Microsoft_plugin_sys_RecycleBin_EmptyTaskRunning, "Plugin: " + Resources.Microsoft_plugin_sys_plugin_name, MessageBoxButton.OK, MessageBoxImage.Information); + return; + } + + await Task.Run(() => EmptyRecycleBinTask(settingEmptyRBSuccesMsg)); + } + + internal static List GetContextMenuForResult(Result result, bool settingEmptyRBSuccesMsg) { var contextMenu = new List(); @@ -67,11 +83,62 @@ namespace Microsoft.PowerToys.Run.Plugin.System.Components FontFamily = "Segoe MDL2 Assets", Glyph = "\xE8C8", // E8C8 => Symbol: Copy Title = Resources.Microsoft_plugin_sys_CopyDetails, - Action = _ => ResultHelper.CopyToClipBoard(contextData.Data), + Action = _ => CopyToClipBoard(contextData.Data), + }); + } + + if (contextData.Type == ResultContextType.RecycleBinCommand) + { + contextMenu.Add(new ContextMenuResult() + { + AcceleratorKey = Key.Delete, + AcceleratorModifiers = ModifierKeys.Shift, // Shift+Delete is the common key for deleting without recycle bin + FontFamily = "Segoe MDL2 Assets", + Glyph = "\xE74D", // E74D => Symbol: Delete + Title = Resources.Microsoft_plugin_sys_RecycleBin_contextMenu, + Action = _ => + { + EmptyRecycleBinAsync(settingEmptyRBSuccesMsg); + return true; + }, }); } return contextMenu; } + + /// + /// Method to process the empty recycle bin command in a separate task + /// + private static void EmptyRecycleBinTask(bool settingEmptyRBSuccesMsg) + { + executingEmptyRecycleBinTask = true; + + // https://learn.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-shemptyrecyclebina/ + // http://www.pinvoke.net/default.aspx/shell32/SHEmptyRecycleBin.html/ + // If the recycle bin is already empty, it will return -2147418113 (0x8000FFFF (E_UNEXPECTED)) + // If the user canceled the deletion task it will return 2147943623 (0x800704C7 (E_CANCELLED - The operation was canceled by the user.)) + // On success it will return 0 (S_OK) + var result = NativeMethods.SHEmptyRecycleBin(IntPtr.Zero, 0); + if (result == (uint)HRESULT.E_UNEXPECTED) + { + _ = MessageBox.Show(Resources.Microsoft_plugin_sys_RecycleBin_IsEmpty, "Plugin: " + Resources.Microsoft_plugin_sys_plugin_name, MessageBoxButton.OK, MessageBoxImage.Information); + } + else if (result != (uint)HRESULT.S_OK && result != (uint)HRESULT.E_CANCELLED) + { + var errorDesc = Win32Helpers.MessageFromHResult((int)result); + var name = "Plugin: " + Resources.Microsoft_plugin_sys_plugin_name; + var message = $"{Resources.Microsoft_plugin_sys_RecycleBin_ErrorMsg} {errorDesc}"; + Log.Error(message + " - Please refer to https://msdn.microsoft.com/en-us/library/windows/desktop/aa378137 for more information.", typeof(Commands)); + _ = MessageBox.Show(message, name, MessageBoxButton.OK, MessageBoxImage.Error); + } + + if (result == (uint)HRESULT.S_OK && settingEmptyRBSuccesMsg) + { + _ = MessageBox.Show(Resources.Microsoft_plugin_sys_RecycleBin_EmptySuccessMessage, "Plugin: " + Resources.Microsoft_plugin_sys_plugin_name, MessageBoxButton.OK, MessageBoxImage.Information); + } + + executingEmptyRecycleBinTask = false; + } } } diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System/Components/SystemPluginContext.cs b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System/Components/SystemPluginContext.cs index 0fc8282f96..c6d26c8624 100644 --- a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System/Components/SystemPluginContext.cs +++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System/Components/SystemPluginContext.cs @@ -14,12 +14,18 @@ namespace Microsoft.PowerToys.Run.Plugin.System.Components /// /// Gets or sets the context data for the command/results /// - public string Data { get; set; } + public string Data { get; set; } = string.Empty; + + /// + /// Gets or sets an additional result name for searching + /// + public string SearchTag { get; set; } = string.Empty; } internal enum ResultContextType { Command, // Reserved for later usage NetworkAdapterInfo, + RecycleBinCommand, } } 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 829e81aec5..e6efc47c0a 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 @@ -7,6 +7,7 @@ using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Windows.Controls; +using ControlzEx.Standard; using ManagedCommon; using Microsoft.PowerToys.Run.Plugin.System.Components; using Microsoft.PowerToys.Run.Plugin.System.Properties; @@ -22,6 +23,7 @@ namespace Microsoft.PowerToys.Run.Plugin.System private PluginInitContext _context; private bool _confirmSystemCommands; + private bool _showSuccessOnEmptyRB; private bool _localizeSystemCommands; private bool _reduceNetworkResultScore; @@ -42,6 +44,12 @@ namespace Microsoft.PowerToys.Run.Plugin.System Value = false, }, new PluginAdditionalOption() + { + Key = "ShowSuccessOnEmptyRB", + DisplayLabel = Resources.Microsoft_plugin_sys_RecycleBin_ShowEmptySuccessMessage, + Value = false, + }, + new PluginAdditionalOption() { Key = "LocalizeSystemCommands", DisplayLabel = Resources.Use_localized_system_commands, @@ -92,6 +100,15 @@ namespace Microsoft.PowerToys.Run.Plugin.System c.TitleHighlightData = resultMatch.MatchData; results.Add(c); } + else if (c?.ContextData is SystemPluginContext contextData) + { + var searchTagMatch = StringMatcher.FuzzySearch(query.Search, contextData.SearchTag); + if (searchTagMatch.Score > 0) + { + c.Score = resultMatch.Score; + results.Add(c); + } + } } // The following information result is not returned because delayed queries doesn't clear output if no results are available. @@ -134,6 +151,15 @@ namespace Microsoft.PowerToys.Run.Plugin.System r.SubTitleHighlightData = resultMatch.MatchData; results.Add(r); } + else if (r?.ContextData is SystemPluginContext contextData) + { + var searchTagMatch = StringMatcher.FuzzySearch(query.Search, contextData.SearchTag); + if (searchTagMatch.Score > 0) + { + r.Score = resultMatch.Score; + results.Add(r); + } + } } } @@ -142,7 +168,7 @@ namespace Microsoft.PowerToys.Run.Plugin.System public List LoadContextMenus(Result selectedResult) { - return ResultHelper.GetContextMenuForResult(selectedResult); + return ResultHelper.GetContextMenuForResult(selectedResult, _showSuccessOnEmptyRB); } private void UpdateIconTheme(Theme theme) @@ -180,6 +206,7 @@ namespace Microsoft.PowerToys.Run.Plugin.System public void UpdateSettings(PowerLauncherPluginSettings settings) { var confirmSystemCommands = false; + var showSuccessOnEmptyRB = false; var localizeSystemCommands = true; var reduceNetworkResultScore = true; @@ -188,6 +215,9 @@ namespace Microsoft.PowerToys.Run.Plugin.System var optionConfirm = settings.AdditionalOptions.FirstOrDefault(x => x.Key == "ConfirmSystemCommands"); confirmSystemCommands = optionConfirm?.Value ?? confirmSystemCommands; + var optionEmptyRBSuccessMsg = settings.AdditionalOptions.FirstOrDefault(x => x.Key == "ShowSuccessOnEmptyRB"); + showSuccessOnEmptyRB = optionEmptyRBSuccessMsg?.Value ?? showSuccessOnEmptyRB; + var optionLocalize = settings.AdditionalOptions.FirstOrDefault(x => x.Key == "LocalizeSystemCommands"); localizeSystemCommands = optionLocalize?.Value ?? localizeSystemCommands; @@ -196,6 +226,7 @@ namespace Microsoft.PowerToys.Run.Plugin.System } _confirmSystemCommands = confirmSystemCommands; + _showSuccessOnEmptyRB = showSuccessOnEmptyRB; _localizeSystemCommands = localizeSystemCommands; _reduceNetworkResultScore = reduceNetworkResultScore; } 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 6ac808810b..fe14b50773 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 @@ -168,24 +168,6 @@ namespace Microsoft.PowerToys.Run.Plugin.System.Properties { } } - /// - /// Looks up a localized string similar to Empty Recycle Bin. - /// - internal static string Microsoft_plugin_sys_emptyrecyclebin { - get { - return ResourceManager.GetString("Microsoft_plugin_sys_emptyrecyclebin", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Empty Recycle Bin. - /// - internal static string Microsoft_plugin_sys_emptyrecyclebin_description { - get { - return ResourceManager.GetString("Microsoft_plugin_sys_emptyrecyclebin_description", resourceCulture); - } - } - /// /// Looks up a localized string similar to Default Gateway. /// @@ -402,6 +384,87 @@ namespace Microsoft.PowerToys.Run.Plugin.System.Properties { } } + /// + /// Looks up a localized string similar to Recycle Bin. + /// + internal static string Microsoft_plugin_sys_RecycleBin { + get { + return ResourceManager.GetString("Microsoft_plugin_sys_RecycleBin", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Empty Recycle Bin (Shift+Delete). + /// + internal static string Microsoft_plugin_sys_RecycleBin_contextMenu { + get { + return ResourceManager.GetString("Microsoft_plugin_sys_RecycleBin_contextMenu", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Open the Recycle Bin. + /// + internal static string Microsoft_plugin_sys_RecycleBin_description { + get { + return ResourceManager.GetString("Microsoft_plugin_sys_RecycleBin_description", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Recycle Bin emptied successfully.. + /// + internal static string Microsoft_plugin_sys_RecycleBin_EmptySuccessMessage { + get { + return ResourceManager.GetString("Microsoft_plugin_sys_RecycleBin_EmptySuccessMessage", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to The task to empty the Recycle Bin is already running.. + /// + internal static string Microsoft_plugin_sys_RecycleBin_EmptyTaskRunning { + get { + return ResourceManager.GetString("Microsoft_plugin_sys_RecycleBin_EmptyTaskRunning", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Failed to empty the Recycle Bin:. + /// + internal static string Microsoft_plugin_sys_RecycleBin_ErrorMsg { + get { + return ResourceManager.GetString("Microsoft_plugin_sys_RecycleBin_ErrorMsg", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Recycle Bin is empty.. + /// + internal static string Microsoft_plugin_sys_RecycleBin_IsEmpty { + get { + return ResourceManager.GetString("Microsoft_plugin_sys_RecycleBin_IsEmpty", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Empty Recycle Bin. + /// + internal static string Microsoft_plugin_sys_RecycleBin_searchTag { + get { + return ResourceManager.GetString("Microsoft_plugin_sys_RecycleBin_searchTag", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Show a success message after empty the Recycle Bin. + /// + internal static string Microsoft_plugin_sys_RecycleBin_ShowEmptySuccessMessage { + get { + return ResourceManager.GetString("Microsoft_plugin_sys_RecycleBin_ShowEmptySuccessMessage", resourceCulture); + } + } + /// /// Looks up a localized string similar to Restart. /// 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 ac60fb3d6d..5d6c53aae8 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 @@ -155,14 +155,6 @@ DNS servers - - Empty Recycle Bin - This should align to the action in Windows of emptying the recycle bin on your computer. - - - Empty Recycle Bin - This should align to the action in Windows of emptying the recycle bin on your computer. - Default Gateway @@ -248,6 +240,41 @@ Windows System Commands Windows operating system commands. + + Recycle Bin + Means the recycle bin folder in Explorer. + + + Empty Recycle Bin (Shift+Delete) + This should align to the action in Windows of emptying the recycle bin on your computer. + + + Open the Recycle Bin + This should align to the action in Windows of emptying the recycle bin on your computer. + + + Recycle Bin emptied successfully. + Means the recycle bin folder in Explorer. + + + The task to empty the Recycle Bin is already running. + Means the recycle bin folder in Explorer. + + + Failed to empty the Recycle Bin: + + + Recycle Bin is empty. + Means the recycle bin folder in Explorer. + + + Empty Recycle Bin + This should align to the action in Windows of emptying the recycle bin on your computer. + + + Show a success message after emptying the Recycle Bin + Means the recycle bin folder in Explorer and "emptying" refers to "Empty Recycle Bin" command. + Restart This should align to the action in Windows of a restarting your computer. diff --git a/src/modules/launcher/Wox.Plugin/Common/Win32/NativeMethods.cs b/src/modules/launcher/Wox.Plugin/Common/Win32/NativeMethods.cs index 2260ceca3d..d7f1228f7e 100644 --- a/src/modules/launcher/Wox.Plugin/Common/Win32/NativeMethods.cs +++ b/src/modules/launcher/Wox.Plugin/Common/Win32/NativeMethods.cs @@ -202,6 +202,13 @@ namespace Wox.Plugin.Common.Win32 /// One or more arguments are not valid. /// E_INVALIDARG = 0x80070057, + + /// + /// The operation was canceled by the user. (Error source 7 means Win32.) + /// + /// + /// + E_CANCELLED = 0x800704C7, } /// diff --git a/src/modules/launcher/Wox.Plugin/Common/Win32/Win32Helpers.cs b/src/modules/launcher/Wox.Plugin/Common/Win32/Win32Helpers.cs index a517a4d7d4..bf5aa9b901 100644 --- a/src/modules/launcher/Wox.Plugin/Common/Win32/Win32Helpers.cs +++ b/src/modules/launcher/Wox.Plugin/Common/Win32/Win32Helpers.cs @@ -44,5 +44,15 @@ namespace Wox.Plugin.Common.Win32 return NativeMethods.CloseHandle(handle); } + + /// + /// Gets the description for an HRESULT error code. + /// + /// The HRESULT number + /// A string containing the description. + public static string MessageFromHResult(int hr) + { + return Marshal.GetExceptionForHR(hr).Message; + } } }