mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 11:48:06 +01:00
QuickAccessList control refactor
This commit is contained in:
49
src/settings-ui/QuickAccess.UI/Helpers/ModuleGpoHelper.cs
Normal file
49
src/settings-ui/QuickAccess.UI/Helpers/ModuleGpoHelper.cs
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
// 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 global::PowerToys.GPOWrapper;
|
||||||
|
using ManagedCommon;
|
||||||
|
using Microsoft.PowerToys.Settings.UI.Library;
|
||||||
|
|
||||||
|
namespace Microsoft.PowerToys.QuickAccess.Helpers;
|
||||||
|
|
||||||
|
internal static class ModuleGpoHelper
|
||||||
|
{
|
||||||
|
public static GpoRuleConfigured GetModuleGpoConfiguration(ModuleType moduleType)
|
||||||
|
{
|
||||||
|
return moduleType switch
|
||||||
|
{
|
||||||
|
ModuleType.AdvancedPaste => GPOWrapper.GetConfiguredAdvancedPasteEnabledValue(),
|
||||||
|
ModuleType.AlwaysOnTop => GPOWrapper.GetConfiguredAlwaysOnTopEnabledValue(),
|
||||||
|
ModuleType.Awake => GPOWrapper.GetConfiguredAwakeEnabledValue(),
|
||||||
|
ModuleType.CmdPal => GPOWrapper.GetConfiguredCmdPalEnabledValue(),
|
||||||
|
ModuleType.ColorPicker => GPOWrapper.GetConfiguredColorPickerEnabledValue(),
|
||||||
|
ModuleType.CropAndLock => GPOWrapper.GetConfiguredCropAndLockEnabledValue(),
|
||||||
|
ModuleType.CursorWrap => GPOWrapper.GetConfiguredCursorWrapEnabledValue(),
|
||||||
|
ModuleType.EnvironmentVariables => GPOWrapper.GetConfiguredEnvironmentVariablesEnabledValue(),
|
||||||
|
ModuleType.FancyZones => GPOWrapper.GetConfiguredFancyZonesEnabledValue(),
|
||||||
|
ModuleType.FileLocksmith => GPOWrapper.GetConfiguredFileLocksmithEnabledValue(),
|
||||||
|
ModuleType.FindMyMouse => GPOWrapper.GetConfiguredFindMyMouseEnabledValue(),
|
||||||
|
ModuleType.Hosts => GPOWrapper.GetConfiguredHostsFileEditorEnabledValue(),
|
||||||
|
ModuleType.ImageResizer => GPOWrapper.GetConfiguredImageResizerEnabledValue(),
|
||||||
|
ModuleType.KeyboardManager => GPOWrapper.GetConfiguredKeyboardManagerEnabledValue(),
|
||||||
|
ModuleType.MouseHighlighter => GPOWrapper.GetConfiguredMouseHighlighterEnabledValue(),
|
||||||
|
ModuleType.MouseJump => GPOWrapper.GetConfiguredMouseJumpEnabledValue(),
|
||||||
|
ModuleType.MousePointerCrosshairs => GPOWrapper.GetConfiguredMousePointerCrosshairsEnabledValue(),
|
||||||
|
ModuleType.MouseWithoutBorders => GPOWrapper.GetConfiguredMouseWithoutBordersEnabledValue(),
|
||||||
|
ModuleType.NewPlus => GPOWrapper.GetConfiguredNewPlusEnabledValue(),
|
||||||
|
ModuleType.Peek => GPOWrapper.GetConfiguredPeekEnabledValue(),
|
||||||
|
ModuleType.PowerRename => GPOWrapper.GetConfiguredPowerRenameEnabledValue(),
|
||||||
|
ModuleType.PowerLauncher => GPOWrapper.GetConfiguredPowerLauncherEnabledValue(),
|
||||||
|
ModuleType.PowerAccent => GPOWrapper.GetConfiguredQuickAccentEnabledValue(),
|
||||||
|
ModuleType.Workspaces => GPOWrapper.GetConfiguredWorkspacesEnabledValue(),
|
||||||
|
ModuleType.RegistryPreview => GPOWrapper.GetConfiguredRegistryPreviewEnabledValue(),
|
||||||
|
ModuleType.MeasureTool => GPOWrapper.GetConfiguredScreenRulerEnabledValue(),
|
||||||
|
ModuleType.ShortcutGuide => GPOWrapper.GetConfiguredShortcutGuideEnabledValue(),
|
||||||
|
ModuleType.PowerOCR => GPOWrapper.GetConfiguredTextExtractorEnabledValue(),
|
||||||
|
ModuleType.ZoomIt => GPOWrapper.GetConfiguredZoomItEnabledValue(),
|
||||||
|
_ => GpoRuleConfigured.Unavailable,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,155 +0,0 @@
|
|||||||
// 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 global::PowerToys.GPOWrapper;
|
|
||||||
using ManagedCommon;
|
|
||||||
using Microsoft.PowerToys.Settings.UI.Library;
|
|
||||||
|
|
||||||
namespace Microsoft.PowerToys.QuickAccess.Helpers;
|
|
||||||
|
|
||||||
internal static class ModuleHelper
|
|
||||||
{
|
|
||||||
public static string GetModuleLabelResourceName(ModuleType moduleType)
|
|
||||||
{
|
|
||||||
return moduleType switch
|
|
||||||
{
|
|
||||||
ModuleType.Workspaces => "Workspaces/ModuleTitle",
|
|
||||||
ModuleType.PowerAccent => "QuickAccent/ModuleTitle",
|
|
||||||
ModuleType.PowerOCR => "TextExtractor/ModuleTitle",
|
|
||||||
ModuleType.FindMyMouse => "MouseUtils_FindMyMouse/Header",
|
|
||||||
ModuleType.MouseHighlighter => "MouseUtils_MouseHighlighter/Header",
|
|
||||||
ModuleType.MouseJump => "MouseUtils_MouseJump/Header",
|
|
||||||
ModuleType.MousePointerCrosshairs => "MouseUtils_MousePointerCrosshairs/Header",
|
|
||||||
ModuleType.CursorWrap => "MouseUtils_CursorWrap/Header",
|
|
||||||
_ => $"{moduleType}/ModuleTitle",
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string GetModuleTypeFluentIconName(ModuleType moduleType)
|
|
||||||
{
|
|
||||||
return moduleType switch
|
|
||||||
{
|
|
||||||
ModuleType.AdvancedPaste => "ms-appx:///Assets/Settings/Icons/AdvancedPaste.png",
|
|
||||||
ModuleType.Workspaces => "ms-appx:///Assets/Settings/Icons/Workspaces.png",
|
|
||||||
ModuleType.PowerOCR => "ms-appx:///Assets/Settings/Icons/TextExtractor.png",
|
|
||||||
ModuleType.PowerAccent => "ms-appx:///Assets/Settings/Icons/QuickAccent.png",
|
|
||||||
ModuleType.MousePointerCrosshairs => "ms-appx:///Assets/Settings/Icons/MouseCrosshairs.png",
|
|
||||||
ModuleType.MeasureTool => "ms-appx:///Assets/Settings/Icons/ScreenRuler.png",
|
|
||||||
ModuleType.PowerLauncher => "ms-appx:///Assets/Settings/Icons/PowerToysRun.png",
|
|
||||||
_ => $"ms-appx:///Assets/Settings/Icons/{moduleType}.png",
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool GetIsModuleEnabled(GeneralSettings generalSettingsConfig, ModuleType moduleType)
|
|
||||||
{
|
|
||||||
return moduleType switch
|
|
||||||
{
|
|
||||||
ModuleType.AdvancedPaste => generalSettingsConfig.Enabled.AdvancedPaste,
|
|
||||||
ModuleType.AlwaysOnTop => generalSettingsConfig.Enabled.AlwaysOnTop,
|
|
||||||
ModuleType.Awake => generalSettingsConfig.Enabled.Awake,
|
|
||||||
ModuleType.CmdPal => generalSettingsConfig.Enabled.CmdPal,
|
|
||||||
ModuleType.ColorPicker => generalSettingsConfig.Enabled.ColorPicker,
|
|
||||||
ModuleType.CropAndLock => generalSettingsConfig.Enabled.CropAndLock,
|
|
||||||
ModuleType.CursorWrap => generalSettingsConfig.Enabled.CursorWrap,
|
|
||||||
ModuleType.LightSwitch => generalSettingsConfig.Enabled.LightSwitch,
|
|
||||||
ModuleType.EnvironmentVariables => generalSettingsConfig.Enabled.EnvironmentVariables,
|
|
||||||
ModuleType.FancyZones => generalSettingsConfig.Enabled.FancyZones,
|
|
||||||
ModuleType.FileLocksmith => generalSettingsConfig.Enabled.FileLocksmith,
|
|
||||||
ModuleType.FindMyMouse => generalSettingsConfig.Enabled.FindMyMouse,
|
|
||||||
ModuleType.Hosts => generalSettingsConfig.Enabled.Hosts,
|
|
||||||
ModuleType.ImageResizer => generalSettingsConfig.Enabled.ImageResizer,
|
|
||||||
ModuleType.KeyboardManager => generalSettingsConfig.Enabled.KeyboardManager,
|
|
||||||
ModuleType.MouseHighlighter => generalSettingsConfig.Enabled.MouseHighlighter,
|
|
||||||
ModuleType.MouseJump => generalSettingsConfig.Enabled.MouseJump,
|
|
||||||
ModuleType.MousePointerCrosshairs => generalSettingsConfig.Enabled.MousePointerCrosshairs,
|
|
||||||
ModuleType.MouseWithoutBorders => generalSettingsConfig.Enabled.MouseWithoutBorders,
|
|
||||||
ModuleType.NewPlus => generalSettingsConfig.Enabled.NewPlus,
|
|
||||||
ModuleType.Peek => generalSettingsConfig.Enabled.Peek,
|
|
||||||
ModuleType.PowerRename => generalSettingsConfig.Enabled.PowerRename,
|
|
||||||
ModuleType.PowerLauncher => generalSettingsConfig.Enabled.PowerLauncher,
|
|
||||||
ModuleType.PowerAccent => generalSettingsConfig.Enabled.PowerAccent,
|
|
||||||
ModuleType.Workspaces => generalSettingsConfig.Enabled.Workspaces,
|
|
||||||
ModuleType.RegistryPreview => generalSettingsConfig.Enabled.RegistryPreview,
|
|
||||||
ModuleType.MeasureTool => generalSettingsConfig.Enabled.MeasureTool,
|
|
||||||
ModuleType.ShortcutGuide => generalSettingsConfig.Enabled.ShortcutGuide,
|
|
||||||
ModuleType.PowerOCR => generalSettingsConfig.Enabled.PowerOcr,
|
|
||||||
ModuleType.ZoomIt => generalSettingsConfig.Enabled.ZoomIt,
|
|
||||||
_ => false,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void SetIsModuleEnabled(GeneralSettings generalSettingsConfig, ModuleType moduleType, bool isEnabled)
|
|
||||||
{
|
|
||||||
switch (moduleType)
|
|
||||||
{
|
|
||||||
case ModuleType.AdvancedPaste: generalSettingsConfig.Enabled.AdvancedPaste = isEnabled; break;
|
|
||||||
case ModuleType.AlwaysOnTop: generalSettingsConfig.Enabled.AlwaysOnTop = isEnabled; break;
|
|
||||||
case ModuleType.Awake: generalSettingsConfig.Enabled.Awake = isEnabled; break;
|
|
||||||
case ModuleType.CmdPal: generalSettingsConfig.Enabled.CmdPal = isEnabled; break;
|
|
||||||
case ModuleType.ColorPicker: generalSettingsConfig.Enabled.ColorPicker = isEnabled; break;
|
|
||||||
case ModuleType.CropAndLock: generalSettingsConfig.Enabled.CropAndLock = isEnabled; break;
|
|
||||||
case ModuleType.CursorWrap: generalSettingsConfig.Enabled.CursorWrap = isEnabled; break;
|
|
||||||
case ModuleType.LightSwitch: generalSettingsConfig.Enabled.LightSwitch = isEnabled; break;
|
|
||||||
case ModuleType.EnvironmentVariables: generalSettingsConfig.Enabled.EnvironmentVariables = isEnabled; break;
|
|
||||||
case ModuleType.FancyZones: generalSettingsConfig.Enabled.FancyZones = isEnabled; break;
|
|
||||||
case ModuleType.FileLocksmith: generalSettingsConfig.Enabled.FileLocksmith = isEnabled; break;
|
|
||||||
case ModuleType.FindMyMouse: generalSettingsConfig.Enabled.FindMyMouse = isEnabled; break;
|
|
||||||
case ModuleType.Hosts: generalSettingsConfig.Enabled.Hosts = isEnabled; break;
|
|
||||||
case ModuleType.ImageResizer: generalSettingsConfig.Enabled.ImageResizer = isEnabled; break;
|
|
||||||
case ModuleType.KeyboardManager: generalSettingsConfig.Enabled.KeyboardManager = isEnabled; break;
|
|
||||||
case ModuleType.MouseHighlighter: generalSettingsConfig.Enabled.MouseHighlighter = isEnabled; break;
|
|
||||||
case ModuleType.MouseJump: generalSettingsConfig.Enabled.MouseJump = isEnabled; break;
|
|
||||||
case ModuleType.MousePointerCrosshairs: generalSettingsConfig.Enabled.MousePointerCrosshairs = isEnabled; break;
|
|
||||||
case ModuleType.MouseWithoutBorders: generalSettingsConfig.Enabled.MouseWithoutBorders = isEnabled; break;
|
|
||||||
case ModuleType.NewPlus: generalSettingsConfig.Enabled.NewPlus = isEnabled; break;
|
|
||||||
case ModuleType.Peek: generalSettingsConfig.Enabled.Peek = isEnabled; break;
|
|
||||||
case ModuleType.PowerRename: generalSettingsConfig.Enabled.PowerRename = isEnabled; break;
|
|
||||||
case ModuleType.PowerLauncher: generalSettingsConfig.Enabled.PowerLauncher = isEnabled; break;
|
|
||||||
case ModuleType.PowerAccent: generalSettingsConfig.Enabled.PowerAccent = isEnabled; break;
|
|
||||||
case ModuleType.Workspaces: generalSettingsConfig.Enabled.Workspaces = isEnabled; break;
|
|
||||||
case ModuleType.RegistryPreview: generalSettingsConfig.Enabled.RegistryPreview = isEnabled; break;
|
|
||||||
case ModuleType.MeasureTool: generalSettingsConfig.Enabled.MeasureTool = isEnabled; break;
|
|
||||||
case ModuleType.ShortcutGuide: generalSettingsConfig.Enabled.ShortcutGuide = isEnabled; break;
|
|
||||||
case ModuleType.PowerOCR: generalSettingsConfig.Enabled.PowerOcr = isEnabled; break;
|
|
||||||
case ModuleType.ZoomIt: generalSettingsConfig.Enabled.ZoomIt = isEnabled; break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static GpoRuleConfigured GetModuleGpoConfiguration(ModuleType moduleType)
|
|
||||||
{
|
|
||||||
return moduleType switch
|
|
||||||
{
|
|
||||||
ModuleType.AdvancedPaste => GPOWrapper.GetConfiguredAdvancedPasteEnabledValue(),
|
|
||||||
ModuleType.AlwaysOnTop => GPOWrapper.GetConfiguredAlwaysOnTopEnabledValue(),
|
|
||||||
ModuleType.Awake => GPOWrapper.GetConfiguredAwakeEnabledValue(),
|
|
||||||
ModuleType.CmdPal => GPOWrapper.GetConfiguredCmdPalEnabledValue(),
|
|
||||||
ModuleType.ColorPicker => GPOWrapper.GetConfiguredColorPickerEnabledValue(),
|
|
||||||
ModuleType.CropAndLock => GPOWrapper.GetConfiguredCropAndLockEnabledValue(),
|
|
||||||
ModuleType.CursorWrap => GPOWrapper.GetConfiguredCursorWrapEnabledValue(),
|
|
||||||
ModuleType.EnvironmentVariables => GPOWrapper.GetConfiguredEnvironmentVariablesEnabledValue(),
|
|
||||||
ModuleType.FancyZones => GPOWrapper.GetConfiguredFancyZonesEnabledValue(),
|
|
||||||
ModuleType.FileLocksmith => GPOWrapper.GetConfiguredFileLocksmithEnabledValue(),
|
|
||||||
ModuleType.FindMyMouse => GPOWrapper.GetConfiguredFindMyMouseEnabledValue(),
|
|
||||||
ModuleType.Hosts => GPOWrapper.GetConfiguredHostsFileEditorEnabledValue(),
|
|
||||||
ModuleType.ImageResizer => GPOWrapper.GetConfiguredImageResizerEnabledValue(),
|
|
||||||
ModuleType.KeyboardManager => GPOWrapper.GetConfiguredKeyboardManagerEnabledValue(),
|
|
||||||
ModuleType.MouseHighlighter => GPOWrapper.GetConfiguredMouseHighlighterEnabledValue(),
|
|
||||||
ModuleType.MouseJump => GPOWrapper.GetConfiguredMouseJumpEnabledValue(),
|
|
||||||
ModuleType.MousePointerCrosshairs => GPOWrapper.GetConfiguredMousePointerCrosshairsEnabledValue(),
|
|
||||||
ModuleType.MouseWithoutBorders => GPOWrapper.GetConfiguredMouseWithoutBordersEnabledValue(),
|
|
||||||
ModuleType.NewPlus => GPOWrapper.GetConfiguredNewPlusEnabledValue(),
|
|
||||||
ModuleType.Peek => GPOWrapper.GetConfiguredPeekEnabledValue(),
|
|
||||||
ModuleType.PowerRename => GPOWrapper.GetConfiguredPowerRenameEnabledValue(),
|
|
||||||
ModuleType.PowerLauncher => GPOWrapper.GetConfiguredPowerLauncherEnabledValue(),
|
|
||||||
ModuleType.PowerAccent => GPOWrapper.GetConfiguredQuickAccentEnabledValue(),
|
|
||||||
ModuleType.Workspaces => GPOWrapper.GetConfiguredWorkspacesEnabledValue(),
|
|
||||||
ModuleType.RegistryPreview => GPOWrapper.GetConfiguredRegistryPreviewEnabledValue(),
|
|
||||||
ModuleType.MeasureTool => GPOWrapper.GetConfiguredScreenRulerEnabledValue(),
|
|
||||||
ModuleType.ShortcutGuide => GPOWrapper.GetConfiguredShortcutGuideEnabledValue(),
|
|
||||||
ModuleType.PowerOCR => GPOWrapper.GetConfiguredTextExtractorEnabledValue(),
|
|
||||||
ModuleType.ZoomIt => GPOWrapper.GetConfiguredZoomItEnabledValue(),
|
|
||||||
_ => GpoRuleConfigured.Unavailable,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
134
src/settings-ui/QuickAccess.UI/Services/QuickAccessLauncher.cs
Normal file
134
src/settings-ui/QuickAccess.UI/Services/QuickAccessLauncher.cs
Normal file
@@ -0,0 +1,134 @@
|
|||||||
|
// 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.Threading;
|
||||||
|
using ManagedCommon;
|
||||||
|
using Microsoft.PowerToys.Settings.UI.Controls;
|
||||||
|
using Microsoft.PowerToys.Settings.UI.Library;
|
||||||
|
using PowerToys.Interop;
|
||||||
|
|
||||||
|
namespace Microsoft.PowerToys.QuickAccess.Services
|
||||||
|
{
|
||||||
|
public class QuickAccessLauncher : IQuickAccessLauncher
|
||||||
|
{
|
||||||
|
private readonly IQuickAccessCoordinator _coordinator;
|
||||||
|
|
||||||
|
public QuickAccessLauncher(IQuickAccessCoordinator coordinator)
|
||||||
|
{
|
||||||
|
_coordinator = coordinator;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Launch(ModuleType moduleType)
|
||||||
|
{
|
||||||
|
bool moduleRun = true;
|
||||||
|
|
||||||
|
switch (moduleType)
|
||||||
|
{
|
||||||
|
case ModuleType.ColorPicker:
|
||||||
|
using (var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, Constants.ShowColorPickerSharedEvent()))
|
||||||
|
{
|
||||||
|
eventHandle.Set();
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
case ModuleType.EnvironmentVariables:
|
||||||
|
{
|
||||||
|
bool launchAdmin = SettingsRepository<EnvironmentVariablesSettings>.GetInstance(SettingsUtils.Default).SettingsConfig.Properties.LaunchAdministrator;
|
||||||
|
bool isElevated = _coordinator?.IsRunnerElevated ?? false;
|
||||||
|
string eventName = !isElevated && launchAdmin
|
||||||
|
? Constants.ShowEnvironmentVariablesAdminSharedEvent()
|
||||||
|
: Constants.ShowEnvironmentVariablesSharedEvent();
|
||||||
|
|
||||||
|
using (var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, eventName))
|
||||||
|
{
|
||||||
|
eventHandle.Set();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
case ModuleType.FancyZones:
|
||||||
|
using (var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, Constants.FZEToggleEvent()))
|
||||||
|
{
|
||||||
|
eventHandle.Set();
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
case ModuleType.Hosts:
|
||||||
|
{
|
||||||
|
bool launchAdmin = SettingsRepository<HostsSettings>.GetInstance(SettingsUtils.Default).SettingsConfig.Properties.LaunchAdministrator;
|
||||||
|
bool isElevated = _coordinator?.IsRunnerElevated ?? false;
|
||||||
|
string eventName = !isElevated && launchAdmin
|
||||||
|
? Constants.ShowHostsAdminSharedEvent()
|
||||||
|
: Constants.ShowHostsSharedEvent();
|
||||||
|
|
||||||
|
using (var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, eventName))
|
||||||
|
{
|
||||||
|
eventHandle.Set();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
case ModuleType.PowerLauncher:
|
||||||
|
using (var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, Constants.PowerLauncherSharedEvent()))
|
||||||
|
{
|
||||||
|
eventHandle.Set();
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
case ModuleType.PowerOCR:
|
||||||
|
using (var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, Constants.ShowPowerOCRSharedEvent()))
|
||||||
|
{
|
||||||
|
eventHandle.Set();
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
case ModuleType.RegistryPreview:
|
||||||
|
using (var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, Constants.RegistryPreviewTriggerEvent()))
|
||||||
|
{
|
||||||
|
eventHandle.Set();
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
case ModuleType.MeasureTool:
|
||||||
|
using (var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, Constants.MeasureToolTriggerEvent()))
|
||||||
|
{
|
||||||
|
eventHandle.Set();
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
case ModuleType.ShortcutGuide:
|
||||||
|
using (var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, Constants.ShortcutGuideTriggerEvent()))
|
||||||
|
{
|
||||||
|
eventHandle.Set();
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
case ModuleType.CmdPal:
|
||||||
|
using (var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, Constants.ShowCmdPalEvent()))
|
||||||
|
{
|
||||||
|
eventHandle.Set();
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
case ModuleType.Workspaces:
|
||||||
|
using (var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, Constants.WorkspacesLaunchEditorEvent()))
|
||||||
|
{
|
||||||
|
eventHandle.Set();
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
moduleRun = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (moduleRun)
|
||||||
|
{
|
||||||
|
_coordinator?.OnModuleLaunched(moduleType);
|
||||||
|
}
|
||||||
|
|
||||||
|
_coordinator?.HideFlyout();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -91,17 +91,17 @@ public sealed class AllAppsViewModel : Observable
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
var gpo = ModuleHelper.GetModuleGpoConfiguration(moduleType);
|
var gpo = Helpers.ModuleGpoHelper.GetModuleGpoConfiguration(moduleType);
|
||||||
var isLocked = gpo is GpoRuleConfigured.Enabled or GpoRuleConfigured.Disabled;
|
var isLocked = gpo is GpoRuleConfigured.Enabled or GpoRuleConfigured.Disabled;
|
||||||
var isEnabled = gpo == GpoRuleConfigured.Enabled || (!isLocked && ModuleHelper.GetIsModuleEnabled(_generalSettings, moduleType));
|
var isEnabled = gpo == GpoRuleConfigured.Enabled || (!isLocked && Microsoft.PowerToys.Settings.UI.Library.Helpers.ModuleHelper.GetIsModuleEnabled(_generalSettings, moduleType));
|
||||||
|
|
||||||
var existingItem = FlyoutMenuItems.FirstOrDefault(x => x.Tag == moduleType);
|
var existingItem = FlyoutMenuItems.FirstOrDefault(x => x.Tag == moduleType);
|
||||||
|
|
||||||
if (existingItem != null)
|
if (existingItem != null)
|
||||||
{
|
{
|
||||||
existingItem.Label = _resourceLoader.GetString(ModuleHelper.GetModuleLabelResourceName(moduleType));
|
existingItem.Label = _resourceLoader.GetString(Microsoft.PowerToys.Settings.UI.Library.Helpers.ModuleHelper.GetModuleLabelResourceName(moduleType));
|
||||||
existingItem.IsLocked = isLocked;
|
existingItem.IsLocked = isLocked;
|
||||||
existingItem.Icon = ModuleHelper.GetModuleTypeFluentIconName(moduleType);
|
existingItem.Icon = Microsoft.PowerToys.Settings.UI.Library.Helpers.ModuleHelper.GetModuleTypeFluentIconName(moduleType);
|
||||||
|
|
||||||
if (existingItem.IsEnabled != isEnabled)
|
if (existingItem.IsEnabled != isEnabled)
|
||||||
{
|
{
|
||||||
@@ -117,11 +117,11 @@ public sealed class AllAppsViewModel : Observable
|
|||||||
{
|
{
|
||||||
desiredItems.Add(new FlyoutMenuItem
|
desiredItems.Add(new FlyoutMenuItem
|
||||||
{
|
{
|
||||||
Label = _resourceLoader.GetString(ModuleHelper.GetModuleLabelResourceName(moduleType)),
|
Label = _resourceLoader.GetString(Microsoft.PowerToys.Settings.UI.Library.Helpers.ModuleHelper.GetModuleLabelResourceName(moduleType)),
|
||||||
IsEnabled = isEnabled,
|
IsEnabled = isEnabled,
|
||||||
IsLocked = isLocked,
|
IsLocked = isLocked,
|
||||||
Tag = moduleType,
|
Tag = moduleType,
|
||||||
Icon = ModuleHelper.GetModuleTypeFluentIconName(moduleType),
|
Icon = Microsoft.PowerToys.Settings.UI.Library.Helpers.ModuleHelper.GetModuleTypeFluentIconName(moduleType),
|
||||||
EnabledChangedCallback = EnabledChangedOnUI,
|
EnabledChangedCallback = EnabledChangedOnUI,
|
||||||
ClickCommand = new RelayCommand(() => _coordinator.OpenSettingsForModule(moduleType)),
|
ClickCommand = new RelayCommand(() => _coordinator.OpenSettingsForModule(moduleType)),
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -2,21 +2,16 @@
|
|||||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||||
// See the LICENSE file in the project root for more information.
|
// See the LICENSE file in the project root for more information.
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using System.Threading;
|
|
||||||
using global::PowerToys.GPOWrapper;
|
using global::PowerToys.GPOWrapper;
|
||||||
using ManagedCommon;
|
using ManagedCommon;
|
||||||
using Microsoft.PowerToys.QuickAccess.Helpers;
|
|
||||||
using Microsoft.PowerToys.QuickAccess.Services;
|
using Microsoft.PowerToys.QuickAccess.Services;
|
||||||
using Microsoft.PowerToys.Settings.UI.Controls;
|
using Microsoft.PowerToys.Settings.UI.Controls;
|
||||||
using Microsoft.PowerToys.Settings.UI.Library;
|
using Microsoft.PowerToys.Settings.UI.Library;
|
||||||
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
|
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
|
||||||
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
|
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
|
||||||
using Microsoft.PowerToys.Settings.UI.Library.ViewModels.Commands;
|
|
||||||
using Microsoft.UI.Dispatching;
|
using Microsoft.UI.Dispatching;
|
||||||
using Microsoft.Windows.ApplicationModel.Resources;
|
using Microsoft.Windows.ApplicationModel.Resources;
|
||||||
using PowerToys.Interop;
|
|
||||||
|
|
||||||
namespace Microsoft.PowerToys.QuickAccess.ViewModels;
|
namespace Microsoft.PowerToys.QuickAccess.ViewModels;
|
||||||
|
|
||||||
@@ -26,9 +21,9 @@ public sealed class LauncherViewModel : Observable
|
|||||||
private readonly ISettingsRepository<GeneralSettings> _settingsRepository;
|
private readonly ISettingsRepository<GeneralSettings> _settingsRepository;
|
||||||
private readonly ResourceLoader _resourceLoader;
|
private readonly ResourceLoader _resourceLoader;
|
||||||
private readonly DispatcherQueue _dispatcherQueue;
|
private readonly DispatcherQueue _dispatcherQueue;
|
||||||
private GeneralSettings _generalSettings;
|
private readonly QuickAccessViewModel _quickAccessViewModel;
|
||||||
|
|
||||||
public ObservableCollection<QuickAccessItem> FlyoutMenuItems { get; }
|
public ObservableCollection<QuickAccessItem> FlyoutMenuItems => _quickAccessViewModel.Items;
|
||||||
|
|
||||||
public bool IsUpdateAvailable { get; private set; }
|
public bool IsUpdateAvailable { get; private set; }
|
||||||
|
|
||||||
@@ -38,200 +33,15 @@ public sealed class LauncherViewModel : Observable
|
|||||||
_dispatcherQueue = DispatcherQueue.GetForCurrentThread();
|
_dispatcherQueue = DispatcherQueue.GetForCurrentThread();
|
||||||
var settingsUtils = SettingsUtils.Default;
|
var settingsUtils = SettingsUtils.Default;
|
||||||
_settingsRepository = SettingsRepository<GeneralSettings>.GetInstance(settingsUtils);
|
_settingsRepository = SettingsRepository<GeneralSettings>.GetInstance(settingsUtils);
|
||||||
_generalSettings = _settingsRepository.SettingsConfig;
|
|
||||||
_generalSettings.AddEnabledModuleChangeNotification(ModuleEnabledChanged);
|
|
||||||
_settingsRepository.SettingsChanged += OnSettingsChanged;
|
|
||||||
|
|
||||||
_resourceLoader = Helpers.ResourceLoaderInstance.ResourceLoader;
|
_resourceLoader = Helpers.ResourceLoaderInstance.ResourceLoader;
|
||||||
FlyoutMenuItems = new ObservableCollection<QuickAccessItem>();
|
|
||||||
|
|
||||||
AddFlyoutMenuItem(ModuleType.ColorPicker);
|
|
||||||
AddFlyoutMenuItem(ModuleType.CmdPal);
|
|
||||||
AddFlyoutMenuItem(ModuleType.EnvironmentVariables);
|
|
||||||
AddFlyoutMenuItem(ModuleType.FancyZones);
|
|
||||||
AddFlyoutMenuItem(ModuleType.Hosts);
|
|
||||||
AddFlyoutMenuItem(ModuleType.PowerLauncher);
|
|
||||||
AddFlyoutMenuItem(ModuleType.PowerOCR);
|
|
||||||
AddFlyoutMenuItem(ModuleType.RegistryPreview);
|
|
||||||
AddFlyoutMenuItem(ModuleType.MeasureTool);
|
|
||||||
AddFlyoutMenuItem(ModuleType.ShortcutGuide);
|
|
||||||
AddFlyoutMenuItem(ModuleType.Workspaces);
|
|
||||||
|
|
||||||
|
_quickAccessViewModel = new QuickAccessViewModel(
|
||||||
|
_settingsRepository,
|
||||||
|
new QuickAccessLauncher(_coordinator),
|
||||||
|
moduleType => Helpers.ModuleGpoHelper.GetModuleGpoConfiguration(moduleType) == GpoRuleConfigured.Disabled,
|
||||||
|
_resourceLoader);
|
||||||
var updatingSettings = UpdatingSettings.LoadSettings() ?? new UpdatingSettings();
|
var updatingSettings = UpdatingSettings.LoadSettings() ?? new UpdatingSettings();
|
||||||
IsUpdateAvailable = updatingSettings.State is UpdatingSettings.UpdatingState.ReadyToInstall or UpdatingSettings.UpdatingState.ReadyToDownload;
|
IsUpdateAvailable = updatingSettings.State is UpdatingSettings.UpdatingState.ReadyToInstall or UpdatingSettings.UpdatingState.ReadyToDownload;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnSettingsChanged(GeneralSettings newSettings)
|
|
||||||
{
|
|
||||||
_dispatcherQueue.TryEnqueue(() =>
|
|
||||||
{
|
|
||||||
ModuleEnabledChanged();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void AddFlyoutMenuItem(ModuleType moduleType)
|
|
||||||
{
|
|
||||||
if (ModuleHelper.GetModuleGpoConfiguration(moduleType) == GpoRuleConfigured.Disabled)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
FlyoutMenuItems.Add(new QuickAccessItem
|
|
||||||
{
|
|
||||||
Title = _resourceLoader.GetString(ModuleHelper.GetModuleLabelResourceName(moduleType)),
|
|
||||||
Tag = moduleType,
|
|
||||||
Visible = ModuleHelper.GetIsModuleEnabled(_generalSettings, moduleType),
|
|
||||||
Description = GetModuleToolTip(moduleType),
|
|
||||||
Icon = ModuleHelper.GetModuleTypeFluentIconName(moduleType),
|
|
||||||
Command = new RelayCommand(() => LaunchModule(moduleType)),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void LaunchModule(ModuleType moduleType)
|
|
||||||
{
|
|
||||||
bool moduleRun = true;
|
|
||||||
|
|
||||||
switch (moduleType)
|
|
||||||
{
|
|
||||||
case ModuleType.ColorPicker:
|
|
||||||
using (var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, Constants.ShowColorPickerSharedEvent()))
|
|
||||||
{
|
|
||||||
eventHandle.Set();
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
case ModuleType.EnvironmentVariables:
|
|
||||||
{
|
|
||||||
bool launchAdmin = SettingsRepository<EnvironmentVariablesSettings>.GetInstance(SettingsUtils.Default).SettingsConfig.Properties.LaunchAdministrator;
|
|
||||||
bool isElevated = _coordinator?.IsRunnerElevated ?? false;
|
|
||||||
string eventName = !isElevated && launchAdmin
|
|
||||||
? Constants.ShowEnvironmentVariablesAdminSharedEvent()
|
|
||||||
: Constants.ShowEnvironmentVariablesSharedEvent();
|
|
||||||
|
|
||||||
using (var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, eventName))
|
|
||||||
{
|
|
||||||
eventHandle.Set();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
case ModuleType.FancyZones:
|
|
||||||
using (var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, Constants.FZEToggleEvent()))
|
|
||||||
{
|
|
||||||
eventHandle.Set();
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
case ModuleType.Hosts:
|
|
||||||
{
|
|
||||||
bool launchAdmin = SettingsRepository<HostsSettings>.GetInstance(SettingsUtils.Default).SettingsConfig.Properties.LaunchAdministrator;
|
|
||||||
bool isElevated = _coordinator?.IsRunnerElevated ?? false;
|
|
||||||
string eventName = !isElevated && launchAdmin
|
|
||||||
? Constants.ShowHostsAdminSharedEvent()
|
|
||||||
: Constants.ShowHostsSharedEvent();
|
|
||||||
|
|
||||||
using (var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, eventName))
|
|
||||||
{
|
|
||||||
eventHandle.Set();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
case ModuleType.PowerLauncher:
|
|
||||||
using (var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, Constants.PowerLauncherSharedEvent()))
|
|
||||||
{
|
|
||||||
eventHandle.Set();
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
case ModuleType.PowerOCR:
|
|
||||||
using (var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, Constants.ShowPowerOCRSharedEvent()))
|
|
||||||
{
|
|
||||||
eventHandle.Set();
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
case ModuleType.RegistryPreview:
|
|
||||||
using (var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, Constants.RegistryPreviewTriggerEvent()))
|
|
||||||
{
|
|
||||||
eventHandle.Set();
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
case ModuleType.MeasureTool:
|
|
||||||
using (var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, Constants.MeasureToolTriggerEvent()))
|
|
||||||
{
|
|
||||||
eventHandle.Set();
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
case ModuleType.ShortcutGuide:
|
|
||||||
using (var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, Constants.ShortcutGuideTriggerEvent()))
|
|
||||||
{
|
|
||||||
eventHandle.Set();
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
case ModuleType.CmdPal:
|
|
||||||
using (var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, Constants.ShowCmdPalEvent()))
|
|
||||||
{
|
|
||||||
eventHandle.Set();
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
case ModuleType.Workspaces:
|
|
||||||
using (var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, Constants.WorkspacesLaunchEditorEvent()))
|
|
||||||
{
|
|
||||||
eventHandle.Set();
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
moduleRun = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (moduleRun)
|
|
||||||
{
|
|
||||||
_coordinator?.OnModuleLaunched(moduleType);
|
|
||||||
}
|
|
||||||
|
|
||||||
_coordinator?.HideFlyout();
|
|
||||||
}
|
|
||||||
|
|
||||||
private string GetModuleToolTip(ModuleType moduleType)
|
|
||||||
{
|
|
||||||
return moduleType switch
|
|
||||||
{
|
|
||||||
ModuleType.ColorPicker => SettingsRepository<ColorPickerSettings>.GetInstance(SettingsUtils.Default).SettingsConfig.Properties.ActivationShortcut.ToString(),
|
|
||||||
ModuleType.FancyZones => SettingsRepository<FancyZonesSettings>.GetInstance(SettingsUtils.Default).SettingsConfig.Properties.FancyzonesEditorHotkey.Value.ToString(),
|
|
||||||
ModuleType.PowerLauncher => SettingsRepository<PowerLauncherSettings>.GetInstance(SettingsUtils.Default).SettingsConfig.Properties.OpenPowerLauncher.ToString(),
|
|
||||||
ModuleType.PowerOCR => SettingsRepository<PowerOcrSettings>.GetInstance(SettingsUtils.Default).SettingsConfig.Properties.ActivationShortcut.ToString(),
|
|
||||||
ModuleType.Workspaces => SettingsRepository<WorkspacesSettings>.GetInstance(SettingsUtils.Default).SettingsConfig.Properties.Hotkey.Value.ToString(),
|
|
||||||
ModuleType.MeasureTool => SettingsRepository<MeasureToolSettings>.GetInstance(SettingsUtils.Default).SettingsConfig.Properties.ActivationShortcut.ToString(),
|
|
||||||
ModuleType.ShortcutGuide => GetShortcutGuideToolTip(),
|
|
||||||
_ => string.Empty,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
private string GetShortcutGuideToolTip()
|
|
||||||
{
|
|
||||||
var shortcutGuideSettings = SettingsRepository<ShortcutGuideSettings>.GetInstance(SettingsUtils.Default).SettingsConfig;
|
|
||||||
return shortcutGuideSettings.Properties.UseLegacyPressWinKeyBehavior.Value
|
|
||||||
? "Win"
|
|
||||||
: shortcutGuideSettings.Properties.OpenShortcutGuide.ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ModuleEnabledChanged()
|
|
||||||
{
|
|
||||||
_generalSettings = _settingsRepository.SettingsConfig;
|
|
||||||
_generalSettings.AddEnabledModuleChangeNotification(ModuleEnabledChanged);
|
|
||||||
foreach (var item in FlyoutMenuItems)
|
|
||||||
{
|
|
||||||
if (item.Tag is ModuleType moduleType)
|
|
||||||
{
|
|
||||||
item.Visible = ModuleHelper.GetIsModuleEnabled(_generalSettings, moduleType);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
// 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 ManagedCommon;
|
||||||
|
|
||||||
|
namespace Microsoft.PowerToys.Settings.UI.Controls
|
||||||
|
{
|
||||||
|
public interface IQuickAccessLauncher
|
||||||
|
{
|
||||||
|
void Launch(ModuleType moduleType);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,66 +3,67 @@
|
|||||||
// See the LICENSE file in the project root for more information.
|
// See the LICENSE file in the project root for more information.
|
||||||
|
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
|
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
|
||||||
using Microsoft.UI.Xaml;
|
using Microsoft.UI.Xaml;
|
||||||
|
|
||||||
namespace Microsoft.PowerToys.Settings.UI.Controls
|
namespace Microsoft.PowerToys.Settings.UI.Controls
|
||||||
{
|
{
|
||||||
public sealed class QuickAccessItem : DependencyObject
|
public sealed class QuickAccessItem : Observable
|
||||||
{
|
{
|
||||||
|
private string _title = string.Empty;
|
||||||
|
|
||||||
public string Title
|
public string Title
|
||||||
{
|
{
|
||||||
get => (string)GetValue(TitleProperty);
|
get => _title;
|
||||||
set => SetValue(TitleProperty, value);
|
set => Set(ref _title, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static readonly DependencyProperty TitleProperty = DependencyProperty.Register(nameof(Title), typeof(string), typeof(QuickAccessItem), new PropertyMetadata(string.Empty));
|
private string _description = string.Empty;
|
||||||
|
|
||||||
public string Description
|
public string Description
|
||||||
{
|
{
|
||||||
get => (string)GetValue(DescriptionProperty);
|
get => _description;
|
||||||
set => SetValue(DescriptionProperty, value);
|
set => Set(ref _description, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static readonly DependencyProperty DescriptionProperty = DependencyProperty.Register(nameof(Description), typeof(string), typeof(QuickAccessItem), new PropertyMetadata(string.Empty));
|
private string _icon = string.Empty;
|
||||||
|
|
||||||
public string Icon
|
public string Icon
|
||||||
{
|
{
|
||||||
get => (string)GetValue(IconProperty);
|
get => _icon;
|
||||||
set => SetValue(IconProperty, value);
|
set => Set(ref _icon, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static readonly DependencyProperty IconProperty = DependencyProperty.Register(nameof(Icon), typeof(string), typeof(QuickAccessItem), new PropertyMetadata(string.Empty));
|
private ICommand? _command;
|
||||||
|
|
||||||
public ICommand Command
|
public ICommand? Command
|
||||||
{
|
{
|
||||||
get => (ICommand)GetValue(CommandProperty);
|
get => _command;
|
||||||
set => SetValue(CommandProperty, value);
|
set => Set(ref _command, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static readonly DependencyProperty CommandProperty = DependencyProperty.Register(nameof(Command), typeof(ICommand), typeof(QuickAccessItem), new PropertyMetadata(null));
|
private object? _commandParameter;
|
||||||
|
|
||||||
public object CommandParameter
|
public object? CommandParameter
|
||||||
{
|
{
|
||||||
get => (object)GetValue(CommandParameterProperty);
|
get => _commandParameter;
|
||||||
set => SetValue(CommandParameterProperty, value);
|
set => Set(ref _commandParameter, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static readonly DependencyProperty CommandParameterProperty = DependencyProperty.Register(nameof(CommandParameter), typeof(object), typeof(QuickAccessItem), new PropertyMetadata(null));
|
private bool _visible = true;
|
||||||
|
|
||||||
public bool Visible
|
public bool Visible
|
||||||
{
|
{
|
||||||
get => (bool)GetValue(VisibleProperty);
|
get => _visible;
|
||||||
set => SetValue(VisibleProperty, value);
|
set => Set(ref _visible, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static readonly DependencyProperty VisibleProperty = DependencyProperty.Register(nameof(Visible), typeof(bool), typeof(QuickAccessItem), new PropertyMetadata(true));
|
private object? _tag;
|
||||||
|
|
||||||
public object Tag
|
public object? Tag
|
||||||
{
|
{
|
||||||
get => (object)GetValue(TagProperty);
|
get => _tag;
|
||||||
set => SetValue(TagProperty, value);
|
set => Set(ref _tag, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static readonly DependencyProperty TagProperty = DependencyProperty.Register(nameof(Tag), typeof(object), typeof(QuickAccessItem), new PropertyMetadata(null));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,140 @@
|
|||||||
|
// 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.ObjectModel;
|
||||||
|
using ManagedCommon;
|
||||||
|
using Microsoft.PowerToys.Settings.UI.Library;
|
||||||
|
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
|
||||||
|
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
|
||||||
|
using Microsoft.PowerToys.Settings.UI.Library.ViewModels.Commands;
|
||||||
|
using Microsoft.UI.Dispatching;
|
||||||
|
using Microsoft.Windows.ApplicationModel.Resources;
|
||||||
|
|
||||||
|
namespace Microsoft.PowerToys.Settings.UI.Controls
|
||||||
|
{
|
||||||
|
public partial class QuickAccessViewModel : Observable
|
||||||
|
{
|
||||||
|
private readonly ISettingsRepository<GeneralSettings> _settingsRepository;
|
||||||
|
private readonly IQuickAccessLauncher _launcher;
|
||||||
|
private readonly Func<ModuleType, bool> _isModuleGpoDisabled;
|
||||||
|
private readonly ResourceLoader _resourceLoader;
|
||||||
|
private readonly DispatcherQueue _dispatcherQueue;
|
||||||
|
private GeneralSettings _generalSettings;
|
||||||
|
|
||||||
|
public ObservableCollection<QuickAccessItem> Items { get; } = new();
|
||||||
|
|
||||||
|
public QuickAccessViewModel(
|
||||||
|
ISettingsRepository<GeneralSettings> settingsRepository,
|
||||||
|
IQuickAccessLauncher launcher,
|
||||||
|
Func<ModuleType, bool> isModuleGpoDisabled,
|
||||||
|
ResourceLoader resourceLoader)
|
||||||
|
{
|
||||||
|
_settingsRepository = settingsRepository;
|
||||||
|
_launcher = launcher;
|
||||||
|
_isModuleGpoDisabled = isModuleGpoDisabled;
|
||||||
|
_resourceLoader = resourceLoader;
|
||||||
|
_dispatcherQueue = DispatcherQueue.GetForCurrentThread();
|
||||||
|
|
||||||
|
_generalSettings = _settingsRepository.SettingsConfig;
|
||||||
|
_generalSettings.AddEnabledModuleChangeNotification(ModuleEnabledChanged);
|
||||||
|
_settingsRepository.SettingsChanged += OnSettingsChanged;
|
||||||
|
|
||||||
|
InitializeItems();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnSettingsChanged(GeneralSettings newSettings)
|
||||||
|
{
|
||||||
|
if (_dispatcherQueue != null)
|
||||||
|
{
|
||||||
|
_dispatcherQueue.TryEnqueue(() =>
|
||||||
|
{
|
||||||
|
_generalSettings = newSettings;
|
||||||
|
_generalSettings.AddEnabledModuleChangeNotification(ModuleEnabledChanged);
|
||||||
|
RefreshItemsVisibility();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void InitializeItems()
|
||||||
|
{
|
||||||
|
AddFlyoutMenuItem(ModuleType.ColorPicker);
|
||||||
|
AddFlyoutMenuItem(ModuleType.CmdPal);
|
||||||
|
AddFlyoutMenuItem(ModuleType.EnvironmentVariables);
|
||||||
|
AddFlyoutMenuItem(ModuleType.FancyZones);
|
||||||
|
AddFlyoutMenuItem(ModuleType.Hosts);
|
||||||
|
AddFlyoutMenuItem(ModuleType.PowerLauncher);
|
||||||
|
AddFlyoutMenuItem(ModuleType.PowerOCR);
|
||||||
|
AddFlyoutMenuItem(ModuleType.RegistryPreview);
|
||||||
|
AddFlyoutMenuItem(ModuleType.MeasureTool);
|
||||||
|
AddFlyoutMenuItem(ModuleType.ShortcutGuide);
|
||||||
|
AddFlyoutMenuItem(ModuleType.Workspaces);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void AddFlyoutMenuItem(ModuleType moduleType)
|
||||||
|
{
|
||||||
|
if (_isModuleGpoDisabled(moduleType))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Items.Add(new QuickAccessItem
|
||||||
|
{
|
||||||
|
Title = _resourceLoader.GetString(Microsoft.PowerToys.Settings.UI.Library.Helpers.ModuleHelper.GetModuleLabelResourceName(moduleType)),
|
||||||
|
Tag = moduleType,
|
||||||
|
Visible = Microsoft.PowerToys.Settings.UI.Library.Helpers.ModuleHelper.GetIsModuleEnabled(_generalSettings, moduleType),
|
||||||
|
Description = GetModuleToolTip(moduleType),
|
||||||
|
Icon = Microsoft.PowerToys.Settings.UI.Library.Helpers.ModuleHelper.GetModuleTypeFluentIconName(moduleType),
|
||||||
|
Command = new RelayCommand(() => _launcher.Launch(moduleType)),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ModuleEnabledChanged()
|
||||||
|
{
|
||||||
|
if (_dispatcherQueue != null)
|
||||||
|
{
|
||||||
|
_dispatcherQueue.TryEnqueue(() =>
|
||||||
|
{
|
||||||
|
_generalSettings = _settingsRepository.SettingsConfig;
|
||||||
|
_generalSettings.AddEnabledModuleChangeNotification(ModuleEnabledChanged);
|
||||||
|
RefreshItemsVisibility();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RefreshItemsVisibility()
|
||||||
|
{
|
||||||
|
foreach (var item in Items)
|
||||||
|
{
|
||||||
|
if (item.Tag is ModuleType moduleType)
|
||||||
|
{
|
||||||
|
item.Visible = Microsoft.PowerToys.Settings.UI.Library.Helpers.ModuleHelper.GetIsModuleEnabled(_generalSettings, moduleType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private string GetModuleToolTip(ModuleType moduleType)
|
||||||
|
{
|
||||||
|
return moduleType switch
|
||||||
|
{
|
||||||
|
ModuleType.ColorPicker => SettingsRepository<ColorPickerSettings>.GetInstance(SettingsUtils.Default).SettingsConfig.Properties.ActivationShortcut.ToString(),
|
||||||
|
ModuleType.FancyZones => SettingsRepository<FancyZonesSettings>.GetInstance(SettingsUtils.Default).SettingsConfig.Properties.FancyzonesEditorHotkey.Value.ToString(),
|
||||||
|
ModuleType.PowerLauncher => SettingsRepository<PowerLauncherSettings>.GetInstance(SettingsUtils.Default).SettingsConfig.Properties.OpenPowerLauncher.ToString(),
|
||||||
|
ModuleType.PowerOCR => SettingsRepository<PowerOcrSettings>.GetInstance(SettingsUtils.Default).SettingsConfig.Properties.ActivationShortcut.ToString(),
|
||||||
|
ModuleType.Workspaces => SettingsRepository<WorkspacesSettings>.GetInstance(SettingsUtils.Default).SettingsConfig.Properties.Hotkey.Value.ToString(),
|
||||||
|
ModuleType.MeasureTool => SettingsRepository<MeasureToolSettings>.GetInstance(SettingsUtils.Default).SettingsConfig.Properties.ActivationShortcut.ToString(),
|
||||||
|
ModuleType.ShortcutGuide => GetShortcutGuideToolTip(),
|
||||||
|
_ => string.Empty,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private string GetShortcutGuideToolTip()
|
||||||
|
{
|
||||||
|
var shortcutGuideSettings = SettingsRepository<ShortcutGuideSettings>.GetInstance(SettingsUtils.Default).SettingsConfig;
|
||||||
|
return shortcutGuideSettings.Properties.UseLegacyPressWinKeyBehavior.Value
|
||||||
|
? "Win"
|
||||||
|
: shortcutGuideSettings.Properties.OpenShortcutGuide.ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -24,4 +24,9 @@
|
|||||||
<PackageReference Include="WinUIEx" />
|
<PackageReference Include="WinUIEx" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\..\common\ManagedCommon\ManagedCommon.csproj" />
|
||||||
|
<ProjectReference Include="..\Settings.UI.Library\Settings.UI.Library.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
121
src/settings-ui/Settings.UI.Library/Helpers/ModuleHelper.cs
Normal file
121
src/settings-ui/Settings.UI.Library/Helpers/ModuleHelper.cs
Normal file
@@ -0,0 +1,121 @@
|
|||||||
|
// 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 ManagedCommon;
|
||||||
|
|
||||||
|
namespace Microsoft.PowerToys.Settings.UI.Library.Helpers
|
||||||
|
{
|
||||||
|
public static class ModuleHelper
|
||||||
|
{
|
||||||
|
public static string GetModuleLabelResourceName(ModuleType moduleType)
|
||||||
|
{
|
||||||
|
return moduleType switch
|
||||||
|
{
|
||||||
|
ModuleType.Workspaces => "Workspaces/ModuleTitle",
|
||||||
|
ModuleType.PowerAccent => "QuickAccent/ModuleTitle",
|
||||||
|
ModuleType.PowerOCR => "TextExtractor/ModuleTitle",
|
||||||
|
ModuleType.FindMyMouse => "MouseUtils_FindMyMouse/Header",
|
||||||
|
ModuleType.MouseHighlighter => "MouseUtils_MouseHighlighter/Header",
|
||||||
|
ModuleType.MouseJump => "MouseUtils_MouseJump/Header",
|
||||||
|
ModuleType.MousePointerCrosshairs => "MouseUtils_MousePointerCrosshairs/Header",
|
||||||
|
ModuleType.CursorWrap => "MouseUtils_CursorWrap/Header",
|
||||||
|
ModuleType.GeneralSettings => "QuickAccessTitle/Title",
|
||||||
|
_ => $"{moduleType}/ModuleTitle",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string GetModuleTypeFluentIconName(ModuleType moduleType)
|
||||||
|
{
|
||||||
|
return moduleType switch
|
||||||
|
{
|
||||||
|
ModuleType.AdvancedPaste => "ms-appx:///Assets/Settings/Icons/AdvancedPaste.png",
|
||||||
|
ModuleType.Workspaces => "ms-appx:///Assets/Settings/Icons/Workspaces.png",
|
||||||
|
ModuleType.PowerOCR => "ms-appx:///Assets/Settings/Icons/TextExtractor.png",
|
||||||
|
ModuleType.PowerAccent => "ms-appx:///Assets/Settings/Icons/QuickAccent.png",
|
||||||
|
ModuleType.MousePointerCrosshairs => "ms-appx:///Assets/Settings/Icons/MouseCrosshairs.png",
|
||||||
|
ModuleType.MeasureTool => "ms-appx:///Assets/Settings/Icons/ScreenRuler.png",
|
||||||
|
ModuleType.PowerLauncher => "ms-appx:///Assets/Settings/Icons/PowerToysRun.png",
|
||||||
|
ModuleType.GeneralSettings => "ms-appx:///Assets/Settings/Icons/PowerToys.png",
|
||||||
|
_ => $"ms-appx:///Assets/Settings/Icons/{moduleType}.png",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool GetIsModuleEnabled(GeneralSettings generalSettingsConfig, ModuleType moduleType)
|
||||||
|
{
|
||||||
|
return moduleType switch
|
||||||
|
{
|
||||||
|
ModuleType.AdvancedPaste => generalSettingsConfig.Enabled.AdvancedPaste,
|
||||||
|
ModuleType.AlwaysOnTop => generalSettingsConfig.Enabled.AlwaysOnTop,
|
||||||
|
ModuleType.Awake => generalSettingsConfig.Enabled.Awake,
|
||||||
|
ModuleType.CmdPal => generalSettingsConfig.Enabled.CmdPal,
|
||||||
|
ModuleType.ColorPicker => generalSettingsConfig.Enabled.ColorPicker,
|
||||||
|
ModuleType.CropAndLock => generalSettingsConfig.Enabled.CropAndLock,
|
||||||
|
ModuleType.CursorWrap => generalSettingsConfig.Enabled.CursorWrap,
|
||||||
|
ModuleType.EnvironmentVariables => generalSettingsConfig.Enabled.EnvironmentVariables,
|
||||||
|
ModuleType.FancyZones => generalSettingsConfig.Enabled.FancyZones,
|
||||||
|
ModuleType.FileLocksmith => generalSettingsConfig.Enabled.FileLocksmith,
|
||||||
|
ModuleType.FindMyMouse => generalSettingsConfig.Enabled.FindMyMouse,
|
||||||
|
ModuleType.Hosts => generalSettingsConfig.Enabled.Hosts,
|
||||||
|
ModuleType.ImageResizer => generalSettingsConfig.Enabled.ImageResizer,
|
||||||
|
ModuleType.KeyboardManager => generalSettingsConfig.Enabled.KeyboardManager,
|
||||||
|
ModuleType.LightSwitch => generalSettingsConfig.Enabled.LightSwitch,
|
||||||
|
ModuleType.MouseHighlighter => generalSettingsConfig.Enabled.MouseHighlighter,
|
||||||
|
ModuleType.MouseJump => generalSettingsConfig.Enabled.MouseJump,
|
||||||
|
ModuleType.MousePointerCrosshairs => generalSettingsConfig.Enabled.MousePointerCrosshairs,
|
||||||
|
ModuleType.MouseWithoutBorders => generalSettingsConfig.Enabled.MouseWithoutBorders,
|
||||||
|
ModuleType.NewPlus => generalSettingsConfig.Enabled.NewPlus,
|
||||||
|
ModuleType.Peek => generalSettingsConfig.Enabled.Peek,
|
||||||
|
ModuleType.PowerRename => generalSettingsConfig.Enabled.PowerRename,
|
||||||
|
ModuleType.PowerLauncher => generalSettingsConfig.Enabled.PowerLauncher,
|
||||||
|
ModuleType.PowerAccent => generalSettingsConfig.Enabled.PowerAccent,
|
||||||
|
ModuleType.RegistryPreview => generalSettingsConfig.Enabled.RegistryPreview,
|
||||||
|
ModuleType.MeasureTool => generalSettingsConfig.Enabled.MeasureTool,
|
||||||
|
ModuleType.ShortcutGuide => generalSettingsConfig.Enabled.ShortcutGuide,
|
||||||
|
ModuleType.PowerOCR => generalSettingsConfig.Enabled.PowerOcr,
|
||||||
|
ModuleType.Workspaces => generalSettingsConfig.Enabled.Workspaces,
|
||||||
|
ModuleType.ZoomIt => generalSettingsConfig.Enabled.ZoomIt,
|
||||||
|
ModuleType.GeneralSettings => generalSettingsConfig.EnableQuickAccess,
|
||||||
|
_ => false,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void SetIsModuleEnabled(GeneralSettings generalSettingsConfig, ModuleType moduleType, bool isEnabled)
|
||||||
|
{
|
||||||
|
switch (moduleType)
|
||||||
|
{
|
||||||
|
case ModuleType.AdvancedPaste: generalSettingsConfig.Enabled.AdvancedPaste = isEnabled; break;
|
||||||
|
case ModuleType.AlwaysOnTop: generalSettingsConfig.Enabled.AlwaysOnTop = isEnabled; break;
|
||||||
|
case ModuleType.Awake: generalSettingsConfig.Enabled.Awake = isEnabled; break;
|
||||||
|
case ModuleType.CmdPal: generalSettingsConfig.Enabled.CmdPal = isEnabled; break;
|
||||||
|
case ModuleType.ColorPicker: generalSettingsConfig.Enabled.ColorPicker = isEnabled; break;
|
||||||
|
case ModuleType.CropAndLock: generalSettingsConfig.Enabled.CropAndLock = isEnabled; break;
|
||||||
|
case ModuleType.CursorWrap: generalSettingsConfig.Enabled.CursorWrap = isEnabled; break;
|
||||||
|
case ModuleType.EnvironmentVariables: generalSettingsConfig.Enabled.EnvironmentVariables = isEnabled; break;
|
||||||
|
case ModuleType.FancyZones: generalSettingsConfig.Enabled.FancyZones = isEnabled; break;
|
||||||
|
case ModuleType.FileLocksmith: generalSettingsConfig.Enabled.FileLocksmith = isEnabled; break;
|
||||||
|
case ModuleType.FindMyMouse: generalSettingsConfig.Enabled.FindMyMouse = isEnabled; break;
|
||||||
|
case ModuleType.Hosts: generalSettingsConfig.Enabled.Hosts = isEnabled; break;
|
||||||
|
case ModuleType.ImageResizer: generalSettingsConfig.Enabled.ImageResizer = isEnabled; break;
|
||||||
|
case ModuleType.KeyboardManager: generalSettingsConfig.Enabled.KeyboardManager = isEnabled; break;
|
||||||
|
case ModuleType.LightSwitch: generalSettingsConfig.Enabled.LightSwitch = isEnabled; break;
|
||||||
|
case ModuleType.MouseHighlighter: generalSettingsConfig.Enabled.MouseHighlighter = isEnabled; break;
|
||||||
|
case ModuleType.MouseJump: generalSettingsConfig.Enabled.MouseJump = isEnabled; break;
|
||||||
|
case ModuleType.MousePointerCrosshairs: generalSettingsConfig.Enabled.MousePointerCrosshairs = isEnabled; break;
|
||||||
|
case ModuleType.MouseWithoutBorders: generalSettingsConfig.Enabled.MouseWithoutBorders = isEnabled; break;
|
||||||
|
case ModuleType.NewPlus: generalSettingsConfig.Enabled.NewPlus = isEnabled; break;
|
||||||
|
case ModuleType.Peek: generalSettingsConfig.Enabled.Peek = isEnabled; break;
|
||||||
|
case ModuleType.PowerRename: generalSettingsConfig.Enabled.PowerRename = isEnabled; break;
|
||||||
|
case ModuleType.PowerLauncher: generalSettingsConfig.Enabled.PowerLauncher = isEnabled; break;
|
||||||
|
case ModuleType.PowerAccent: generalSettingsConfig.Enabled.PowerAccent = isEnabled; break;
|
||||||
|
case ModuleType.RegistryPreview: generalSettingsConfig.Enabled.RegistryPreview = isEnabled; break;
|
||||||
|
case ModuleType.MeasureTool: generalSettingsConfig.Enabled.MeasureTool = isEnabled; break;
|
||||||
|
case ModuleType.ShortcutGuide: generalSettingsConfig.Enabled.ShortcutGuide = isEnabled; break;
|
||||||
|
case ModuleType.PowerOCR: generalSettingsConfig.Enabled.PowerOcr = isEnabled; break;
|
||||||
|
case ModuleType.Workspaces: generalSettingsConfig.Enabled.Workspaces = isEnabled; break;
|
||||||
|
case ModuleType.ZoomIt: generalSettingsConfig.Enabled.ZoomIt = isEnabled; break;
|
||||||
|
case ModuleType.GeneralSettings: generalSettingsConfig.EnableQuickAccess = isEnabled; break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
91
src/settings-ui/Settings.UI/Helpers/ModuleGpoHelper.cs
Normal file
91
src/settings-ui/Settings.UI/Helpers/ModuleGpoHelper.cs
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
// 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 global::PowerToys.GPOWrapper;
|
||||||
|
using ManagedCommon;
|
||||||
|
using Microsoft.PowerToys.Settings.UI.Library;
|
||||||
|
using Microsoft.PowerToys.Settings.UI.Views;
|
||||||
|
using Windows.UI;
|
||||||
|
|
||||||
|
namespace Microsoft.PowerToys.Settings.UI.Helpers
|
||||||
|
{
|
||||||
|
internal sealed class ModuleGpoHelper
|
||||||
|
{
|
||||||
|
public static GpoRuleConfigured GetModuleGpoConfiguration(ModuleType moduleType)
|
||||||
|
{
|
||||||
|
switch (moduleType)
|
||||||
|
{
|
||||||
|
case ModuleType.AdvancedPaste: return GPOWrapper.GetConfiguredAdvancedPasteEnabledValue();
|
||||||
|
case ModuleType.AlwaysOnTop: return GPOWrapper.GetConfiguredAlwaysOnTopEnabledValue();
|
||||||
|
case ModuleType.Awake: return GPOWrapper.GetConfiguredAwakeEnabledValue();
|
||||||
|
case ModuleType.CmdPal: return GPOWrapper.GetConfiguredCmdPalEnabledValue();
|
||||||
|
case ModuleType.ColorPicker: return GPOWrapper.GetConfiguredColorPickerEnabledValue();
|
||||||
|
case ModuleType.CropAndLock: return GPOWrapper.GetConfiguredCropAndLockEnabledValue();
|
||||||
|
case ModuleType.CursorWrap: return GPOWrapper.GetConfiguredCursorWrapEnabledValue();
|
||||||
|
case ModuleType.EnvironmentVariables: return GPOWrapper.GetConfiguredEnvironmentVariablesEnabledValue();
|
||||||
|
case ModuleType.FancyZones: return GPOWrapper.GetConfiguredFancyZonesEnabledValue();
|
||||||
|
case ModuleType.FileLocksmith: return GPOWrapper.GetConfiguredFileLocksmithEnabledValue();
|
||||||
|
case ModuleType.FindMyMouse: return GPOWrapper.GetConfiguredFindMyMouseEnabledValue();
|
||||||
|
case ModuleType.Hosts: return GPOWrapper.GetConfiguredHostsFileEditorEnabledValue();
|
||||||
|
case ModuleType.ImageResizer: return GPOWrapper.GetConfiguredImageResizerEnabledValue();
|
||||||
|
case ModuleType.KeyboardManager: return GPOWrapper.GetConfiguredKeyboardManagerEnabledValue();
|
||||||
|
case ModuleType.MouseHighlighter: return GPOWrapper.GetConfiguredMouseHighlighterEnabledValue();
|
||||||
|
case ModuleType.MouseJump: return GPOWrapper.GetConfiguredMouseJumpEnabledValue();
|
||||||
|
case ModuleType.MousePointerCrosshairs: return GPOWrapper.GetConfiguredMousePointerCrosshairsEnabledValue();
|
||||||
|
case ModuleType.MouseWithoutBorders: return GPOWrapper.GetConfiguredMouseWithoutBordersEnabledValue();
|
||||||
|
case ModuleType.NewPlus: return GPOWrapper.GetConfiguredNewPlusEnabledValue();
|
||||||
|
case ModuleType.Peek: return GPOWrapper.GetConfiguredPeekEnabledValue();
|
||||||
|
case ModuleType.PowerRename: return GPOWrapper.GetConfiguredPowerRenameEnabledValue();
|
||||||
|
case ModuleType.PowerLauncher: return GPOWrapper.GetConfiguredPowerLauncherEnabledValue();
|
||||||
|
case ModuleType.PowerAccent: return GPOWrapper.GetConfiguredQuickAccentEnabledValue();
|
||||||
|
case ModuleType.Workspaces: return GPOWrapper.GetConfiguredWorkspacesEnabledValue();
|
||||||
|
case ModuleType.RegistryPreview: return GPOWrapper.GetConfiguredRegistryPreviewEnabledValue();
|
||||||
|
case ModuleType.MeasureTool: return GPOWrapper.GetConfiguredScreenRulerEnabledValue();
|
||||||
|
case ModuleType.ShortcutGuide: return GPOWrapper.GetConfiguredShortcutGuideEnabledValue();
|
||||||
|
case ModuleType.PowerOCR: return GPOWrapper.GetConfiguredTextExtractorEnabledValue();
|
||||||
|
case ModuleType.ZoomIt: return GPOWrapper.GetConfiguredZoomItEnabledValue();
|
||||||
|
default: return GpoRuleConfigured.Unavailable;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static System.Type GetModulePageType(ModuleType moduleType)
|
||||||
|
{
|
||||||
|
return moduleType switch
|
||||||
|
{
|
||||||
|
ModuleType.AdvancedPaste => typeof(AdvancedPastePage),
|
||||||
|
ModuleType.AlwaysOnTop => typeof(AlwaysOnTopPage),
|
||||||
|
ModuleType.Awake => typeof(AwakePage),
|
||||||
|
ModuleType.CmdPal => typeof(CmdPalPage),
|
||||||
|
ModuleType.ColorPicker => typeof(ColorPickerPage),
|
||||||
|
ModuleType.CropAndLock => typeof(CropAndLockPage),
|
||||||
|
ModuleType.CursorWrap => typeof(MouseUtilsPage),
|
||||||
|
ModuleType.LightSwitch => typeof(LightSwitchPage),
|
||||||
|
ModuleType.EnvironmentVariables => typeof(EnvironmentVariablesPage),
|
||||||
|
ModuleType.FancyZones => typeof(FancyZonesPage),
|
||||||
|
ModuleType.FileLocksmith => typeof(FileLocksmithPage),
|
||||||
|
ModuleType.FindMyMouse => typeof(MouseUtilsPage),
|
||||||
|
ModuleType.GeneralSettings => typeof(GeneralPage),
|
||||||
|
ModuleType.Hosts => typeof(HostsPage),
|
||||||
|
ModuleType.ImageResizer => typeof(ImageResizerPage),
|
||||||
|
ModuleType.KeyboardManager => typeof(KeyboardManagerPage),
|
||||||
|
ModuleType.MouseHighlighter => typeof(MouseUtilsPage),
|
||||||
|
ModuleType.MouseJump => typeof(MouseUtilsPage),
|
||||||
|
ModuleType.MousePointerCrosshairs => typeof(MouseUtilsPage),
|
||||||
|
ModuleType.MouseWithoutBorders => typeof(MouseWithoutBordersPage),
|
||||||
|
ModuleType.NewPlus => typeof(NewPlusPage),
|
||||||
|
ModuleType.Peek => typeof(PeekPage),
|
||||||
|
ModuleType.PowerRename => typeof(PowerRenamePage),
|
||||||
|
ModuleType.PowerLauncher => typeof(PowerLauncherPage),
|
||||||
|
ModuleType.PowerAccent => typeof(PowerAccentPage),
|
||||||
|
ModuleType.Workspaces => typeof(WorkspacesPage),
|
||||||
|
ModuleType.RegistryPreview => typeof(RegistryPreviewPage),
|
||||||
|
ModuleType.MeasureTool => typeof(MeasureToolPage),
|
||||||
|
ModuleType.ShortcutGuide => typeof(ShortcutGuidePage),
|
||||||
|
ModuleType.PowerOCR => typeof(PowerOcrPage),
|
||||||
|
ModuleType.ZoomIt => typeof(ZoomItPage),
|
||||||
|
_ => typeof(DashboardPage), // never called, all values listed above
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,201 +0,0 @@
|
|||||||
// 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 global::PowerToys.GPOWrapper;
|
|
||||||
using ManagedCommon;
|
|
||||||
using Microsoft.PowerToys.Settings.UI.Library;
|
|
||||||
using Microsoft.PowerToys.Settings.UI.Views;
|
|
||||||
using Windows.UI;
|
|
||||||
|
|
||||||
namespace Microsoft.PowerToys.Settings.UI.Helpers
|
|
||||||
{
|
|
||||||
internal sealed class ModuleHelper
|
|
||||||
{
|
|
||||||
public static string GetModuleLabelResourceName(ModuleType moduleType)
|
|
||||||
{
|
|
||||||
switch (moduleType)
|
|
||||||
{
|
|
||||||
case ModuleType.Workspaces: return "Workspaces/ModuleTitle";
|
|
||||||
case ModuleType.PowerAccent: return "QuickAccent/ModuleTitle";
|
|
||||||
case ModuleType.PowerOCR: return "TextExtractor/ModuleTitle";
|
|
||||||
case ModuleType.FindMyMouse:
|
|
||||||
case ModuleType.MouseHighlighter:
|
|
||||||
case ModuleType.MouseJump:
|
|
||||||
case ModuleType.MousePointerCrosshairs:
|
|
||||||
case ModuleType.CursorWrap: return $"MouseUtils_{moduleType}/Header";
|
|
||||||
case ModuleType.GeneralSettings: return "QuickAccessTitle/Title";
|
|
||||||
default: return $"{moduleType}/ModuleTitle";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string GetModuleTypeFluentIconName(ModuleType moduleType)
|
|
||||||
{
|
|
||||||
switch (moduleType)
|
|
||||||
{
|
|
||||||
case ModuleType.AdvancedPaste: return "ms-appx:///Assets/Settings/Icons/AdvancedPaste.png";
|
|
||||||
case ModuleType.Workspaces: return "ms-appx:///Assets/Settings/Icons/Workspaces.png";
|
|
||||||
case ModuleType.PowerOCR: return "ms-appx:///Assets/Settings/Icons/TextExtractor.png";
|
|
||||||
case ModuleType.PowerAccent: return "ms-appx:///Assets/Settings/Icons/QuickAccent.png";
|
|
||||||
case ModuleType.MousePointerCrosshairs: return "ms-appx:///Assets/Settings/Icons/MouseCrosshairs.png";
|
|
||||||
case ModuleType.MeasureTool: return "ms-appx:///Assets/Settings/Icons/ScreenRuler.png";
|
|
||||||
case ModuleType.PowerLauncher: return $"ms-appx:///Assets/Settings/Icons/PowerToysRun.png";
|
|
||||||
case ModuleType.GeneralSettings: return "ms-appx:///Assets/Settings/Icons/PowerToys.png";
|
|
||||||
default: return $"ms-appx:///Assets/Settings/Icons/{moduleType}.png";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool GetIsModuleEnabled(Library.GeneralSettings generalSettingsConfig, ModuleType moduleType)
|
|
||||||
{
|
|
||||||
switch (moduleType)
|
|
||||||
{
|
|
||||||
case ModuleType.AdvancedPaste: return generalSettingsConfig.Enabled.AdvancedPaste;
|
|
||||||
case ModuleType.AlwaysOnTop: return generalSettingsConfig.Enabled.AlwaysOnTop;
|
|
||||||
case ModuleType.Awake: return generalSettingsConfig.Enabled.Awake;
|
|
||||||
case ModuleType.CmdPal: return generalSettingsConfig.Enabled.CmdPal;
|
|
||||||
case ModuleType.ColorPicker: return generalSettingsConfig.Enabled.ColorPicker;
|
|
||||||
case ModuleType.CropAndLock: return generalSettingsConfig.Enabled.CropAndLock;
|
|
||||||
case ModuleType.CursorWrap: return generalSettingsConfig.Enabled.CursorWrap;
|
|
||||||
case ModuleType.LightSwitch: return generalSettingsConfig.Enabled.LightSwitch;
|
|
||||||
case ModuleType.EnvironmentVariables: return generalSettingsConfig.Enabled.EnvironmentVariables;
|
|
||||||
case ModuleType.FancyZones: return generalSettingsConfig.Enabled.FancyZones;
|
|
||||||
case ModuleType.FileLocksmith: return generalSettingsConfig.Enabled.FileLocksmith;
|
|
||||||
case ModuleType.FindMyMouse: return generalSettingsConfig.Enabled.FindMyMouse;
|
|
||||||
case ModuleType.Hosts: return generalSettingsConfig.Enabled.Hosts;
|
|
||||||
case ModuleType.ImageResizer: return generalSettingsConfig.Enabled.ImageResizer;
|
|
||||||
case ModuleType.KeyboardManager: return generalSettingsConfig.Enabled.KeyboardManager;
|
|
||||||
case ModuleType.MouseHighlighter: return generalSettingsConfig.Enabled.MouseHighlighter;
|
|
||||||
case ModuleType.MouseJump: return generalSettingsConfig.Enabled.MouseJump;
|
|
||||||
case ModuleType.MousePointerCrosshairs: return generalSettingsConfig.Enabled.MousePointerCrosshairs;
|
|
||||||
case ModuleType.MouseWithoutBorders: return generalSettingsConfig.Enabled.MouseWithoutBorders;
|
|
||||||
case ModuleType.NewPlus: return generalSettingsConfig.Enabled.NewPlus;
|
|
||||||
case ModuleType.Peek: return generalSettingsConfig.Enabled.Peek;
|
|
||||||
case ModuleType.PowerRename: return generalSettingsConfig.Enabled.PowerRename;
|
|
||||||
case ModuleType.PowerLauncher: return generalSettingsConfig.Enabled.PowerLauncher;
|
|
||||||
case ModuleType.PowerAccent: return generalSettingsConfig.Enabled.PowerAccent;
|
|
||||||
case ModuleType.Workspaces: return generalSettingsConfig.Enabled.Workspaces;
|
|
||||||
case ModuleType.RegistryPreview: return generalSettingsConfig.Enabled.RegistryPreview;
|
|
||||||
case ModuleType.MeasureTool: return generalSettingsConfig.Enabled.MeasureTool;
|
|
||||||
case ModuleType.ShortcutGuide: return generalSettingsConfig.Enabled.ShortcutGuide;
|
|
||||||
case ModuleType.PowerOCR: return generalSettingsConfig.Enabled.PowerOcr;
|
|
||||||
case ModuleType.ZoomIt: return generalSettingsConfig.Enabled.ZoomIt;
|
|
||||||
case ModuleType.GeneralSettings: return generalSettingsConfig.EnableQuickAccess;
|
|
||||||
default: return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
internal static void SetIsModuleEnabled(GeneralSettings generalSettingsConfig, ModuleType moduleType, bool isEnabled)
|
|
||||||
{
|
|
||||||
switch (moduleType)
|
|
||||||
{
|
|
||||||
case ModuleType.AdvancedPaste: generalSettingsConfig.Enabled.AdvancedPaste = isEnabled; break;
|
|
||||||
case ModuleType.AlwaysOnTop: generalSettingsConfig.Enabled.AlwaysOnTop = isEnabled; break;
|
|
||||||
case ModuleType.Awake: generalSettingsConfig.Enabled.Awake = isEnabled; break;
|
|
||||||
case ModuleType.CmdPal: generalSettingsConfig.Enabled.CmdPal = isEnabled; break;
|
|
||||||
case ModuleType.ColorPicker: generalSettingsConfig.Enabled.ColorPicker = isEnabled; break;
|
|
||||||
case ModuleType.CropAndLock: generalSettingsConfig.Enabled.CropAndLock = isEnabled; break;
|
|
||||||
case ModuleType.CursorWrap: generalSettingsConfig.Enabled.CursorWrap = isEnabled; break;
|
|
||||||
case ModuleType.LightSwitch: generalSettingsConfig.Enabled.LightSwitch = isEnabled; break;
|
|
||||||
case ModuleType.EnvironmentVariables: generalSettingsConfig.Enabled.EnvironmentVariables = isEnabled; break;
|
|
||||||
case ModuleType.FancyZones: generalSettingsConfig.Enabled.FancyZones = isEnabled; break;
|
|
||||||
case ModuleType.FileLocksmith: generalSettingsConfig.Enabled.FileLocksmith = isEnabled; break;
|
|
||||||
case ModuleType.FindMyMouse: generalSettingsConfig.Enabled.FindMyMouse = isEnabled; break;
|
|
||||||
case ModuleType.Hosts: generalSettingsConfig.Enabled.Hosts = isEnabled; break;
|
|
||||||
case ModuleType.ImageResizer: generalSettingsConfig.Enabled.ImageResizer = isEnabled; break;
|
|
||||||
case ModuleType.KeyboardManager: generalSettingsConfig.Enabled.KeyboardManager = isEnabled; break;
|
|
||||||
case ModuleType.MouseHighlighter: generalSettingsConfig.Enabled.MouseHighlighter = isEnabled; break;
|
|
||||||
case ModuleType.MouseJump: generalSettingsConfig.Enabled.MouseJump = isEnabled; break;
|
|
||||||
case ModuleType.MousePointerCrosshairs: generalSettingsConfig.Enabled.MousePointerCrosshairs = isEnabled; break;
|
|
||||||
case ModuleType.MouseWithoutBorders: generalSettingsConfig.Enabled.MouseWithoutBorders = isEnabled; break;
|
|
||||||
case ModuleType.NewPlus: generalSettingsConfig.Enabled.NewPlus = isEnabled; break;
|
|
||||||
case ModuleType.Peek: generalSettingsConfig.Enabled.Peek = isEnabled; break;
|
|
||||||
case ModuleType.PowerRename: generalSettingsConfig.Enabled.PowerRename = isEnabled; break;
|
|
||||||
case ModuleType.PowerLauncher: generalSettingsConfig.Enabled.PowerLauncher = isEnabled; break;
|
|
||||||
case ModuleType.PowerAccent: generalSettingsConfig.Enabled.PowerAccent = isEnabled; break;
|
|
||||||
case ModuleType.Workspaces: generalSettingsConfig.Enabled.Workspaces = isEnabled; break;
|
|
||||||
case ModuleType.RegistryPreview: generalSettingsConfig.Enabled.RegistryPreview = isEnabled; break;
|
|
||||||
case ModuleType.MeasureTool: generalSettingsConfig.Enabled.MeasureTool = isEnabled; break;
|
|
||||||
case ModuleType.ShortcutGuide: generalSettingsConfig.Enabled.ShortcutGuide = isEnabled; break;
|
|
||||||
case ModuleType.PowerOCR: generalSettingsConfig.Enabled.PowerOcr = isEnabled; break;
|
|
||||||
case ModuleType.ZoomIt: generalSettingsConfig.Enabled.ZoomIt = isEnabled; break;
|
|
||||||
case ModuleType.GeneralSettings: generalSettingsConfig.EnableQuickAccess = isEnabled; break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static GpoRuleConfigured GetModuleGpoConfiguration(ModuleType moduleType)
|
|
||||||
{
|
|
||||||
switch (moduleType)
|
|
||||||
{
|
|
||||||
case ModuleType.AdvancedPaste: return GPOWrapper.GetConfiguredAdvancedPasteEnabledValue();
|
|
||||||
case ModuleType.AlwaysOnTop: return GPOWrapper.GetConfiguredAlwaysOnTopEnabledValue();
|
|
||||||
case ModuleType.Awake: return GPOWrapper.GetConfiguredAwakeEnabledValue();
|
|
||||||
case ModuleType.CmdPal: return GPOWrapper.GetConfiguredCmdPalEnabledValue();
|
|
||||||
case ModuleType.ColorPicker: return GPOWrapper.GetConfiguredColorPickerEnabledValue();
|
|
||||||
case ModuleType.CropAndLock: return GPOWrapper.GetConfiguredCropAndLockEnabledValue();
|
|
||||||
case ModuleType.CursorWrap: return GPOWrapper.GetConfiguredCursorWrapEnabledValue();
|
|
||||||
case ModuleType.EnvironmentVariables: return GPOWrapper.GetConfiguredEnvironmentVariablesEnabledValue();
|
|
||||||
case ModuleType.FancyZones: return GPOWrapper.GetConfiguredFancyZonesEnabledValue();
|
|
||||||
case ModuleType.FileLocksmith: return GPOWrapper.GetConfiguredFileLocksmithEnabledValue();
|
|
||||||
case ModuleType.FindMyMouse: return GPOWrapper.GetConfiguredFindMyMouseEnabledValue();
|
|
||||||
case ModuleType.Hosts: return GPOWrapper.GetConfiguredHostsFileEditorEnabledValue();
|
|
||||||
case ModuleType.ImageResizer: return GPOWrapper.GetConfiguredImageResizerEnabledValue();
|
|
||||||
case ModuleType.KeyboardManager: return GPOWrapper.GetConfiguredKeyboardManagerEnabledValue();
|
|
||||||
case ModuleType.MouseHighlighter: return GPOWrapper.GetConfiguredMouseHighlighterEnabledValue();
|
|
||||||
case ModuleType.MouseJump: return GPOWrapper.GetConfiguredMouseJumpEnabledValue();
|
|
||||||
case ModuleType.MousePointerCrosshairs: return GPOWrapper.GetConfiguredMousePointerCrosshairsEnabledValue();
|
|
||||||
case ModuleType.MouseWithoutBorders: return GPOWrapper.GetConfiguredMouseWithoutBordersEnabledValue();
|
|
||||||
case ModuleType.NewPlus: return GPOWrapper.GetConfiguredNewPlusEnabledValue();
|
|
||||||
case ModuleType.Peek: return GPOWrapper.GetConfiguredPeekEnabledValue();
|
|
||||||
case ModuleType.PowerRename: return GPOWrapper.GetConfiguredPowerRenameEnabledValue();
|
|
||||||
case ModuleType.PowerLauncher: return GPOWrapper.GetConfiguredPowerLauncherEnabledValue();
|
|
||||||
case ModuleType.PowerAccent: return GPOWrapper.GetConfiguredQuickAccentEnabledValue();
|
|
||||||
case ModuleType.Workspaces: return GPOWrapper.GetConfiguredWorkspacesEnabledValue();
|
|
||||||
case ModuleType.RegistryPreview: return GPOWrapper.GetConfiguredRegistryPreviewEnabledValue();
|
|
||||||
case ModuleType.MeasureTool: return GPOWrapper.GetConfiguredScreenRulerEnabledValue();
|
|
||||||
case ModuleType.ShortcutGuide: return GPOWrapper.GetConfiguredShortcutGuideEnabledValue();
|
|
||||||
case ModuleType.PowerOCR: return GPOWrapper.GetConfiguredTextExtractorEnabledValue();
|
|
||||||
case ModuleType.ZoomIt: return GPOWrapper.GetConfiguredZoomItEnabledValue();
|
|
||||||
default: return GpoRuleConfigured.Unavailable;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static System.Type GetModulePageType(ModuleType moduleType)
|
|
||||||
{
|
|
||||||
return moduleType switch
|
|
||||||
{
|
|
||||||
ModuleType.AdvancedPaste => typeof(AdvancedPastePage),
|
|
||||||
ModuleType.AlwaysOnTop => typeof(AlwaysOnTopPage),
|
|
||||||
ModuleType.Awake => typeof(AwakePage),
|
|
||||||
ModuleType.CmdPal => typeof(CmdPalPage),
|
|
||||||
ModuleType.ColorPicker => typeof(ColorPickerPage),
|
|
||||||
ModuleType.CropAndLock => typeof(CropAndLockPage),
|
|
||||||
ModuleType.CursorWrap => typeof(MouseUtilsPage),
|
|
||||||
ModuleType.LightSwitch => typeof(LightSwitchPage),
|
|
||||||
ModuleType.EnvironmentVariables => typeof(EnvironmentVariablesPage),
|
|
||||||
ModuleType.FancyZones => typeof(FancyZonesPage),
|
|
||||||
ModuleType.FileLocksmith => typeof(FileLocksmithPage),
|
|
||||||
ModuleType.FindMyMouse => typeof(MouseUtilsPage),
|
|
||||||
ModuleType.GeneralSettings => typeof(GeneralPage),
|
|
||||||
ModuleType.Hosts => typeof(HostsPage),
|
|
||||||
ModuleType.ImageResizer => typeof(ImageResizerPage),
|
|
||||||
ModuleType.KeyboardManager => typeof(KeyboardManagerPage),
|
|
||||||
ModuleType.MouseHighlighter => typeof(MouseUtilsPage),
|
|
||||||
ModuleType.MouseJump => typeof(MouseUtilsPage),
|
|
||||||
ModuleType.MousePointerCrosshairs => typeof(MouseUtilsPage),
|
|
||||||
ModuleType.MouseWithoutBorders => typeof(MouseWithoutBordersPage),
|
|
||||||
ModuleType.NewPlus => typeof(NewPlusPage),
|
|
||||||
ModuleType.Peek => typeof(PeekPage),
|
|
||||||
ModuleType.PowerRename => typeof(PowerRenamePage),
|
|
||||||
ModuleType.PowerLauncher => typeof(PowerLauncherPage),
|
|
||||||
ModuleType.PowerAccent => typeof(PowerAccentPage),
|
|
||||||
ModuleType.Workspaces => typeof(WorkspacesPage),
|
|
||||||
ModuleType.RegistryPreview => typeof(RegistryPreviewPage),
|
|
||||||
ModuleType.MeasureTool => typeof(MeasureToolPage),
|
|
||||||
ModuleType.ShortcutGuide => typeof(ShortcutGuidePage),
|
|
||||||
ModuleType.PowerOCR => typeof(PowerOcrPage),
|
|
||||||
ModuleType.ZoomIt => typeof(ZoomItPage),
|
|
||||||
_ => typeof(DashboardPage), // never called, all values listed above
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
122
src/settings-ui/Settings.UI/Services/DashboardLauncher.cs
Normal file
122
src/settings-ui/Settings.UI/Services/DashboardLauncher.cs
Normal file
@@ -0,0 +1,122 @@
|
|||||||
|
// 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.Threading;
|
||||||
|
using ManagedCommon;
|
||||||
|
using Microsoft.PowerToys.Settings.UI.Controls;
|
||||||
|
using Microsoft.PowerToys.Settings.UI.Library;
|
||||||
|
using PowerToys.Interop;
|
||||||
|
|
||||||
|
namespace Microsoft.PowerToys.Settings.UI.Services
|
||||||
|
{
|
||||||
|
public class DashboardLauncher : IQuickAccessLauncher
|
||||||
|
{
|
||||||
|
private readonly bool _isElevated;
|
||||||
|
|
||||||
|
public DashboardLauncher(bool isElevated)
|
||||||
|
{
|
||||||
|
_isElevated = isElevated;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Launch(ModuleType moduleType)
|
||||||
|
{
|
||||||
|
switch (moduleType)
|
||||||
|
{
|
||||||
|
case ModuleType.ColorPicker:
|
||||||
|
using (var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, Constants.ShowColorPickerSharedEvent()))
|
||||||
|
{
|
||||||
|
eventHandle.Set();
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
case ModuleType.EnvironmentVariables:
|
||||||
|
{
|
||||||
|
bool launchAdmin = SettingsRepository<EnvironmentVariablesSettings>.GetInstance(SettingsUtils.Default).SettingsConfig.Properties.LaunchAdministrator;
|
||||||
|
string eventName = !_isElevated && launchAdmin
|
||||||
|
? Constants.ShowEnvironmentVariablesAdminSharedEvent()
|
||||||
|
: Constants.ShowEnvironmentVariablesSharedEvent();
|
||||||
|
|
||||||
|
using (var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, eventName))
|
||||||
|
{
|
||||||
|
eventHandle.Set();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
case ModuleType.FancyZones:
|
||||||
|
using (var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, Constants.FZEToggleEvent()))
|
||||||
|
{
|
||||||
|
eventHandle.Set();
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
case ModuleType.Hosts:
|
||||||
|
{
|
||||||
|
bool launchAdmin = SettingsRepository<HostsSettings>.GetInstance(SettingsUtils.Default).SettingsConfig.Properties.LaunchAdministrator;
|
||||||
|
string eventName = !_isElevated && launchAdmin
|
||||||
|
? Constants.ShowHostsAdminSharedEvent()
|
||||||
|
: Constants.ShowHostsSharedEvent();
|
||||||
|
|
||||||
|
using (var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, eventName))
|
||||||
|
{
|
||||||
|
eventHandle.Set();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
case ModuleType.PowerLauncher:
|
||||||
|
using (var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, Constants.PowerLauncherSharedEvent()))
|
||||||
|
{
|
||||||
|
eventHandle.Set();
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
case ModuleType.PowerOCR:
|
||||||
|
using (var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, Constants.ShowPowerOCRSharedEvent()))
|
||||||
|
{
|
||||||
|
eventHandle.Set();
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
case ModuleType.RegistryPreview:
|
||||||
|
using (var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, Constants.RegistryPreviewTriggerEvent()))
|
||||||
|
{
|
||||||
|
eventHandle.Set();
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
case ModuleType.MeasureTool:
|
||||||
|
using (var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, Constants.MeasureToolTriggerEvent()))
|
||||||
|
{
|
||||||
|
eventHandle.Set();
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
case ModuleType.ShortcutGuide:
|
||||||
|
using (var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, Constants.ShortcutGuideTriggerEvent()))
|
||||||
|
{
|
||||||
|
eventHandle.Set();
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
case ModuleType.CmdPal:
|
||||||
|
using (var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, Constants.ShowCmdPalEvent()))
|
||||||
|
{
|
||||||
|
eventHandle.Set();
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
case ModuleType.Workspaces:
|
||||||
|
using (var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, Constants.WorkspacesLaunchEditorEvent()))
|
||||||
|
{
|
||||||
|
eventHandle.Set();
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -71,7 +71,7 @@ namespace Microsoft.PowerToys.Settings.UI.SettingsXAML.Controls.Dashboard
|
|||||||
settingsCard.DataContext is ModuleHotkeyData moduleData)
|
settingsCard.DataContext is ModuleHotkeyData moduleData)
|
||||||
{
|
{
|
||||||
var moduleType = moduleData.ModuleType;
|
var moduleType = moduleData.ModuleType;
|
||||||
NavigationService.Navigate(ModuleHelper.GetModulePageType(moduleType));
|
NavigationService.Navigate(ModuleGpoHelper.GetModulePageType(moduleType));
|
||||||
this.Close();
|
this.Close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ using ManagedCommon;
|
|||||||
using Microsoft.PowerLauncher.Telemetry;
|
using Microsoft.PowerLauncher.Telemetry;
|
||||||
using Microsoft.PowerToys.Settings.UI.Helpers;
|
using Microsoft.PowerToys.Settings.UI.Helpers;
|
||||||
using Microsoft.PowerToys.Settings.UI.Library;
|
using Microsoft.PowerToys.Settings.UI.Library;
|
||||||
|
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
|
||||||
using Microsoft.PowerToys.Settings.UI.Views;
|
using Microsoft.PowerToys.Settings.UI.Views;
|
||||||
using Microsoft.PowerToys.Telemetry;
|
using Microsoft.PowerToys.Telemetry;
|
||||||
using Microsoft.UI;
|
using Microsoft.UI;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) Microsoft Corporation
|
// Copyright (c) Microsoft Corporation
|
||||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||||
// See the LICENSE file in the project root for more information.
|
// See the LICENSE file in the project root for more information.
|
||||||
|
|
||||||
@@ -41,7 +41,9 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
|||||||
|
|
||||||
public ObservableCollection<DashboardListItem> ActionModules { get; set; } = new ObservableCollection<DashboardListItem>();
|
public ObservableCollection<DashboardListItem> ActionModules { get; set; } = new ObservableCollection<DashboardListItem>();
|
||||||
|
|
||||||
public ObservableCollection<QuickAccessItem> QuickAccessItems { get; set; } = new ObservableCollection<QuickAccessItem>();
|
public ObservableCollection<QuickAccessItem> QuickAccessItems => _quickAccessViewModel.Items;
|
||||||
|
|
||||||
|
private readonly QuickAccessViewModel _quickAccessViewModel;
|
||||||
|
|
||||||
// Master list of module items that is sorted and projected into AllModules.
|
// Master list of module items that is sorted and projected into AllModules.
|
||||||
private List<DashboardListItem> _moduleItems = new List<DashboardListItem>();
|
private List<DashboardListItem> _moduleItems = new List<DashboardListItem>();
|
||||||
@@ -111,6 +113,12 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
|||||||
// set the callback functions value to handle outgoing IPC message.
|
// set the callback functions value to handle outgoing IPC message.
|
||||||
SendConfigMSG = ipcMSGCallBackFunc;
|
SendConfigMSG = ipcMSGCallBackFunc;
|
||||||
|
|
||||||
|
_quickAccessViewModel = new QuickAccessViewModel(
|
||||||
|
_settingsRepository,
|
||||||
|
new DashboardLauncher(App.IsElevated),
|
||||||
|
moduleType => Helpers.ModuleGpoHelper.GetModuleGpoConfiguration(moduleType) == global::PowerToys.GPOWrapper.GpoRuleConfigured.Disabled,
|
||||||
|
resourceLoader);
|
||||||
|
|
||||||
BuildModuleList();
|
BuildModuleList();
|
||||||
SortModuleList();
|
SortModuleList();
|
||||||
RefreshShortcutModules();
|
RefreshShortcutModules();
|
||||||
@@ -170,7 +178,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
GpoRuleConfigured gpo = ModuleHelper.GetModuleGpoConfiguration(moduleType);
|
GpoRuleConfigured gpo = ModuleGpoHelper.GetModuleGpoConfiguration(moduleType);
|
||||||
var newItem = new DashboardListItem()
|
var newItem = new DashboardListItem()
|
||||||
{
|
{
|
||||||
Tag = moduleType,
|
Tag = moduleType,
|
||||||
@@ -236,7 +244,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
|||||||
{
|
{
|
||||||
foreach (var item in _moduleItems)
|
foreach (var item in _moduleItems)
|
||||||
{
|
{
|
||||||
GpoRuleConfigured gpo = ModuleHelper.GetModuleGpoConfiguration(item.Tag);
|
GpoRuleConfigured gpo = ModuleGpoHelper.GetModuleGpoConfiguration(item.Tag);
|
||||||
|
|
||||||
// GPO can force-enable (Enabled) or force-disable (Disabled) a module.
|
// GPO can force-enable (Enabled) or force-disable (Disabled) a module.
|
||||||
// If Enabled: module is on and the user cannot disable it.
|
// If Enabled: module is on and the user cannot disable it.
|
||||||
@@ -346,7 +354,6 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
|||||||
{
|
{
|
||||||
ShortcutModules.Clear();
|
ShortcutModules.Clear();
|
||||||
ActionModules.Clear();
|
ActionModules.Clear();
|
||||||
QuickAccessItems.Clear();
|
|
||||||
|
|
||||||
foreach (var x in AllModules.Where(x => x.IsEnabled))
|
foreach (var x in AllModules.Where(x => x.IsEnabled))
|
||||||
{
|
{
|
||||||
@@ -391,18 +398,6 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
|||||||
|
|
||||||
ActionModules.Add(newItem);
|
ActionModules.Add(newItem);
|
||||||
newItem.EnabledChangedCallback = x.EnabledChangedCallback;
|
newItem.EnabledChangedCallback = x.EnabledChangedCallback;
|
||||||
|
|
||||||
foreach (DashboardModuleButtonItem item in filteredItems)
|
|
||||||
{
|
|
||||||
QuickAccessItems.Add(new QuickAccessItem
|
|
||||||
{
|
|
||||||
Title = item.ButtonTitle,
|
|
||||||
Description = item.ButtonDescription,
|
|
||||||
Icon = item.ButtonGlyph,
|
|
||||||
Command = new RelayCommand(() => item.ButtonClickHandler?.Invoke(null, null)),
|
|
||||||
Tag = x.Tag,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -744,7 +739,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
|||||||
{
|
{
|
||||||
if (sender is ModuleType moduleType)
|
if (sender is ModuleType moduleType)
|
||||||
{
|
{
|
||||||
NavigationService.Navigate(ModuleHelper.GetModulePageType(moduleType));
|
NavigationService.Navigate(ModuleGpoHelper.GetModulePageType(moduleType));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ using System.Windows.Threading;
|
|||||||
using ManagedCommon;
|
using ManagedCommon;
|
||||||
using Microsoft.PowerToys.Settings.UI.Helpers;
|
using Microsoft.PowerToys.Settings.UI.Helpers;
|
||||||
using Microsoft.PowerToys.Settings.UI.Library;
|
using Microsoft.PowerToys.Settings.UI.Library;
|
||||||
|
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
|
||||||
using Microsoft.PowerToys.Settings.UI.Library.HotkeyConflicts;
|
using Microsoft.PowerToys.Settings.UI.Library.HotkeyConflicts;
|
||||||
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
|
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
|
||||||
using Microsoft.PowerToys.Settings.UI.SerializationContext;
|
using Microsoft.PowerToys.Settings.UI.SerializationContext;
|
||||||
|
|||||||
Reference in New Issue
Block a user