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 0000000000..7fed152227
Binary files /dev/null and b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Images/ColorPicker.png differ
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 0000000000..1d70bbb959
Binary files /dev/null and b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Images/FancyZones.png differ
diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Images/Hosts.png b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Images/Hosts.png
new file mode 100644
index 0000000000..ce81ac6dda
Binary files /dev/null and b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Images/Hosts.png differ
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 100644
index 0000000000..3f5dcb1a9e
Binary files /dev/null and b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Images/PowerOcr.png differ
diff --git a/src/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 0000000000..2277ad6146
Binary files /dev/null and b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Images/PowerToys.dark.png differ
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 0000000000..3de8782dad
Binary files /dev/null and b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Images/PowerToys.light.png differ
diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Images/RegistryPreview.png b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Images/RegistryPreview.png
new file mode 100644
index 0000000000..887c42a182
Binary files /dev/null and b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Images/RegistryPreview.png differ
diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Images/ScreenRuler.png b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Images/ScreenRuler.png
new file mode 100644
index 0000000000..bc93c7e113
Binary files /dev/null and b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Images/ScreenRuler.png differ
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 0000000000..dbdfc2c687
Binary files /dev/null and b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Images/ShortcutGuide.png differ
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()));
}
}
}