-
Notifications
You must be signed in to change notification settings - Fork 7.6k
[settings] Show uneditable shortcut in CmdPal page #38060
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| // 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.IO; | ||
| using System.IO.Abstractions; | ||
| using System.Text.Json; | ||
| using System.Text.Json.Serialization; | ||
|
|
||
| namespace Microsoft.PowerToys.Settings.UI.Library | ||
| { | ||
| public class CmdPalProperties | ||
| { | ||
| // Default shortcut - Win + Alt + Space | ||
| public static readonly HotkeySettings DefaultHotkeyValue = new HotkeySettings(true, false, true, false, 32); | ||
|
|
||
| #pragma warning disable SA1401 // Fields should be private | ||
| #pragma warning disable CA1051 // Do not declare visible instance fields | ||
| public HotkeySettings Hotkey; | ||
| #pragma warning restore CA1051 // Do not declare visible instance fields | ||
| #pragma warning restore SA1401 // Fields should be private | ||
|
|
||
| private string _settingsFilePath; | ||
|
|
||
| public CmdPalProperties() | ||
| { | ||
| var localAppDataDir = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); | ||
|
|
||
| #if DEBUG | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i mean big picture, this isn't exactly right, but it'll work this week |
||
| _settingsFilePath = Path.Combine(localAppDataDir, "Packages", "Microsoft.CommandPalette.Dev_8wekyb3d8bbwe", "LocalState", "settings.json"); | ||
| #else | ||
| _settingsFilePath = Path.Combine(localAppDataDir, "Packages", "Microsoft.CommandPalette_8wekyb3d8bbwe", "LocalState", "settings.json"); | ||
| #endif | ||
|
|
||
| InitializeHotkey(); | ||
| } | ||
|
|
||
| public void InitializeHotkey() | ||
| { | ||
| try | ||
| { | ||
| string json = File.ReadAllText(_settingsFilePath); // Read JSON file | ||
| using JsonDocument doc = JsonDocument.Parse(json); | ||
|
|
||
| if (doc.RootElement.TryGetProperty(nameof(Hotkey), out JsonElement hotkeyElement)) | ||
| { | ||
| Hotkey = JsonSerializer.Deserialize<HotkeySettings>(hotkeyElement.GetRawText()); | ||
|
|
||
| if (Hotkey == null) | ||
| { | ||
| Hotkey = DefaultHotkeyValue; | ||
| } | ||
| } | ||
| } | ||
| catch (Exception) | ||
| { | ||
| Hotkey = DefaultHotkeyValue; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 @@ public class CmdPalViewModel : Observable | |
| { | ||
| 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 @@ public CmdPalViewModel(ISettingsUtils settingsUtils, ISettingsRepository<General | |
|
|
||
| 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 @@ public bool IsEnabled | |
| } | ||
| } | ||
|
|
||
| public HotkeySettings Hotkey | ||
|
||
| { | ||
| get => _hotkey; | ||
|
|
||
| private set | ||
| { | ||
| } | ||
| } | ||
|
|
||
| public bool IsEnabledGpoConfigured { get; private set; } | ||
|
|
||
| public void RefreshEnabledState() | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay this is my c# knowledge being limited, but is there a reason to do it this way vs just