From 471bb3bba22a6b463b45fa412032def93afb9247 Mon Sep 17 00:00:00 2001 From: Davide Giacometti Date: Tue, 2 May 2023 13:10:54 +0200 Subject: [PATCH] [Run]New plugin to start other PowerToys (#24934) * PowerToys plugin * bring setting window to foreground * resources * fix deep linking always opening general page * dll signing * setup * registry preview added * align registry preview icon and setup * fix setup * fix setup build * PR feedbacks addressed --- .pipelines/ESRPSigning_core.json | 3 +- PowerToys.sln | 16 ++ installer/PowerToysSetup/Product.wxs | 3 + installer/PowerToysSetup/Resources.wxs | 2 +- installer/PowerToysSetup/Run.wxs | 18 ++ src/common/Common.UI/SettingsDeepLink.cs | 8 +- src/common/interop/interop.cpp | 10 +- src/common/interop/shared_constants.h | 4 + .../Hosts/HostsModuleInterface/dllmain.cpp | 73 ++++++++ .../Components/Utility.cs | 96 ++++++++++ .../Components/UtilityHelper.cs | 115 ++++++++++++ .../Components/UtilityKey.cs | 17 ++ .../Components/UtilityProvider.cs | 148 +++++++++++++++ .../Images/ColorPicker.png | Bin 0 -> 1593 bytes .../Images/FancyZones.png | Bin 0 -> 968 bytes .../Images/Hosts.png | Bin 0 -> 1770 bytes .../Images/PowerOcr.png | Bin 0 -> 921 bytes .../Images/PowerToys.dark.png | Bin 0 -> 329 bytes .../Images/PowerToys.light.png | Bin 0 -> 320 bytes .../Images/RegistryPreview.png | Bin 0 -> 1746 bytes .../Images/ScreenRuler.png | Bin 0 -> 1770 bytes .../Images/ShortcutGuide.png | Bin 0 -> 2259 bytes .../Main.cs | 74 ++++++++ ...soft.PowerToys.Run.Plugin.PowerToys.csproj | 96 ++++++++++ .../Properties/Resources.Designer.cs | 171 ++++++++++++++++++ .../Properties/Resources.resx | 163 +++++++++++++++++ .../plugin.json | 14 ++ src/runner/settings_window.cpp | 22 ++- src/runner/settings_window.h | 2 + src/settings-ui/Settings.UI/App.xaml.cs | 67 ++++--- src/settings-ui/Settings.UI/MainWindow.xaml | 2 +- .../Settings.UI/MainWindow.xaml.cs | 7 +- .../Settings.UI/Views/ShellPage.xaml.cs | 6 +- 33 files changed, 1096 insertions(+), 41 deletions(-) create mode 100644 src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Components/Utility.cs create mode 100644 src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Components/UtilityHelper.cs create mode 100644 src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Components/UtilityKey.cs create mode 100644 src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Components/UtilityProvider.cs create mode 100644 src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Images/ColorPicker.png create mode 100644 src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Images/FancyZones.png create mode 100644 src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Images/Hosts.png create mode 100644 src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Images/PowerOcr.png create mode 100644 src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Images/PowerToys.dark.png create mode 100644 src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Images/PowerToys.light.png create mode 100644 src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Images/RegistryPreview.png create mode 100644 src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Images/ScreenRuler.png create mode 100644 src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Images/ShortcutGuide.png create mode 100644 src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Main.cs create mode 100644 src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Microsoft.PowerToys.Run.Plugin.PowerToys.csproj create mode 100644 src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Properties/Resources.Designer.cs create mode 100644 src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Properties/Resources.resx create mode 100644 src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/plugin.json diff --git a/.pipelines/ESRPSigning_core.json b/.pipelines/ESRPSigning_core.json index 117385722e..fd0aedc5ae 100644 --- a/.pipelines/ESRPSigning_core.json +++ b/.pipelines/ESRPSigning_core.json @@ -109,7 +109,8 @@ "modules\\launcher\\Plugins\\Folder\\Microsoft.Plugin.Folder.dll", "modules\\launcher\\Plugins\\Indexer\\Microsoft.Plugin.Indexer.dll", "modules\\launcher\\Plugins\\OneNote\\Microsoft.PowerToys.Run.Plugin.OneNote.dll", - "modules\\launcher\\Plugins\\History\\Microsoft.PowerToys.Run.Plugin.History.dll", + "modules\\launcher\\Plugins\\History\\Microsoft.PowerToys.Run.Plugin.History.dll", + "modules\\launcher\\Plugins\\PowerToys\\Microsoft.PowerToys.Run.Plugin.PowerToys.dll", "modules\\launcher\\Plugins\\Program\\Microsoft.Plugin.Program.dll", "modules\\launcher\\Plugins\\Registry\\Microsoft.PowerToys.Run.Plugin.Registry.dll", "modules\\launcher\\Plugins\\WindowsSettings\\Microsoft.PowerToys.Run.Plugin.WindowsSettings.dll", diff --git a/PowerToys.sln b/PowerToys.sln index ec3bdfde46..5bc55a0c74 100644 --- a/PowerToys.sln +++ b/PowerToys.sln @@ -129,6 +129,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PowerLauncher", "src\module {0351ADA4-0C32-4652-9BA0-41F7B602372B} = {0351ADA4-0C32-4652-9BA0-41F7B602372B} {4BABF3FE-3451-42FD-873F-3C332E18DCEF} = {4BABF3FE-3451-42FD-873F-3C332E18DCEF} {4D971245-7A70-41D5-BAA0-DDB5684CAF51} = {4D971245-7A70-41D5-BAA0-DDB5684CAF51} + {500DED3E-CFB5-4ED5-ACC6-02B3D6DC336D} = {500DED3E-CFB5-4ED5-ACC6-02B3D6DC336D} {5043CECE-E6A7-4867-9CBE-02D27D83747A} = {5043CECE-E6A7-4867-9CBE-02D27D83747A} {59BD9891-3837-438A-958D-ADC7F91F6F7E} = {59BD9891-3837-438A-958D-ADC7F91F6F7E} {5A1DB2F0-0715-4B3B-98E6-79BC41540045} = {5A1DB2F0-0715-4B3B-98E6-79BC41540045} @@ -500,6 +501,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RegistryPreviewExt", "src\m EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "RegistryPreview", "RegistryPreview", "{929C1324-22E8-4412-A9A8-80E85F3985A5}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.PowerToys.Run.Plugin.PowerToys", "src\modules\launcher\Plugins\Microsoft.PowerToys.Run.Plugin.PowerToys\Microsoft.PowerToys.Run.Plugin.PowerToys.csproj", "{500DED3E-CFB5-4ED5-ACC6-02B3D6DC336D}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|ARM64 = Debug|ARM64 @@ -2096,6 +2099,18 @@ Global {697C6AF9-0A48-49A9-866C-67DA12384015}.Release|x64.Build.0 = Release|x64 {697C6AF9-0A48-49A9-866C-67DA12384015}.Release|x86.ActiveCfg = Release|x64 {697C6AF9-0A48-49A9-866C-67DA12384015}.Release|x86.Build.0 = Release|x64 + {500DED3E-CFB5-4ED5-ACC6-02B3D6DC336D}.Debug|ARM64.ActiveCfg = Debug|ARM64 + {500DED3E-CFB5-4ED5-ACC6-02B3D6DC336D}.Debug|ARM64.Build.0 = Debug|ARM64 + {500DED3E-CFB5-4ED5-ACC6-02B3D6DC336D}.Debug|x64.ActiveCfg = Debug|x64 + {500DED3E-CFB5-4ED5-ACC6-02B3D6DC336D}.Debug|x64.Build.0 = Debug|x64 + {500DED3E-CFB5-4ED5-ACC6-02B3D6DC336D}.Debug|x86.ActiveCfg = Debug|x64 + {500DED3E-CFB5-4ED5-ACC6-02B3D6DC336D}.Debug|x86.Build.0 = Debug|x64 + {500DED3E-CFB5-4ED5-ACC6-02B3D6DC336D}.Release|ARM64.ActiveCfg = Release|ARM64 + {500DED3E-CFB5-4ED5-ACC6-02B3D6DC336D}.Release|ARM64.Build.0 = Release|ARM64 + {500DED3E-CFB5-4ED5-ACC6-02B3D6DC336D}.Release|x64.ActiveCfg = Release|x64 + {500DED3E-CFB5-4ED5-ACC6-02B3D6DC336D}.Release|x64.Build.0 = Release|x64 + {500DED3E-CFB5-4ED5-ACC6-02B3D6DC336D}.Release|x86.ActiveCfg = Release|x64 + {500DED3E-CFB5-4ED5-ACC6-02B3D6DC336D}.Release|x86.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -2273,6 +2288,7 @@ Global {FD86C06A-FB54-4D5E-9831-1CDADF60D45F} = {929C1324-22E8-4412-A9A8-80E85F3985A5} {697C6AF9-0A48-49A9-866C-67DA12384015} = {929C1324-22E8-4412-A9A8-80E85F3985A5} {929C1324-22E8-4412-A9A8-80E85F3985A5} = {4574FDD0-F61D-4376-98BF-E5A1262C11EC} + {500DED3E-CFB5-4ED5-ACC6-02B3D6DC336D} = {4AFC9975-2456-4C70-94A4-84073C1CED93} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {C3A2F9D1-7930-4EF4-A6FC-7EE0A99821D0} diff --git a/installer/PowerToysSetup/Product.wxs b/installer/PowerToysSetup/Product.wxs index a45d0e4044..0d6bf0dbd2 100644 --- a/installer/PowerToysSetup/Product.wxs +++ b/installer/PowerToysSetup/Product.wxs @@ -570,6 +570,9 @@ + + + diff --git a/installer/PowerToysSetup/Resources.wxs b/installer/PowerToysSetup/Resources.wxs index 351bd05393..459fbaa533 100644 --- a/installer/PowerToysSetup/Resources.wxs +++ b/installer/PowerToysSetup/Resources.wxs @@ -11,7 +11,7 @@ - + diff --git a/installer/PowerToysSetup/Run.wxs b/installer/PowerToysSetup/Run.wxs index 9d22b64156..2f4f5a0b96 100644 --- a/installer/PowerToysSetup/Run.wxs +++ b/installer/PowerToysSetup/Run.wxs @@ -100,6 +100,11 @@ + + + + + @@ -311,6 +316,17 @@ + + + + + + + + + + + @@ -355,6 +371,8 @@ + + diff --git a/src/common/Common.UI/SettingsDeepLink.cs b/src/common/Common.UI/SettingsDeepLink.cs index c63f3fc1ad..6e883e110c 100644 --- a/src/common/Common.UI/SettingsDeepLink.cs +++ b/src/common/Common.UI/SettingsDeepLink.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation +// Copyright (c) Microsoft Corporation // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -24,6 +24,8 @@ namespace Common.UI ShortcutGuide, VideoConference, Hosts, + MeasureTool, + PowerOCR, RegistryPreview, } @@ -57,6 +59,10 @@ namespace Common.UI return "VideoConference"; case SettingsWindow.Hosts: return "Hosts"; + case SettingsWindow.MeasureTool: + return "MeasureTool"; + case SettingsWindow.PowerOCR: + return "PowerOCR"; case SettingsWindow.RegistryPreview: return "RegistryPreview"; default: diff --git a/src/common/interop/interop.cpp b/src/common/interop/interop.cpp index ae63efa64b..a06f10efcb 100644 --- a/src/common/interop/interop.cpp +++ b/src/common/interop/interop.cpp @@ -188,7 +188,7 @@ public } static String ^ FZEToggleEvent() { - return gcnew String(CommonSharedConstants::FANCY_ZONES_EDITOR_TOGGLE_EVENT); + return gcnew String(CommonSharedConstants::FANCY_ZONES_EDITOR_TOGGLE_EVENT); } static String ^ ColorPickerSendSettingsTelemetryEvent() { @@ -242,5 +242,13 @@ public static String ^ SvgPreviewResizeEvent() { return gcnew String(CommonSharedConstants::SVG_PREVIEW_RESIZE_EVENT); } + + static String ^ ShowHostsSharedEvent() { + return gcnew String(CommonSharedConstants::SHOW_HOSTS_EVENT); + } + + static String ^ ShowHostsAdminSharedEvent() { + return gcnew String(CommonSharedConstants::SHOW_HOSTS_ADMIN_EVENT); + } }; } diff --git a/src/common/interop/shared_constants.h b/src/common/interop/shared_constants.h index 7f8c0bbd7e..66cc0f8eac 100644 --- a/src/common/interop/shared_constants.h +++ b/src/common/interop/shared_constants.h @@ -34,6 +34,10 @@ namespace CommonSharedConstants const wchar_t FANCY_ZONES_EDITOR_TOGGLE_EVENT[] = L"Local\\FancyZones-ToggleEditorEvent-1e174338-06a3-472b-874d-073b21c62f14"; + const wchar_t SHOW_HOSTS_EVENT[] = L"Local\\Hosts-ShowHostsEvent-5a0c0aae-5ff5-40f5-95c2-20e37ed671f0"; + + const wchar_t SHOW_HOSTS_ADMIN_EVENT[] = L"Local\\Hosts-ShowHostsAdminEvent-60ff44e2-efd3-43bf-928a-f4d269f98bec"; + // Path to the event used by Awake const wchar_t AWAKE_EXIT_EVENT[] = L"Local\\PowerToysAwakeExitEvent-c0d5e305-35fc-4fb5-83ec-f6070cfaf7fe"; diff --git a/src/modules/Hosts/HostsModuleInterface/dllmain.cpp b/src/modules/Hosts/HostsModuleInterface/dllmain.cpp index aeb05ba2e6..ec1a705903 100644 --- a/src/modules/Hosts/HostsModuleInterface/dllmain.cpp +++ b/src/modules/Hosts/HostsModuleInterface/dllmain.cpp @@ -7,6 +7,8 @@ #include "Generated Files/resource.h" #include +#include +#include #include #include #include @@ -49,6 +51,10 @@ private: HANDLE m_hProcess; + HANDLE m_hShowEvent; + + HANDLE m_hShowAdminEvent; + bool is_process_running() { return WaitForSingleObject(m_hProcess, 0) == WAIT_TIMEOUT; @@ -104,11 +110,55 @@ private: } public: + EventWaiter m_showEventWaiter; + + EventWaiter m_showAdminEventWaiter; + HostsModuleInterface() { app_name = GET_RESOURCE_STRING(IDS_HOSTS_NAME); app_key = ModuleKey; LoggerHelpers::init_logger(app_key, L"ModuleInterface", LogSettings::hostsLoggerName); + + m_hShowEvent = CreateDefaultEvent(CommonSharedConstants::SHOW_HOSTS_EVENT); + if (!m_hShowEvent) + { + Logger::error(L"Failed to create show hosts event"); + auto message = get_last_error_message(GetLastError()); + if (message.has_value()) + { + Logger::error(message.value()); + } + } + + m_hShowAdminEvent = CreateDefaultEvent(CommonSharedConstants::SHOW_HOSTS_ADMIN_EVENT); + if (!m_hShowEvent) + { + Logger::error(L"Failed to create show hosts admin event"); + auto message = get_last_error_message(GetLastError()); + if (message.has_value()) + { + Logger::error(message.value()); + } + } + + m_showEventWaiter = EventWaiter(CommonSharedConstants::SHOW_HOSTS_EVENT, [&](int err) + { + if (m_enabled && err == ERROR_SUCCESS) + { + Logger::trace(L"{} event was signaled", CommonSharedConstants::SHOW_HOSTS_EVENT); + launch_process(false); + } + }); + + m_showAdminEventWaiter = EventWaiter(CommonSharedConstants::SHOW_HOSTS_ADMIN_EVENT, [&](int err) + { + if (m_enabled && err == ERROR_SUCCESS) + { + Logger::trace(L"{} event was signaled", CommonSharedConstants::SHOW_HOSTS_ADMIN_EVENT); + launch_process(true); + } + }); } ~HostsModuleInterface() @@ -120,6 +170,19 @@ public: virtual void destroy() override { Logger::trace("HostsModuleInterface::destroy()"); + + if (m_hShowEvent) + { + CloseHandle(m_hShowEvent); + m_hShowEvent = nullptr; + } + + if (m_hShowAdminEvent) + { + CloseHandle(m_hShowAdminEvent); + m_hShowAdminEvent = nullptr; + } + delete this; } @@ -194,6 +257,16 @@ public: Logger::trace("HostsModuleInterface::disable()"); if (m_enabled) { + if (m_hShowEvent) + { + ResetEvent(m_hShowEvent); + } + + if (m_hShowAdminEvent) + { + ResetEvent(m_hShowAdminEvent); + } + TerminateProcess(m_hProcess, 1); } diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Components/Utility.cs b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Components/Utility.cs new file mode 100644 index 0000000000..7359eb32ac --- /dev/null +++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Components/Utility.cs @@ -0,0 +1,96 @@ +// Copyright (c) Microsoft Corporation +// The Microsoft Corporation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Collections.Generic; +using System.Threading; +using System.Windows.Input; +using Common.UI; +using interop; +using Microsoft.PowerToys.Run.Plugin.PowerToys.Properties; +using Wox.Infrastructure; +using Wox.Plugin; + +namespace Microsoft.PowerToys.Run.Plugin.PowerToys.Components +{ + public class Utility + { + public UtilityKey Key { get; } + + public string Name { get; } + + public bool Enabled { get; private set; } + + public Utility(UtilityKey key, string name, bool enabled) + { + Key = key; + Name = name; + Enabled = enabled; + } + + public Result CreateResult(MatchResult matchResult) + { + return new Result + { + Title = Name, + SubTitle = Resources.Subtitle_Powertoys_Utility, + IcoPath = UtilityHelper.GetIcoPath(Key), + Action = UtilityHelper.GetAction(Key), + ContextData = this, + Score = matchResult.Score, + TitleHighlightData = matchResult.MatchData, + }; + } + + public List CreateContextMenuResults() + { + var results = new List(); + + if (Key == UtilityKey.Hosts) + { + results.Add(new ContextMenuResult + { + Title = Resources.Action_Run_As_Administrator, + Glyph = "\xE7EF", + FontFamily = "Segoe MDL2 Assets", + AcceleratorKey = System.Windows.Input.Key.Enter, + AcceleratorModifiers = ModifierKeys.Control | ModifierKeys.Shift, + Action = _ => + { + using (var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, Constants.ShowHostsAdminSharedEvent())) + { + eventHandle.Set(); + } + + return true; + }, + }); + } + + var settingsWindow = UtilityHelper.GetSettingsWindow(Key); + if (settingsWindow.HasValue) + { + results.Add(new ContextMenuResult + { + Title = Resources.Action_Open_Settings, + Glyph = "\xE713", + FontFamily = "Segoe MDL2 Assets", + AcceleratorKey = System.Windows.Input.Key.S, + AcceleratorModifiers = ModifierKeys.Control | ModifierKeys.Shift, + Action = _ => + { + SettingsDeepLink.OpenSettings(settingsWindow.Value); + return true; + }, + }); + } + + return results; + } + + public void Enable(bool enabled) + { + Enabled = enabled; + } + } +} diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Components/UtilityHelper.cs b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Components/UtilityHelper.cs new file mode 100644 index 0000000000..621ef44c6a --- /dev/null +++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Components/UtilityHelper.cs @@ -0,0 +1,115 @@ +// Copyright (c) Microsoft Corporation +// The Microsoft Corporation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Threading; +using Common.UI; +using interop; +using Wox.Plugin; + +namespace Microsoft.PowerToys.Run.Plugin.PowerToys.Components +{ + public static class UtilityHelper + { + public static string GetIcoPath(UtilityKey key) + { + return key switch + { + UtilityKey.ColorPicker => "Images/ColorPicker.png", + UtilityKey.FancyZones => "Images/FancyZones.png", + UtilityKey.Hosts => "Images/Hosts.png", + UtilityKey.MeasureTool => "Images/ScreenRuler.png", + UtilityKey.PowerOCR => "Images/PowerOcr.png", + UtilityKey.ShortcutGuide => "Images/ShortcutGuide.png", + UtilityKey.RegistryPreview => "Images/RegistryPreview.png", + _ => null, + }; + } + + public static SettingsDeepLink.SettingsWindow? GetSettingsWindow(UtilityKey key) + { + return key switch + { + UtilityKey.ColorPicker => SettingsDeepLink.SettingsWindow.ColorPicker, + UtilityKey.FancyZones => SettingsDeepLink.SettingsWindow.FancyZones, + UtilityKey.Hosts => SettingsDeepLink.SettingsWindow.Hosts, + UtilityKey.MeasureTool => SettingsDeepLink.SettingsWindow.MeasureTool, + UtilityKey.PowerOCR => SettingsDeepLink.SettingsWindow.PowerOCR, + UtilityKey.ShortcutGuide => SettingsDeepLink.SettingsWindow.ShortcutGuide, + UtilityKey.RegistryPreview => SettingsDeepLink.SettingsWindow.RegistryPreview, + _ => null, + }; + } + + public static Func GetAction(UtilityKey key) + { + return (context) => + { + switch (key) + { + case UtilityKey.ColorPicker: // Launch ColorPicker + using (var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, Constants.ShowColorPickerSharedEvent())) + { + eventHandle.Set(); + } + + break; + case UtilityKey.FancyZones: // Launch FancyZones Editor + using (var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, Constants.FZEToggleEvent())) + { + eventHandle.Set(); + } + + break; + + case UtilityKey.Hosts: // Launch Hosts + { + using (var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, Constants.ShowHostsSharedEvent())) + { + eventHandle.Set(); + } + } + + break; + + case UtilityKey.MeasureTool: // Launch Screen Ruler + using (var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, Constants.MeasureToolTriggerEvent())) + { + eventHandle.Set(); + } + + break; + case UtilityKey.PowerOCR: // Launch Text Extractor + using (var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, Constants.ShowPowerOCRSharedEvent())) + { + eventHandle.Set(); + } + + break; + + case UtilityKey.ShortcutGuide: // Launch Shortcut Guide + using (var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, Constants.ShortcutGuideTriggerEvent())) + { + eventHandle.Set(); + } + + break; + + case UtilityKey.RegistryPreview: // Launch Registry Preview + using (var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, Constants.RegistryPreviewTriggerEvent())) + { + eventHandle.Set(); + } + + break; + + default: + break; + } + + return true; + }; + } + } +} diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Components/UtilityKey.cs b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Components/UtilityKey.cs new file mode 100644 index 0000000000..4276e0988b --- /dev/null +++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Components/UtilityKey.cs @@ -0,0 +1,17 @@ +// Copyright (c) Microsoft Corporation +// The Microsoft Corporation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace Microsoft.PowerToys.Run.Plugin.PowerToys.Components +{ + public enum UtilityKey + { + ColorPicker = 0, + FancyZones = 1, + Hosts = 2, + MeasureTool = 3, + PowerOCR = 4, + ShortcutGuide = 5, + RegistryPreview = 6, + } +} diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Components/UtilityProvider.cs b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Components/UtilityProvider.cs new file mode 100644 index 0000000000..314a81728e --- /dev/null +++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Components/UtilityProvider.cs @@ -0,0 +1,148 @@ +// Copyright (c) Microsoft Corporation +// The Microsoft Corporation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Threading; +using Microsoft.PowerToys.Run.Plugin.PowerToys.Components; +using Microsoft.PowerToys.Run.Plugin.PowerToys.Properties; +using Microsoft.PowerToys.Settings.UI.Library; +using PowerToys.GPOWrapper; +using Wox.Plugin.Logger; + +namespace Microsoft.PowerToys.Run.Plugin.PowerToys +{ + public class UtilityProvider : IDisposable + { + private const int MaxNumberOfRetry = 5; + private readonly List _utilities; + private readonly FileSystemWatcher _watcher; + private readonly object _loadingSettingsLock = new(); + private bool _disposed; + + public UtilityProvider() + { + var settingsUtils = new SettingsUtils(); + var generalSettings = settingsUtils.GetSettings(); + + _utilities = new List(); + + if (GPOWrapper.GetConfiguredColorPickerEnabledValue() != GpoRuleConfigured.Disabled) + { + _utilities.Add(new Utility(UtilityKey.ColorPicker, Resources.Color_Picker, generalSettings.Enabled.ColorPicker)); + } + + if (GPOWrapper.GetConfiguredFancyZonesEnabledValue() != GpoRuleConfigured.Disabled) + { + _utilities.Add(new Utility(UtilityKey.FancyZones, Resources.FancyZones_Editor, generalSettings.Enabled.FancyZones)); + } + + if (GPOWrapper.GetConfiguredHostsFileEditorEnabledValue() != GpoRuleConfigured.Disabled) + { + _utilities.Add(new Utility(UtilityKey.Hosts, Resources.Hosts_File_Editor, generalSettings.Enabled.Hosts)); + } + + if (GPOWrapper.GetConfiguredScreenRulerEnabledValue() != GpoRuleConfigured.Disabled) + { + _utilities.Add(new Utility(UtilityKey.MeasureTool, Resources.Screen_Ruler, generalSettings.Enabled.MeasureTool)); + } + + if (GPOWrapper.GetConfiguredTextExtractorEnabledValue() != GpoRuleConfigured.Disabled) + { + _utilities.Add(new Utility(UtilityKey.PowerOCR, Resources.Text_Extractor, generalSettings.Enabled.PowerOCR)); + } + + if (GPOWrapper.GetConfiguredShortcutGuideEnabledValue() != GpoRuleConfigured.Disabled) + { + _utilities.Add(new Utility(UtilityKey.ShortcutGuide, Resources.Shortcut_Guide, generalSettings.Enabled.ShortcutGuide)); + } + + if (GPOWrapper.GetConfiguredRegistryPreviewEnabledValue() != GpoRuleConfigured.Disabled) + { + _utilities.Add(new Utility(UtilityKey.RegistryPreview, Resources.Registry_Preview, generalSettings.Enabled.RegistryPreview)); + } + + _watcher = new FileSystemWatcher + { + Path = Path.GetDirectoryName(settingsUtils.GetSettingsFilePath()), + Filter = Path.GetFileName(settingsUtils.GetSettingsFilePath()), + NotifyFilter = NotifyFilters.LastWrite, + }; + + _watcher.Changed += (s, e) => ReloadUtilities(); + _watcher.EnableRaisingEvents = true; + } + + public IEnumerable GetEnabledUtilities() + { + return _utilities.Where(u => u.Enabled); + } + + private void ReloadUtilities() + { + lock (_loadingSettingsLock) + { + var retry = true; + var retryCount = 0; + + while (retry) + { + try + { + retryCount++; + + var settingsUtils = new SettingsUtils(); + var generalSettings = settingsUtils.GetSettings(); + + foreach (var u in _utilities) + { + switch (u.Key) + { + case UtilityKey.ColorPicker: u.Enable(generalSettings.Enabled.ColorPicker); break; + case UtilityKey.FancyZones: u.Enable(generalSettings.Enabled.FancyZones); break; + case UtilityKey.Hosts: u.Enable(generalSettings.Enabled.Hosts); break; + case UtilityKey.PowerOCR: u.Enable(generalSettings.Enabled.PowerOCR); break; + case UtilityKey.MeasureTool: u.Enable(generalSettings.Enabled.MeasureTool); break; + case UtilityKey.ShortcutGuide: u.Enable(generalSettings.Enabled.ShortcutGuide); break; + case UtilityKey.RegistryPreview: u.Enable(generalSettings.Enabled.RegistryPreview); break; + } + } + + retry = false; + } + catch (Exception ex) + { + if (retryCount > MaxNumberOfRetry) + { + Log.Exception("Failed to read changed settings", ex, typeof(UtilityProvider)); + retry = false; + } + + Thread.Sleep(500); + } + } + } + } + + public void Dispose() + { + Dispose(disposing: true); + GC.SuppressFinalize(this); + } + + protected virtual void Dispose(bool disposing) + { + if (!_disposed) + { + if (disposing) + { + _watcher?.Dispose(); + _disposed = true; + } + } + } + } +} diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Images/ColorPicker.png b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Images/ColorPicker.png new file mode 100644 index 0000000000000000000000000000000000000000..7fed1522277d93ae8ea7ea5e4d0e395fd5fceed4 GIT binary patch literal 1593 zcmV-92FCe`P)0&Ec;AOqqL8S$}YN;p$9m)fdd%eK%^J}ju7sk2v!eJ0stJWBftnHLlI(h zgkc62Kms$KE$LQ@`YO&*%k^>MOJ)iDk4G?W@Moki;Jnn}NZ_4d0RMBKEhbJwx{D&n zg*&)-N435D41kRP?z|pj9C+(G3_4!UqFhK67a>6@=1&8@@?QfoCT8 zMHf(j$PWP`(7H;*0>mXG;Ryp3u<(p9TgA)fdn9wS^*3{FA!MC*tM%eW?hbd*^Rl$bQyX}P%`fM`K$QD zNvl-)P$n3xyt}{2i5~<2q4(UJY;$Pc*}QbOUMvBQ08;SMk5fR21VaI{yGs^V`TO&C z_F*!b%_h;s%vj*}&z|AFpWnrAPFy9MD`P3-AU=S?_kq(XCL_4sN=2oTb)M5i7WAsmGQ+)UTg5#>0Ox&yP;)Vf!w?LRP56cd&3eX$Wrn z+Xn?b0wupm&kGg6A%wm%Ia#mGkuTWZhnb+&T*W0+T!M)!S~)c4c-{CPf5TDV`mQFg zgWN&-8sf1GP38gvOhOE+GFqXqZc~TQZF9s6cXEquleAiGM1pY%k790aj?<6$^%W1j z?}Hx&EZf%W{aW)k+Dp6nbP!-L2n5Nd(H5l)Ar&w=)?ML<=kMUw+Y1VmK*jt!$GM&DY!74CxRKfnmwxO2e_}yE&DJ_1q>vZ zxDGSU@n@aS9p3#H^4q=Ss`|5TM)$jKr?+$k8%zSiNa}b}L!`PRSnUb&Ret`oh5ayI zz_<%Z^rAC2JHbh3p2r>Edj$FBYf)X8w79lLxYvuY3r<7r*2X}>VNex@TgLurw{mVd z?cDSF<8<0<_>fI;9cG+U&c1-#zwbyoo3_)~K8yDxvxrSBVAq|X6W2fo1Tp|{A%+)( z!hoIv>{{lDcb^6_*1D^J_FrPux=qKOem-~lKp&>Do%)V>JUU1Q0d;$XMuTcMM>0Tw z54Fr8AP^fb2!pYF#Xg>Tw{hNZziq6o;mx z^ z0Yx8#!6goLvO!*Hv~|?V9DnYWboR|NF*yVDfF7^>;-C1`kIskc6k*$TYEu)*ronQE zLkE%z*myxGU~F@hvoC`Ce&Vlu>QUEWx>4cnKRJu9{bd<$cq?l48ekBWRy6<;2sj)d z95A8bmLVtrK{OWU`11wMZ9j4Xp$svOQ@!C03FR_!ffCHHGLj!UP(%ccUJwrE$z(LP zEzrrYL3B~8WPlZUQL<=AWl4u;892g*Q~{w8D_E$MD=BX&xI+r3=XCg%83H)Sid9M$ zZoE}Fa`AEap*CZ~6>AFUsMkk-4h=#bW`;&?C&MU(Mk@%z05AgZFn|<*a7X~89~}<= z#?XMUL$~bmJX*~nQ)SdU@V`z06^w=&p`1euI%J^yzH{FT&5mbhF1=CZa5><^KQz3c r9IeW*vI3Zba13?M;SlF)cS!FaNRv-w;dDss00000NkvXXu0mjfoWt;s literal 0 HcmV?d00001 diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Images/FancyZones.png b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Images/FancyZones.png new file mode 100644 index 0000000000000000000000000000000000000000..1d70bbb9598a863bf178151e7b280004f79f8547 GIT binary patch literal 968 zcmV;(12_DMP)KavzWV_uoMM#c{lgdqp?G?cOyUQ6T77?!0Vm5Oul_>1Lbu&MpoHV5 zy}ahk_Kyu9$&8?8BZHYYB62);eN9HPo#`~2bIdG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D zpTyH|-e|gz!l~QGtW$r3F&3QGX@wpgWv^ zZ+A6aOrqEB;?d{Nb;KLN+_@RB3oS9R-!t%r1tU~I0#oW}Y*fdmGxF%W1uIFqkU+27 zN26lx?K-a4?cu|_n&zjn0;s(F?k!5QdGTTq;*ujqnQRyj30$3pnIlsiLnINwxtmAK zTnD^Sj0Bx^`TwVXvmB_X$l!IEIWvuk;}iB-ABu^i<5+#P0wqZ4i%f|47KG^%gi0Q}!loNj`sfLmm*(}TJRz>nH7!kSuraCm_pvSUPI9$#msA{L5p zr3F=WJBS7EOCl3Dvzwo+dsTRh@TRu=VOCP!t77K(gtTXKhLluc4DnPUNE&zItGb9X$peCsfXU^WrK2iZ+2K;F^T2d=F;3cB=yj5>& zyYcI_Q*Xgb#P0sJEI z2+sWXq-?#}R=?X5+S)F;xuR@7TSH~1g8ZS9!SLPEjv+wkO=>DYh|wXmCI5K2Epg%J z1(`ZAg~D7OokmmYm6i@vQ+1Oc$zsavRN48UiELb^&d$r~-M7P8=F`}m2B8$DVO3PtEGa!v)l~%it~} z44$Mw_>xf|Dm$ci<9!{^K6#?E7v?24S2Q0Tx^WCUuQw$(UqmdM5HAtIz{CrmKSJ<% z6=Aol4_7iCD4as1u2?WGFn1XM@9noQ5zizvJ(-haDUCo8iO|7i&No}X1A~dZ} zXbRx7OjHbEOXgzd%1Pw&#PZkQ*G&PyC+~*qFAoS&Cp8>{%$CGUD{RRKJ8p>NC8PW; z1O@yIx#F@W(Rp-XLWC8^NLVl`vv6hNj|mUroBYC$Q2O8P-NF>aaZUaZu=@61STKGh zP#Nw-CXaA&gHT3MR~F7c6;~1is}Qcf+pYMUj75Lhf**6eAEH|i0Aw{GMgC`-mH+?% M07*qoM6N<$f+AK)-v9sr literal 0 HcmV?d00001 diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Images/PowerOcr.png b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Images/PowerOcr.png new file mode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modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Images/PowerToys.dark.png b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Images/PowerToys.dark.png new file mode 100644 index 0000000000000000000000000000000000000000..2277ad614683eb58c9512f1777bae9cef837f1bb GIT binary patch literal 329 zcmV-P0k-~$P)wA)+9|NeDy)EUCttA?QC88I#1a$-}!&kV3*sG#wl4 zu>o1JX44H#T>}A^H+IdYnOBnn0s?KZCy-$q3Sa`K5Fnx+ul-)Dz@zvO>(vS1_fSZT z>I6y&;MEE65=sQhFIMo>F7VMIus?iIvxJ!86$miHGY6IHULEx!yZkZyLOk;k0uF<{ zfB1h$6`2Z5p4ubjW{3Kn%{r^RRw)}p;wE&lH6bHPt<6ZnAj3&t?nZ3vT5Ra)JHs#x b!#ERPOctVjA>nbA00000NkvXXu0mjfD-VMv literal 0 HcmV?d00001 diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Images/PowerToys.light.png b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Images/PowerToys.light.png new file mode 100644 index 0000000000000000000000000000000000000000..3de8782dad0a6c09d11f6cc7910bb9246f15ae7e GIT binary patch literal 320 zcmV-G0l)rR3DP)p3i^!b z%Aq3#hsK~!6hG{4ROGc!(5E1@M%)uA^xuit1C1MiOHORlt9Rc zKwH9`03h+br*(mkH32#NY-5EQ!`l$pKK#hJ{>dQ%mkq-&oZ86u2!V*f-kc^7%#F;A zKC`cs#b4?LBzD!_wF<~W;-+-5mC%v3b`uh+$=XkuP*OS$U2rCaGvPRn<2XN?1uwX@ SV^G)t0000$v%EV4h+@US(TtOGc(4Y*z z0GgP%Q@YU|ohBxOi3wvY1nAszJYVPpN8>df4in+7rcqgJGptUITKkO&PRlRlWbbau;t6igB@ z%y>l2u8&P3z|g?~GB>KHzu91^MATF;AntM(sbREE$cfEL^4m!`f2+DBKwTQSAyrMc zRv?1a^5~|~u$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9l_K~6JdW9tBE2^c-oCO zl>F#%!fYnYdjYvZ9Q|PO+qOVrnSxdm<%?l>%7xbyWBg$ADO@DT`v!s4pZK=Lmsqya z$++zSyq?KT93af8>ih=-fyEd9j?)n=TfEV`M;c8yUSE8-ppPkk1I`}+XCh*}8~^|S M07*qoM6N<$g1)df?*IS* literal 0 HcmV?d00001 diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Images/ShortcutGuide.png b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Images/ShortcutGuide.png new file mode 100644 index 0000000000000000000000000000000000000000..dbdfc2c687ce2da0f43b380094992f9f1e908d5d GIT binary patch literal 2259 zcmV;^2rT!BP){4S>l`!RmcRbm zl1r+ms(Md}P)gxH$^IpPo&)q8pyvR+>jR&LA=E3C5Qixx>v~S(6bAU+84IxKvD6b1 zfM`E@PLdyZ%%-GbU!D@8y^o}|JT?KC66$jlcPH9r@j?Tu0C5Jn?-vB2BWaN~+qQWF zKL~hp!!Qtw#Sldyf-nRWU|AMS(M<0D8A}L{+ zCVu(LUtz(5`8e#bLpgAx(V)3aIO2#yuyW-J2JzVAkK^HoAHmsYoyi$ZBof%RZ9AGR z7iXV+27?g*zW0M4Vcps_IPB0v2y}o_xr|?J+6vcm8}Z1DDX_r+IP-2mWl5(~$mjEj znHI9SEYg__a=9GMr}?y9U0r&P-UZ4~oP+1-_bff#-QBu;pZRW_XSO@OK$T zw9cgUHqXm;L)$T%g4*D{BFW`X@LmCDJc<ER;%dmALK@!nVCVYR-+Tf zFgP@fh&E|B4nMm`M!2lH7skdWFiU<^kb%FJ-^v(l4F%w6VXP=WD-8T6$MYFlH5aaN^`5#LY!D5 zOapGq<%~K`lgs6Lp7v)FxUR?Lqk}P6T^uHgQvCb;dA&NrC91^U5SZ*_NSp2kTYjx|BhNQG`ml!pvDk{v-t)yjUtyPvz0m-338wokkPIatVtU zEkZ7zWmZveK5(IrP`k}_|>m{6HAsX!Re=+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Q%v~K(PX77O~o*75>!z4>I&lxRJ1k7MEQH|`B3CBE~ePcaxWQz>`k*`HgDhWygU-v?il!OWoN zHE(*Y-_^AicWk*ax8G40S<7wIw>>`M-142L{t?RW z(szFHtLhIw@;=@M|7tT#82Rpuk&hvY1dueK%+#z=SmcB3Uk)g$PQtnS=TrXlP%W4q zuCyNStE3L!@1n%M$6O3RTKE^63Vo~m?GJpd`jgLYQA+Z^Ho}evDh%oXObh>divW~m ht6uJa^jjT%{2Kjf^*L@H7zh9W002ovPDHLkV1iRAQ-1&e literal 0 HcmV?d00001 diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Main.cs b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Main.cs new file mode 100644 index 0000000000..5a61a74b5c --- /dev/null +++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Main.cs @@ -0,0 +1,74 @@ +// Copyright (c) Microsoft Corporation +// The Microsoft Corporation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Collections.Generic; +using System.Linq; +using Microsoft.PowerToys.Run.Plugin.PowerToys.Components; +using Microsoft.PowerToys.Run.Plugin.PowerToys.Properties; +using Wox.Infrastructure; +using Wox.Plugin; + +namespace Microsoft.PowerToys.Run.Plugin.PowerToys +{ + public class Main : IPlugin, IPluginI18n, IContextMenu, IDisposable + { + private UtilityProvider _utilityProvider; + private bool _disposed; + + public string Name => Resources.Plugin_Name; + + public string Description => Resources.Plugin_Description; + + public string GetTranslatedPluginTitle() => Resources.Plugin_Name; + + public string GetTranslatedPluginDescription() => Resources.Plugin_Description; + + public void Init(PluginInitContext context) + { + _utilityProvider = new UtilityProvider(); + } + + public List LoadContextMenus(Result selectedResult) + { + return selectedResult.ContextData is Utility u + ? u.CreateContextMenuResults() + : new List(); + } + + public List Query(Query query) + { + var results = new List(); + + foreach (var utility in _utilityProvider.GetEnabledUtilities()) + { + var matchResult = StringMatcher.FuzzySearch(query.Search, utility.Name); + if (string.IsNullOrWhiteSpace(query.Search) || matchResult.Score > 0) + { + results.Add(utility.CreateResult(matchResult)); + } + } + + return results.OrderBy(r => r.Title).ToList(); + } + + public void Dispose() + { + Dispose(disposing: true); + GC.SuppressFinalize(this); + } + + protected virtual void Dispose(bool disposing) + { + if (!_disposed) + { + if (disposing) + { + _utilityProvider?.Dispose(); + _disposed = true; + } + } + } + } +} diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Microsoft.PowerToys.Run.Plugin.PowerToys.csproj b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Microsoft.PowerToys.Run.Plugin.PowerToys.csproj new file mode 100644 index 0000000000..34b66f1054 --- /dev/null +++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Microsoft.PowerToys.Run.Plugin.PowerToys.csproj @@ -0,0 +1,96 @@ + + + + + + net7.0-windows10.0.19041.0 + Microsoft.PowerToys.Run.Plugin.PowerToys + Microsoft.PowerToys.Run.Plugin.PowerToys + $(Version).0 + false + false + true + ..\..\..\..\..\$(Platform)\$(Configuration)\modules\launcher\Plugins\PowerToys\ + + + + + PowerToys.GPOWrapper + $(OutDir) + false + + + + DEBUG;TRACE + false + full + true + + + + TRACE + true + pdbonly + + + + + + + + + + + PreserveNewest + + + + + + + + + + True + True + Resources.resx + + + + + ResXFileCodeGenerator + Resources.Designer.cs + + + + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + + diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Properties/Resources.Designer.cs b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Properties/Resources.Designer.cs new file mode 100644 index 0000000000..be8e3664d0 --- /dev/null +++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Properties/Resources.Designer.cs @@ -0,0 +1,171 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Microsoft.PowerToys.Run.Plugin.PowerToys.Properties { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Microsoft.PowerToys.Run.Plugin.PowerToys.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized string similar to Open settings (Ctrl+Shift+S). + /// + internal static string Action_Open_Settings { + get { + return ResourceManager.GetString("Action_Open_Settings", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Run as administrator (Ctrl+Shift+Enter). + /// + internal static string Action_Run_As_Administrator { + get { + return ResourceManager.GetString("Action_Run_As_Administrator", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Color Picker. + /// + internal static string Color_Picker { + get { + return ResourceManager.GetString("Color_Picker", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to FancyZones Editor. + /// + internal static string FancyZones_Editor { + get { + return ResourceManager.GetString("FancyZones_Editor", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Hosts File Editor. + /// + internal static string Hosts_File_Editor { + get { + return ResourceManager.GetString("Hosts_File_Editor", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Open PowerToys utilities and settings.. + /// + internal static string Plugin_Description { + get { + return ResourceManager.GetString("Plugin_Description", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to PowerToys. + /// + internal static string Plugin_Name { + get { + return ResourceManager.GetString("Plugin_Name", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Registry Preview. + /// + internal static string Registry_Preview { + get { + return ResourceManager.GetString("Registry_Preview", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Screen Ruler. + /// + internal static string Screen_Ruler { + get { + return ResourceManager.GetString("Screen_Ruler", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Shortcut Guide. + /// + internal static string Shortcut_Guide { + get { + return ResourceManager.GetString("Shortcut_Guide", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to PowerToys Utility. + /// + internal static string Subtitle_Powertoys_Utility { + get { + return ResourceManager.GetString("Subtitle_Powertoys_Utility", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Text Extractor. + /// + internal static string Text_Extractor { + get { + return ResourceManager.GetString("Text_Extractor", resourceCulture); + } + } + } +} diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Properties/Resources.resx b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Properties/Resources.resx new file mode 100644 index 0000000000..53eb6605be --- /dev/null +++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Properties/Resources.resx @@ -0,0 +1,163 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Open settings (Ctrl+Shift+S) + + + Run as administrator (Ctrl+Shift+Enter) + + + Color Picker + "Color Picker" is the name of the utility + + + FancyZones Editor + "FancyZones" is the name of the utility + + + Hosts File Editor + "Hosts File Editor" is the name of the utility + + + Open PowerToys utilities and settings. + + + PowerToys + + + Registry Preview + "Registry Preview" is the name of the utility + + + Screen Ruler + "Screen Ruler" is the name of the utility + + + Shortcut Guide + "Shortcut Guide" is the name of the utility + + + PowerToys Utility + + + Text Extractor + "Text Extractor" is the name of the utility + + \ No newline at end of file diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/plugin.json b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/plugin.json new file mode 100644 index 0000000000..a3d6c86c28 --- /dev/null +++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/plugin.json @@ -0,0 +1,14 @@ +{ + "ID": "29DD65DB28C84A37BDEF1D2B43DA368B", + "Disabled": true, + "ActionKeyword": "@", + "IsGlobal": true, + "Name": "PowerToys", + "Author": "davidegiacometti", + "Version": "1.0.0", + "Language": "csharp", + "Website": "https://aka.ms/powertoys", + "ExecuteFileName": "Microsoft.PowerToys.Run.Plugin.PowerToys.dll", + "IcoPathDark": "Images\\PowerToys.dark.png", + "IcoPathLight": "Images\\PowerToys.light.png" +} diff --git a/src/runner/settings_window.cpp b/src/runner/settings_window.cpp index 9dfb269aae..8773391c83 100644 --- a/src/runner/settings_window.cpp +++ b/src/runner/settings_window.cpp @@ -586,7 +586,15 @@ void open_settings_window(std::optional settings_window, bool show // bring_settings_to_front(); if (current_settings_ipc) { - current_settings_ipc->send(L"{\"ShowYourself\":\"main_page\"}"); + if (settings_window.has_value()) + { + std::wstring msg = L"{\"ShowYourself\":\"" + settings_window.value() + L"\"}"; + current_settings_ipc->send(msg); + } + else + { + current_settings_ipc->send(L"{\"ShowYourself\":\"Overview\"}"); + } } } } @@ -657,6 +665,10 @@ std::string ESettingsWindowNames_to_string(ESettingsWindowNames value) return "VideoConference"; case ESettingsWindowNames::Hosts: return "Hosts"; + case ESettingsWindowNames::MeasureTool: + return "MeasureTool"; + case ESettingsWindowNames::PowerOCR: + return "PowerOCR"; case ESettingsWindowNames::RegistryPreview: return "RegistryPreview"; default: @@ -722,6 +734,14 @@ ESettingsWindowNames ESettingsWindowNames_from_string(std::string value) { return ESettingsWindowNames::Hosts; } + else if (value == "MeasureTool") + { + return ESettingsWindowNames::MeasureTool; + } + else if (value == "PowerOCR") + { + return ESettingsWindowNames::PowerOCR; + } else if (value == "RegistryPreview") { return ESettingsWindowNames::RegistryPreview; diff --git a/src/runner/settings_window.h b/src/runner/settings_window.h index 1497c2382e..0601237256 100644 --- a/src/runner/settings_window.h +++ b/src/runner/settings_window.h @@ -17,6 +17,8 @@ enum class ESettingsWindowNames ShortcutGuide, VideoConference, Hosts, + MeasureTool, + PowerOCR, RegistryPreview, }; diff --git a/src/settings-ui/Settings.UI/App.xaml.cs b/src/settings-ui/Settings.UI/App.xaml.cs index 007482ee92..e1642947c7 100644 --- a/src/settings-ui/Settings.UI/App.xaml.cs +++ b/src/settings-ui/Settings.UI/App.xaml.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation +// Copyright (c) Microsoft Corporation // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -12,12 +12,12 @@ using ManagedCommon; using Microsoft.PowerToys.Settings.UI.Helpers; using Microsoft.PowerToys.Settings.UI.Library; using Microsoft.PowerToys.Settings.UI.Library.Telemetry.Events; -using Microsoft.PowerToys.Settings.UI.Library.Utilities; using Microsoft.PowerToys.Settings.UI.Views; using Microsoft.PowerToys.Telemetry; using Microsoft.UI.Xaml; using Windows.UI.Popups; using WinRT.Interop; +using WinUIEx; namespace Microsoft.PowerToys.Settings.UI { @@ -82,7 +82,6 @@ namespace Microsoft.PowerToys.Settings.UI if (settingsWindow == null) { settingsWindow = new MainWindow(IsDarkTheme()); - type = typeof(GeneralPage); } settingsWindow.Activate(); @@ -132,31 +131,8 @@ namespace Microsoft.PowerToys.Settings.UI if (containsSettingsWindow) { - // open specific window - switch (cmdArgs[currentArgumentIndex]) - { - case "Overview": StartupPage = typeof(Views.GeneralPage); break; - case "AlwaysOnTop": StartupPage = typeof(Views.AlwaysOnTopPage); break; - case "Awake": StartupPage = typeof(Views.AwakePage); break; - case "ColorPicker": StartupPage = typeof(Views.ColorPickerPage); break; - case "FancyZones": StartupPage = typeof(Views.FancyZonesPage); break; - case "FileLocksmith": StartupPage = typeof(Views.FileLocksmithPage); break; - case "Run": StartupPage = typeof(Views.PowerLauncherPage); break; - case "ImageResizer": StartupPage = typeof(Views.ImageResizerPage); break; - case "KBM": StartupPage = typeof(Views.KeyboardManagerPage); break; - case "MouseUtils": StartupPage = typeof(Views.MouseUtilsPage); break; - case "PowerRename": StartupPage = typeof(Views.PowerRenamePage); break; - case "QuickAccent": StartupPage = typeof(Views.PowerAccentPage); break; - case "FileExplorer": StartupPage = typeof(Views.PowerPreviewPage); break; - case "ShortcutGuide": StartupPage = typeof(Views.ShortcutGuidePage); break; - case "TextExtractor": StartupPage = typeof(Views.PowerOcrPage); break; - case "VideoConference": StartupPage = typeof(Views.VideoConferencePage); break; - case "MeasureTool": StartupPage = typeof(Views.MeasureToolPage); break; - case "Hosts": StartupPage = typeof(Views.HostsPage); break; - case "RegistryPreview": StartupPage = typeof(Views.RegistryPreviewPage); break; - case "PastePlain": StartupPage = typeof(Views.PastePlainPage); break; - default: Debug.Assert(false, "Unexpected SettingsWindow argument value"); break; - } + // Open specific window + StartupPage = GetPage(cmdArgs[currentArgumentIndex]); currentArgumentIndex++; } @@ -189,6 +165,10 @@ namespace Microsoft.PowerToys.Settings.UI settingsWindow = new MainWindow(isDark); settingsWindow.Activate(); settingsWindow.NavigateToSection(StartupPage); + + // https://github.com/microsoft/microsoft-ui-xaml/issues/7595 - Activate doesn't bring window to the foreground + // Need to call SetForegroundWindow to actually gain focus. + Utils.BecomeForegroundWindow(settingsWindow.GetWindowHandle()); } else { @@ -364,5 +344,36 @@ namespace Microsoft.PowerToys.Settings.UI { flyoutWindow = null; } + + public static Type GetPage(string settingWindow) + { + switch (settingWindow) + { + case "Overview": return typeof(GeneralPage); + case "AlwaysOnTop": return typeof(AlwaysOnTopPage); + case "Awake": return typeof(AwakePage); + case "ColorPicker": return typeof(ColorPickerPage); + case "FancyZones": return typeof(FancyZonesPage); + case "FileLocksmith": return typeof(FileLocksmithPage); + case "Run": return typeof(PowerLauncherPage); + case "ImageResizer": return typeof(ImageResizerPage); + case "KBM": return typeof(KeyboardManagerPage); + case "MouseUtils": return typeof(MouseUtilsPage); + case "PowerRename": return typeof(PowerRenamePage); + case "QuickAccent": return typeof(PowerAccentPage); + case "FileExplorer": return typeof(PowerPreviewPage); + case "ShortcutGuide": return typeof(ShortcutGuidePage); + case "PowerOCR": return typeof(PowerOcrPage); + case "VideoConference": return typeof(VideoConferencePage); + case "MeasureTool": return typeof(MeasureToolPage); + case "Hosts": return typeof(HostsPage); + case "RegistryPreview": return typeof(RegistryPreviewPage); + case "PastePlain": return typeof(PastePlainPage); + default: + // Fallback to general + Debug.Assert(false, "Unexpected SettingsWindow argument value"); + return typeof(GeneralPage); + } + } } } diff --git a/src/settings-ui/Settings.UI/MainWindow.xaml b/src/settings-ui/Settings.UI/MainWindow.xaml index 01a08ddf21..3f40a0dafb 100644 --- a/src/settings-ui/Settings.UI/MainWindow.xaml +++ b/src/settings-ui/Settings.UI/MainWindow.xaml @@ -1,4 +1,4 @@ - + ShellPage.SetOpenMainWindowCallback(type => { - this.DispatcherQueue.TryEnqueue(Microsoft.UI.Dispatching.DispatcherQueuePriority.Normal, () => - App.OpenSettingsWindow(typeof(GeneralPage))); + DispatcherQueue.TryEnqueue(Microsoft.UI.Dispatching.DispatcherQueuePriority.Normal, () => + App.OpenSettingsWindow(type)); }); // open main window diff --git a/src/settings-ui/Settings.UI/Views/ShellPage.xaml.cs b/src/settings-ui/Settings.UI/Views/ShellPage.xaml.cs index 273fda48d3..f48e327277 100644 --- a/src/settings-ui/Settings.UI/Views/ShellPage.xaml.cs +++ b/src/settings-ui/Settings.UI/Views/ShellPage.xaml.cs @@ -30,7 +30,7 @@ namespace Microsoft.PowerToys.Settings.UI.Views /// /// Declaration for the opening main window callback function. /// - public delegate void MainOpeningCallback(); + public delegate void MainOpeningCallback(Type type); /// /// Declaration for the updating the general settings callback function. @@ -351,9 +351,9 @@ namespace Microsoft.PowerToys.Settings.UI.Views OpenFlyoutCallback(p); } - else if (whatToShowJson.ValueType == JsonValueType.String && whatToShowJson.GetString().Equals("main_page", StringComparison.Ordinal)) + else if (whatToShowJson.ValueType == JsonValueType.String) { - OpenMainWindowCallback(); + OpenMainWindowCallback(App.GetPage(whatToShowJson.GetString())); } } }