[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

@@ -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
_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;
}
}
}
}