Settings Flyout improvement (#43840)

<!-- Enter a brief description/summary of your PR here. What does it
fix/what does it change/how was it tested (even manually, if necessary)?
-->
## Summary of the Pull Request
This pull request introduces the new Quick Access feature to PowerToys
by integrating its host process management into the runner and system
tray. The changes add the Quick Access host implementation, update
project and build files to include it, and modify the runner and tray
icon logic to launch and interact with the Quick Access UI.

<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist

- [x] Closes: #43694
<!-- - [ ] Closes: #yyy (add separate lines for additional resolved
issues) -->
- [x] **Communication:** I've discussed this with core contributors
already. If the work hasn't been agreed, this work might be rejected
- [x] **Tests:** Added/updated and all pass
- [ ] **Localization:** All end-user-facing strings can be localized
- [ ] **Dev docs:** Added/updated
- [ ] **New binaries:** Added on the required places
- [ ] [JSON for
signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json)
for new binaries
- [ ] [WXS for
installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs)
for new binaries and localization folder
- [ ] [YML for CI
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml)
for new test projects
- [ ] [YML for signed
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml)
- [ ] **Documentation updated:** If checked, please file a pull request
on [our docs
repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys)
and link it here: #xxx

<!-- Provide a more detailed description of the PR, other things fixed,
or any additional comments/features here -->
## Detailed Description of the Pull Request / Additional comments
<img width="290" height="420" alt="image"
src="https://github.com/user-attachments/assets/7390a706-171c-479f-a4a2-999b18cfc65f"
/>

<img width="290" height="420" alt="image"
src="https://github.com/user-attachments/assets/99e99bc9-b1a3-46c6-b648-81e3048dec1b"
/>

<img width="490" height="350" alt="image"
src="https://github.com/user-attachments/assets/2cce4ad6-a54e-4587-87b7-fdc7fba1f54f"
/>

<!-- Describe how you validated the behavior. Add automated tests
wherever possible, but list manual validation steps taken as well -->
## Validation Steps Performed

---------

Signed-off-by: Shawn Yuan (from Dev Box) <shuaiyuan@microsoft.com>
Signed-off-by: Shuai Yuan <shuai.yuan.zju@gmail.com>
Co-authored-by: Niels Laute <niels.laute@live.nl>
This commit is contained in:
Shawn Yuan
2026-01-07 16:38:09 +08:00
committed by GitHub
parent 19c9b4e1fd
commit 9086995eeb
89 changed files with 3916 additions and 1388 deletions

View File

