mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-03 17:56:44 +02:00
[KeyboardManager WinUI3] Create WinUI3 project and wrapper for Keyboard Manager Editor (#37427)
* Set up KBM WinUI3 Editor UI project * Test invoking the KBM library via wrapper for WinUI3 C# UI * Set up Editor Library Wrapper and enable logging * fix spelling * update spacing and remove unused file * fix formatting * update sln * update wrapper project config * import common props * update UI reference * gate the new editor with the experimentation toggle in settings
This commit is contained in:
@@ -19,6 +19,7 @@ using Microsoft.PowerToys.Settings.UI.Library.Helpers;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.ViewModels.Commands;
|
||||
using Microsoft.PowerToys.Settings.Utilities;
|
||||
using Microsoft.Win32;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
||||
{
|
||||
@@ -31,7 +32,12 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
||||
private const string PowerToyName = KeyboardManagerSettings.ModuleName;
|
||||
private const string JsonFileType = ".json";
|
||||
|
||||
// Default editor path. Can be removed once the new WinUI3 editor is released.
|
||||
private const string KeyboardManagerEditorPath = "KeyboardManagerEditor\\PowerToys.KeyboardManagerEditor.exe";
|
||||
|
||||
// New WinUI3 editor path. Still in development and do NOT use it in production.
|
||||
private const string KeyboardManagerEditorUIPath = "KeyboardManagerEditorUI\\PowerToys.KeyboardManagerEditorUI.exe";
|
||||
|
||||
private Process editor;
|
||||
|
||||
private enum KeyboardManagerEditorType
|
||||
@@ -261,7 +267,37 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
||||
return;
|
||||
}
|
||||
|
||||
string path = Path.Combine(Environment.CurrentDirectory, KeyboardManagerEditorPath);
|
||||
// Launch the new editor if:
|
||||
// 1. the experimentation toggle is enabled in the settings
|
||||
// 2. the new WinUI3 editor is enabled in the registry. The registry value does not exist by default and is only used for development purposes
|
||||
string editorPath = KeyboardManagerEditorPath;
|
||||
try
|
||||
{
|
||||
// Check if the experimentation toggle is enabled in the settings
|
||||
var settingsUtils = new SettingsUtils();
|
||||
bool isExperimentationEnabled = SettingsRepository<GeneralSettings>.GetInstance(settingsUtils).SettingsConfig.EnableExperimentation;
|
||||
|
||||
// Only read the registry value if the experimentation toggle is enabled
|
||||
if (isExperimentationEnabled)
|
||||
{
|
||||
// Read the registry value to determine which editor to launch
|
||||
var key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\PowerToys\Keyboard Manager");
|
||||
if (key != null && (int?)key.GetValue("UseNewEditor") == 1)
|
||||
{
|
||||
editorPath = KeyboardManagerEditorUIPath;
|
||||
}
|
||||
|
||||
// Close the registry key
|
||||
key?.Close();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// Fall back to the default editor path if any exception occurs
|
||||
Logger.LogError("Failed to launch the new WinUI3 Editor", e);
|
||||
}
|
||||
|
||||
string path = Path.Combine(Environment.CurrentDirectory, editorPath);
|
||||
Logger.LogInfo($"Starting {PowerToyName} editor from {path}");
|
||||
|
||||
// InvariantCulture: type represents the KeyboardManagerEditorType enum value
|
||||
|
||||
Reference in New Issue
Block a user