[settings] Show uneditable shortcut in CmdPal page (#38060)

* [settings] Show CmdPal shortcut
* show in dashboard as well


![image](https://github.com/user-attachments/assets/395d112d-162c-412c-99c2-2625b23cc451)

![image](https://github.com/user-attachments/assets/a0362e2b-e647-4a19-b4ff-fdb501e236d7)

As noted in #37908
This commit is contained in:
Stefan Markovic
2025-03-20 16:20:19 +01:00
committed by GitHub
parent dadd306555
commit 665e957cde
7 changed files with 149 additions and 3 deletions

View File

@@ -4,15 +4,19 @@
using System;
using System.IO;
using System.IO.Abstractions;
using System.Linq;
using System.Reflection;
using System.Text.Json;
using System.Text.RegularExpressions;
using global::PowerToys.GPOWrapper;
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.Utilities;
using Microsoft.PowerToys.Settings.UI.ViewModels.Commands;
using Microsoft.UI.Dispatching;
using Windows.Management.Deployment;
namespace Microsoft.PowerToys.Settings.UI.ViewModels
@@ -21,12 +25,16 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
{
private GpoRuleConfigured _enabledGpoRuleConfiguration;
private bool _isEnabled;
private HotkeySettings _hotkey;
private IFileSystemWatcher _watcher;
private DispatcherQueue _uiDispatcherQueue;
private CmdPalProperties _cmdPalProperties;
private GeneralSettings GeneralSettingsConfig { get; set; }
private Func<string, int> SendConfigMSG { get; }
public CmdPalViewModel(ISettingsUtils settingsUtils, ISettingsRepository<GeneralSettings> settingsRepository, Func<string, int> ipcMSGCallBackFunc)
public CmdPalViewModel(ISettingsUtils settingsUtils, ISettingsRepository<GeneralSettings> settingsRepository, Func<string, int> ipcMSGCallBackFunc, DispatcherQueue uiDispatcherQueue)
{
ArgumentNullException.ThrowIfNull(settingsUtils);
@@ -35,8 +43,32 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
GeneralSettingsConfig = settingsRepository.SettingsConfig;
_uiDispatcherQueue = uiDispatcherQueue;
_cmdPalProperties = new CmdPalProperties();
InitializeEnabledValue();
var localAppDataDir = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
#if DEBUG
var settingsPath = Path.Combine(localAppDataDir, "Packages", "Microsoft.CommandPalette.Dev_8wekyb3d8bbwe", "LocalState", "settings.json");
#else
var settingsPath = Path.Combine(localAppDataDir, "Packages", "Microsoft.CommandPalette_8wekyb3d8bbwe", "LocalState", "settings.json");
#endif
_hotkey = _cmdPalProperties.Hotkey;
_watcher = Helper.GetFileWatcher(settingsPath, () =>
{
_cmdPalProperties.InitializeHotkey();
_hotkey = _cmdPalProperties.Hotkey;
_uiDispatcherQueue.TryEnqueue(() =>
{
OnPropertyChanged(nameof(Hotkey));
});
});
// set the callback functions value to handle outgoing IPC message.
SendConfigMSG = ipcMSGCallBackFunc;
}
@@ -82,6 +114,15 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
}
}
public HotkeySettings Hotkey
{
get => _hotkey;
private set
{
}
}
public bool IsEnabledGpoConfigured { get; private set; }
public void RefreshEnabledState()