@@ -8,44 +8,39 @@ using System.ComponentModel;
using System.Runtime.CompilerServices;
using ManagedCommon;
using Microsoft.PowerToys.Settings.UI.Controls;
using Microsoft.UI;
using Windows.UI;
namespace Microsoft.PowerToys.Settings.UI.ViewModels
{
public partial class DashboardListItem : INotifyPropertyChanged
public partial class DashboardListItem : ModuleListItem
{
private bool _visible;
private bool _isEnabled;
public string Label { get; set; }
public bool IsNew { get; set; }
public string Icon { get; set; }
public string ToolTip { get; set; }
public ModuleType Tag { get; set; }
public bool IsLocked { get; set; }
public bool IsEnabled
public new ModuleType Tag
{
get => _isEnabled;
get => (ModuleType)base.Tag!;
set => base.Tag = value;
}
public Action<DashboardListItem> EnabledChangedCallback { get; set; }
public override bool IsEnabled
{
get => base.IsEnabled;
set
{
if (_isEnabled != value)
if (base.IsEnabled != value)
{
_isEnabled = value;
OnPropertyChanged();
base.IsEnabled = value;
EnabledChangedCallback?.Invoke(this);
}
}
}
public Action<DashboardListItem> EnabledChangedCallback { get; set; }
public bool Visible
{
get => _visible;
@@ -59,13 +54,6 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
public ObservableCollection<DashboardModuleItem> DashboardModuleItems { get; set; } = new ObservableCollection<DashboardModuleItem>();
}
}

View File

@@ -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,6 +12,7 @@ using System.Windows.Threading;
using CommunityToolkit.WinUI.Controls;
using global::PowerToys.GPOWrapper;
using ManagedCommon;
using Microsoft.PowerToys.Settings.UI.Controls;
using Microsoft.PowerToys.Settings.UI.Helpers;
using Microsoft.PowerToys.Settings.UI.Library;
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
@@ -40,11 +41,16 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
public ObservableCollection<DashboardListItem> ActionModules { get; set; } = new ObservableCollection<DashboardListItem>();
public ObservableCollection<QuickAccessItem> QuickAccessItems => _quickAccessViewModel.Items;
private readonly QuickAccessViewModel _quickAccessViewModel;
// Master list of module items that is sorted and projected into AllModules.
private List<DashboardListItem> _moduleItems = new List<DashboardListItem>();
// Flag to prevent circular updates when a UI toggle triggers settings changes.
private bool _isUpdatingFromUI;
private bool _isUpdatingFromSettings;
private AllHotkeyConflictsData _allHotkeyConflictsData = new AllHotkeyConflictsData();
@@ -79,6 +85,10 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
{
generalSettingsConfig.DashboardSortOrder = value;
OutGoingGeneralSettings outgoing = new OutGoingGeneralSettings(generalSettingsConfig);
// Save settings to file
SettingsUtils.Default.SaveSettings(generalSettingsConfig.ToJsonString());
SendConfigMSG(outgoing.ToString());
SortModuleList();
}
@@ -95,6 +105,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
_settingsRepository = settingsRepository;
generalSettingsConfig = settingsRepository.SettingsConfig;
generalSettingsConfig.AddEnabledModuleChangeNotification(ModuleEnabledChangedOnSettingsPage);
_settingsRepository.SettingsChanged += OnSettingsChanged;
// Initialize dashboard sort order from settings
_dashboardSortOrder = generalSettingsConfig.DashboardSortOrder;
@@ -102,11 +113,27 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
// set the callback functions value to handle outgoing IPC message.
SendConfigMSG = ipcMSGCallBackFunc;
_quickAccessViewModel = new QuickAccessViewModel(
_settingsRepository,
new Microsoft.PowerToys.Settings.UI.Controls.QuickAccessLauncher(App.IsElevated),
moduleType => Helpers.ModuleGpoHelper.GetModuleGpoConfiguration(moduleType) == global::PowerToys.GPOWrapper.GpoRuleConfigured.Disabled,
resourceLoader);
BuildModuleList();
SortModuleList();
RefreshShortcutModules();
}
private void OnSettingsChanged(GeneralSettings newSettings)
{
dispatcher.BeginInvoke(() =>
{
generalSettingsConfig = newSettings;
generalSettingsConfig.AddEnabledModuleChangeNotification(ModuleEnabledChangedOnSettingsPage);
ModuleEnabledChangedOnSettingsPage();
});
}
protected override void OnConflictsUpdated(object sender, AllHotkeyConflictsEventArgs e)
{
dispatcher.BeginInvoke(() =>
@@ -146,7 +173,12 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
foreach (ModuleType moduleType in Enum.GetValues<ModuleType>())
{
GpoRuleConfigured gpo = ModuleHelper.GetModuleGpoConfiguration(moduleType);
if (moduleType == ModuleType.GeneralSettings)
{
continue;
}
GpoRuleConfigured gpo = ModuleGpoHelper.GetModuleGpoConfiguration(moduleType);
var newItem = new DashboardListItem()
{
Tag = moduleType,
@@ -156,6 +188,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
Icon = ModuleHelper.GetModuleTypeFluentIconName(moduleType),
IsNew = moduleType == ModuleType.CursorWrap,
DashboardModuleItems = GetModuleItems(moduleType),
ClickCommand = new RelayCommand<object>(DashboardListItemClick),
};
newItem.EnabledChangedCallback = EnabledChangedOnUI;
_moduleItems.Add(newItem);
@@ -211,7 +244,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
{
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.
// If Enabled: module is on and the user cannot disable it.
@@ -244,6 +277,11 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
/// </summary>
private void EnabledChangedOnUI(DashboardListItem dashboardListItem)
{
if (_isUpdatingFromSettings)
{
return;
}
_isUpdatingFromUI = true;
try
{
@@ -287,6 +325,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
return;
}
_isUpdatingFromSettings = true;
try
{
RefreshModuleList();
@@ -301,6 +340,10 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
{
Logger.LogError($"Updating active/disabled modules list failed: {ex.Message}");
}
finally
{
_isUpdatingFromSettings = false;
}
}
/// <summary>
@@ -695,10 +738,21 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
internal void DashboardListItemClick(object sender)
{
if (sender is SettingsCard card && card.Tag is ModuleType moduleType)
if (sender is ModuleType moduleType)
{
NavigationService.Navigate(ModuleHelper.GetModulePageType(moduleType));
NavigationService.Navigate(ModuleGpoHelper.GetModulePageType(moduleType));
}
}
public override void Dispose()
{
base.Dispose();
if (_settingsRepository != null)
{
_settingsRepository.SettingsChanged -= OnSettingsChanged;
}
GC.SuppressFinalize(this);
}
}
}

View File

@@ -1,78 +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 System;
using System.Collections.ObjectModel;
using global::PowerToys.GPOWrapper;
using ManagedCommon;
using Microsoft.PowerToys.Settings.UI.Helpers;
using Microsoft.PowerToys.Settings.UI.Library;
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
using Microsoft.Windows.ApplicationModel.Resources;
namespace Microsoft.PowerToys.Settings.UI.ViewModels
{
public partial class AllAppsViewModel : Observable
{
public ObservableCollection<FlyoutMenuItem> FlyoutMenuItems { get; set; }
private ISettingsRepository<GeneralSettings> _settingsRepository;
private GeneralSettings generalSettingsConfig;
private ResourceLoader resourceLoader;
private Func<string, int> SendConfigMSG { get; }
public AllAppsViewModel(ISettingsRepository<GeneralSettings> settingsRepository, Func<string, int> ipcMSGCallBackFunc)
{
_settingsRepository = settingsRepository;
generalSettingsConfig = settingsRepository.SettingsConfig;
generalSettingsConfig.AddEnabledModuleChangeNotification(ModuleEnabledChangedOnSettingsPage);
resourceLoader = Helpers.ResourceLoaderInstance.ResourceLoader;
FlyoutMenuItems = new ObservableCollection<FlyoutMenuItem>();
foreach (ModuleType moduleType in Enum.GetValues<ModuleType>())
{
AddFlyoutMenuItem(moduleType);
}
// set the callback functions value to handle outgoing IPC message.
SendConfigMSG = ipcMSGCallBackFunc;
}
private void AddFlyoutMenuItem(ModuleType moduleType)
{
GpoRuleConfigured gpo = ModuleHelper.GetModuleGpoConfiguration(moduleType);
FlyoutMenuItems.Add(new FlyoutMenuItem()
{
Label = resourceLoader.GetString(ModuleHelper.GetModuleLabelResourceName(moduleType)),
IsEnabled = gpo == GpoRuleConfigured.Enabled || (gpo != GpoRuleConfigured.Disabled && ModuleHelper.GetIsModuleEnabled(generalSettingsConfig, moduleType)),
IsLocked = gpo == GpoRuleConfigured.Enabled || gpo == GpoRuleConfigured.Disabled,
Tag = moduleType,
Icon = ModuleHelper.GetModuleTypeFluentIconName(moduleType),
EnabledChangedCallback = EnabledChangedOnUI,
});
}
private void EnabledChangedOnUI(FlyoutMenuItem flyoutMenuItem)
{
if (Views.ShellPage.UpdateGeneralSettingsCallback(flyoutMenuItem.Tag, flyoutMenuItem.IsEnabled))
{
Views.ShellPage.DisableFlyoutHidingCallback();
}
}
private void ModuleEnabledChangedOnSettingsPage()
{
generalSettingsConfig = _settingsRepository.SettingsConfig;
generalSettingsConfig.AddEnabledModuleChangeNotification(ModuleEnabledChangedOnSettingsPage);
foreach (FlyoutMenuItem item in FlyoutMenuItems)
{
item.IsEnabled = ModuleHelper.GetIsModuleEnabled(generalSettingsConfig, item.Tag);
}
}
}
}

View File

@@ -1,64 +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 System;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using ManagedCommon;
namespace Microsoft.PowerToys.Settings.UI.ViewModels
{
public partial class FlyoutMenuItem : INotifyPropertyChanged
{
private bool _visible;
private bool _isEnabled;
public string Label { get; set; }
public string Icon { get; set; }
public string ToolTip { get; set; }
public ModuleType Tag { get; set; }
public bool IsLocked { get; set; }
public bool IsEnabled
{
get => _isEnabled;
set
{
if (_isEnabled != value)
{
_isEnabled = value;
OnPropertyChanged();
EnabledChangedCallback?.Invoke(this);
}
}
}
public Action<FlyoutMenuItem> EnabledChangedCallback { get; set; }
public bool Visible
{
get => _visible;
set
{
if (_visible != value)
{
_visible = value;
OnPropertyChanged();
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}

View File

@@ -1,57 +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 System;
using System.Timers;
namespace Microsoft.PowerToys.Settings.UI.ViewModels.Flyout
{
public partial class FlyoutViewModel : IDisposable
{
private Timer _hideTimer;
private bool _disposed;
public bool CanHide { get; set; }
public FlyoutViewModel()
{
CanHide = true;
_hideTimer = new Timer();
_hideTimer.Elapsed += HideTimer_Elapsed;
_hideTimer.Interval = 1000;
_hideTimer.Enabled = false;
}
private void HideTimer_Elapsed(object sender, ElapsedEventArgs e)
{
CanHide = true;
_hideTimer.Stop();
}
internal void DisableHiding()
{
CanHide = false;
_hideTimer.Stop();
_hideTimer.Start();
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if (!_disposed)
{
if (disposing)
{
_hideTimer?.Dispose();
_disposed = true;
}
}
}
}
}

View File

@@ -1,130 +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 System;
using System.Collections.ObjectModel;
using global::PowerToys.GPOWrapper;
using ManagedCommon;
using Microsoft.PowerToys.Settings.UI.Helpers;
using Microsoft.PowerToys.Settings.UI.Library;
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
using Microsoft.Windows.ApplicationModel.Resources;
namespace Microsoft.PowerToys.Settings.UI.ViewModels
{
public partial class LauncherViewModel : Observable
{
public bool IsUpdateAvailable { get; set; }
public ObservableCollection<FlyoutMenuItem> FlyoutMenuItems { get; set; }
private GeneralSettings generalSettingsConfig;
private UpdatingSettings updatingSettingsConfig;
private ISettingsRepository<GeneralSettings> _settingsRepository;
private ResourceLoader resourceLoader;
private Func<string, int> SendIPCMessage { get; }
public LauncherViewModel(ISettingsRepository<GeneralSettings> settingsRepository, Func<string, int> ipcMSGCallBackFunc)
{
_settingsRepository = settingsRepository;
generalSettingsConfig = settingsRepository.SettingsConfig;
generalSettingsConfig.AddEnabledModuleChangeNotification(ModuleEnabledChanged);
// set the callback functions value to handle outgoing IPC message.
SendIPCMessage = ipcMSGCallBackFunc;
resourceLoader = ResourceLoaderInstance.ResourceLoader;
FlyoutMenuItems = new ObservableCollection<FlyoutMenuItem>();
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);
updatingSettingsConfig = UpdatingSettings.LoadSettings();
if (updatingSettingsConfig == null)
{
updatingSettingsConfig = new UpdatingSettings();
}
if (updatingSettingsConfig.State == UpdatingSettings.UpdatingState.ReadyToInstall || updatingSettingsConfig.State == UpdatingSettings.UpdatingState.ReadyToDownload)
{
IsUpdateAvailable = true;
}
else
{
IsUpdateAvailable = false;
}
}
private void AddFlyoutMenuItem(ModuleType moduleType)
{
if (ModuleHelper.GetModuleGpoConfiguration(moduleType) == GpoRuleConfigured.Disabled)
{
return;
}
FlyoutMenuItems.Add(new FlyoutMenuItem()
{
Label = resourceLoader.GetString(ModuleHelper.GetModuleLabelResourceName(moduleType)),
Tag = moduleType,
Visible = ModuleHelper.GetIsModuleEnabled(generalSettingsConfig, moduleType),
ToolTip = GetModuleToolTip(moduleType),
Icon = ModuleHelper.GetModuleTypeFluentIconName(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 void ModuleEnabledChanged()
{
generalSettingsConfig = _settingsRepository.SettingsConfig;
generalSettingsConfig.AddEnabledModuleChangeNotification(ModuleEnabledChanged);
foreach (FlyoutMenuItem item in FlyoutMenuItems)
{
item.Visible = ModuleHelper.GetIsModuleEnabled(generalSettingsConfig, item.Tag);
}
}
private string GetShortcutGuideToolTip()
{
var shortcutGuideSettings = SettingsRepository<ShortcutGuideSettings>.GetInstance(SettingsUtils.Default).SettingsConfig;
return shortcutGuideSettings.Properties.UseLegacyPressWinKeyBehavior.Value
? "Win"
: shortcutGuideSettings.Properties.OpenShortcutGuide.ToString();
}
internal void StartBugReport()
{
SendIPCMessage("{\"bugreport\": 0 }");
}
internal void KillRunner()
{
SendIPCMessage("{\"killrunner\": 0 }");
}
}
}

View File

@@ -31,7 +31,7 @@ using Windows.System.Profile;
namespace Microsoft.PowerToys.Settings.UI.ViewModels
{
public partial class GeneralViewModel : Observable
public partial class GeneralViewModel : PageViewModelBase
{
public enum InstallScope
{
@@ -39,6 +39,16 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
PerUser,
}
protected override string ModuleName => "GeneralSettings";
public override Dictionary<string, HotkeySettings[]> GetAllHotkeySettings()
{
return new Dictionary<string, HotkeySettings[]>
{
{ ModuleName, new HotkeySettings[] { QuickAccessShortcut } },
};
}
private GeneralSettings GeneralSettingsConfig { get; set; }
private UpdatingSettings UpdatingSettingsConfig { get; set; }
@@ -75,6 +85,9 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
private string _settingsConfigFileFolder = string.Empty;
private ISettingsRepository<GeneralSettings> _settingsRepository;
private Microsoft.UI.Dispatching.DispatcherQueue _dispatcherQueue;
private IFileSystemWatcher _fileWatcher;
private Func<Task<string>> PickSingleFolderDialog { get; }
@@ -100,6 +113,10 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
// To obtain the general settings configuration of PowerToys if it exists, else to create a new file and return the default configurations.
ArgumentNullException.ThrowIfNull(settingsRepository);
_settingsRepository = settingsRepository;
_settingsRepository.SettingsChanged += OnSettingsChanged;
_dispatcherQueue = GetDispatcherQueue();
GeneralSettingsConfig = settingsRepository.SettingsConfig;
UpdatingSettingsConfig = UpdatingSettings.LoadSettings();
if (UpdatingSettingsConfig == null)
@@ -155,6 +172,12 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
_isElevated = isElevated;
_runElevated = GeneralSettingsConfig.RunElevated;
_enableWarningsElevatedApps = GeneralSettingsConfig.EnableWarningsElevatedApps;
_enableQuickAccess = GeneralSettingsConfig.EnableQuickAccess;
_quickAccessShortcut = GeneralSettingsConfig.QuickAccessShortcut;
if (_quickAccessShortcut != null)
{
_quickAccessShortcut.PropertyChanged += QuickAccessShortcut_PropertyChanged;
}
RunningAsUserDefaultText = runAsUserText;
RunningAsAdminDefaultText = runAsAdminText;
@@ -236,6 +259,8 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
private bool _runElevated;
private bool _isAdmin;
private bool _enableWarningsElevatedApps;
private bool _enableQuickAccess;
private HotkeySettings _quickAccessShortcut;
private int _themeIndex;
private bool _showNewUpdatesToastNotification;
@@ -480,6 +505,57 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
}
}
public bool EnableQuickAccess
{
get
{
return _enableQuickAccess;
}
set
{
if (_enableQuickAccess != value)
{
_enableQuickAccess = value;
GeneralSettingsConfig.EnableQuickAccess = value;
NotifyPropertyChanged();
}
}
}
public HotkeySettings QuickAccessShortcut
{
get
{
return _quickAccessShortcut;
}
set
{
if (_quickAccessShortcut != value)
{
if (_quickAccessShortcut != null)
{
_quickAccessShortcut.PropertyChanged -= QuickAccessShortcut_PropertyChanged;
}
_quickAccessShortcut = value;
if (_quickAccessShortcut != null)
{
_quickAccessShortcut.PropertyChanged += QuickAccessShortcut_PropertyChanged;
}
GeneralSettingsConfig.QuickAccessShortcut = value;
NotifyPropertyChanged();
}
}
}
private void QuickAccessShortcut_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
NotifyPropertyChanged(nameof(QuickAccessShortcut));
}
public bool SomeUpdateSettingsAreGpoManaged
{
get
@@ -1434,5 +1510,35 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
Process.Start("explorer.exe", etwDirPath);
}
}
private void OnSettingsChanged(GeneralSettings newSettings)
{
_dispatcherQueue?.TryEnqueue(() =>
{
GeneralSettingsConfig = newSettings;
if (_enableQuickAccess != newSettings.EnableQuickAccess)
{
_enableQuickAccess = newSettings.EnableQuickAccess;
OnPropertyChanged(nameof(EnableQuickAccess));
}
});
}
public override void Dispose()
{
base.Dispose();
if (_settingsRepository != null)
{
_settingsRepository.SettingsChanged -= OnSettingsChanged;
}
GC.SuppressFinalize(this);
}
protected virtual Microsoft.UI.Dispatching.DispatcherQueue GetDispatcherQueue()
{
return Microsoft.UI.Dispatching.DispatcherQueue.GetForCurrentThread();
}
}
}

View File

@@ -16,6 +16,7 @@ using System.Windows.Threading;
using ManagedCommon;
using Microsoft.PowerToys.Settings.UI.Helpers;
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.Interfaces;
using Microsoft.PowerToys.Settings.UI.SerializationContext;
@@ -253,6 +254,9 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
// Send IPC notification using the same format as other ViewModels
SendConfigMSG(settingsConfig, moduleName);
// Request updated conflicts after changing a hotkey
GlobalHotkeyConflictManager.Instance?.RequestAllConflicts();
}
}
catch (Exception ex)
@@ -273,11 +277,22 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
? JsonSerializer.Serialize(settingsConfig, jsonTypeInfo)
: JsonSerializer.Serialize(settingsConfig);
var ipcMessage = string.Format(
CultureInfo.InvariantCulture,
"{{ \"powertoys\": {{ \"{0}\": {1} }} }}",
moduleName,
serializedSettings);
string ipcMessage;
if (string.Equals(moduleName, "GeneralSettings", StringComparison.OrdinalIgnoreCase))
{
ipcMessage = string.Format(
CultureInfo.InvariantCulture,
"{{ \"general\": {0} }}",
serializedSettings);
}
else
{
ipcMessage = string.Format(
CultureInfo.InvariantCulture,
"{{ \"powertoys\": {{ \"{0}\": {1} }} }}",
moduleName,
serializedSettings);
}
var result = _ipcMSGCallBackFunc(ipcMessage);
System.Diagnostics.Debug.WriteLine($"Sent IPC notification for {moduleName}, result: {result}");