2025-12-23 21:07:44 +08:00
|
|
|
// 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.
|
|
|
|
|
|
2026-03-04 15:46:42 -05:00
|
|
|
using System;
|
2025-12-23 21:07:44 +08:00
|
|
|
using System.Collections.Generic;
|
2026-03-04 15:46:42 -05:00
|
|
|
using System.IO;
|
|
|
|
|
using System.Text.Json;
|
2025-12-23 21:07:44 +08:00
|
|
|
using Microsoft.CommandPalette.Extensions.Toolkit;
|
|
|
|
|
using PowerToysExtension.Commands;
|
|
|
|
|
using PowerToysExtension.Helpers;
|
2026-01-04 15:18:27 +08:00
|
|
|
using PowerToysExtension.Properties;
|
2025-12-23 21:07:44 +08:00
|
|
|
using static Common.UI.SettingsDeepLink;
|
|
|
|
|
|
|
|
|
|
namespace PowerToysExtension.Modules;
|
|
|
|
|
|
|
|
|
|
internal sealed class KeyboardManagerModuleCommandProvider : ModuleCommandProvider
|
|
|
|
|
{
|
|
|
|
|
public override IEnumerable<ListItem> BuildCommands()
|
|
|
|
|
{
|
|
|
|
|
var title = SettingsWindow.KBM.ModuleDisplayName();
|
|
|
|
|
var icon = SettingsWindow.KBM.ModuleIcon();
|
|
|
|
|
|
2026-03-04 15:46:42 -05:00
|
|
|
if (IsUseNewEditorEnabled())
|
|
|
|
|
{
|
|
|
|
|
yield return new ListItem(new OpenNewKeyboardManagerEditorCommand())
|
|
|
|
|
{
|
|
|
|
|
Title = Resources.KeyboardManager_OpenNewEditor_Title,
|
|
|
|
|
Subtitle = Resources.KeyboardManager_OpenNewEditor_Subtitle,
|
|
|
|
|
Icon = icon,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-04 01:25:56 -06:00
|
|
|
yield return new ListItem(new OpenInSettingsCommand(SettingsWindow.KBM, title) { Id = "com.microsoft.powertoys.keyboardManager.openSettings" })
|
2025-12-23 21:07:44 +08:00
|
|
|
{
|
|
|
|
|
Title = title,
|
2026-01-04 15:18:27 +08:00
|
|
|
Subtitle = Resources.KeyboardManager_Settings_Subtitle,
|
2025-12-23 21:07:44 +08:00
|
|
|
Icon = icon,
|
|
|
|
|
};
|
|
|
|
|
}
|
2026-03-04 15:46:42 -05:00
|
|
|
|
|
|
|
|
private static bool IsUseNewEditorEnabled()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var settingsPath = Path.Combine(
|
|
|
|
|
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
|
|
|
|
|
"Microsoft",
|
|
|
|
|
"PowerToys",
|
|
|
|
|
"Keyboard Manager",
|
|
|
|
|
"settings.json");
|
|
|
|
|
|
|
|
|
|
if (!File.Exists(settingsPath))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var json = File.ReadAllText(settingsPath);
|
|
|
|
|
using var doc = JsonDocument.Parse(json);
|
|
|
|
|
|
|
|
|
|
if (doc.RootElement.TryGetProperty("properties", out var properties) &&
|
|
|
|
|
properties.TryGetProperty("useNewEditor", out var useNewEditor))
|
|
|
|
|
{
|
|
|
|
|
return useNewEditor.GetBoolean();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
// If we can't read the setting, default to not showing the command
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2025-12-23 21:07:44 +08:00
|
|
|
}
|