2020-08-18 01:00:56 +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.
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2021-04-27 03:01:38 +08:00
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.Globalization;
|
2020-09-24 04:20:32 +08:00
|
|
|
|
using System.IO;
|
2020-08-18 01:00:56 +08:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows.Input;
|
2022-10-26 21:02:31 +08:00
|
|
|
|
using global::PowerToys.GPOWrapper;
|
2023-03-21 17:27:29 +08:00
|
|
|
|
using ManagedCommon;
|
2022-10-26 21:02:31 +08:00
|
|
|
|
using Microsoft.PowerToys.Settings.UI.Library;
|
2020-10-23 00:45:48 +08:00
|
|
|
|
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
|
|
|
|
|
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
|
|
|
|
|
using Microsoft.PowerToys.Settings.UI.Library.ViewModels.Commands;
|
2022-10-26 21:02:31 +08:00
|
|
|
|
using Microsoft.PowerToys.Settings.Utilities;
|
2020-08-18 01:00:56 +08:00
|
|
|
|
|
2022-10-26 21:02:31 +08:00
|
|
|
|
namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
2020-08-18 01:00:56 +08:00
|
|
|
|
{
|
|
|
|
|
public class KeyboardManagerViewModel : Observable
|
|
|
|
|
{
|
2020-09-24 04:20:32 +08:00
|
|
|
|
private GeneralSettings GeneralSettingsConfig { get; set; }
|
|
|
|
|
|
2020-09-22 01:14:44 +08:00
|
|
|
|
private readonly ISettingsUtils _settingsUtils;
|
|
|
|
|
|
2020-09-24 04:20:32 +08:00
|
|
|
|
private const string PowerToyName = KeyboardManagerSettings.ModuleName;
|
2020-08-18 01:00:56 +08:00
|
|
|
|
private const string JsonFileType = ".json";
|
2021-04-09 01:42:46 +08:00
|
|
|
|
|
2023-07-20 07:12:46 +08:00
|
|
|
|
private const string KeyboardManagerEditorPath = "KeyboardManagerEditor\\PowerToys.KeyboardManagerEditor.exe";
|
2021-04-27 03:01:38 +08:00
|
|
|
|
private Process editor;
|
2021-04-09 01:42:46 +08:00
|
|
|
|
|
2021-04-27 03:01:38 +08:00
|
|
|
|
private enum KeyboardManagerEditorType
|
|
|
|
|
{
|
|
|
|
|
KeyEditor = 0,
|
|
|
|
|
ShortcutEditor,
|
|
|
|
|
}
|
2020-08-18 01:00:56 +08:00
|
|
|
|
|
2022-10-26 21:02:31 +08:00
|
|
|
|
private GpoRuleConfigured _enabledGpoRuleConfiguration;
|
|
|
|
|
private bool _enabledStateIsGPOConfigured;
|
|
|
|
|
private bool _isEnabled;
|
|
|
|
|
|
2020-08-20 06:59:10 +08:00
|
|
|
|
public KeyboardManagerSettings Settings { get; set; }
|
2020-08-18 01:00:56 +08:00
|
|
|
|
|
2020-08-20 06:59:10 +08:00
|
|
|
|
private ICommand _remapKeyboardCommand;
|
|
|
|
|
private ICommand _editShortcutCommand;
|
|
|
|
|
private KeyboardManagerProfile _profile;
|
2020-08-18 01:00:56 +08:00
|
|
|
|
|
2020-08-18 06:00:19 +08:00
|
|
|
|
private Func<string, int> SendConfigMSG { get; }
|
|
|
|
|
|
|
|
|
|
private Func<List<KeysDataModel>, int> FilterRemapKeysList { get; }
|
|
|
|
|
|
2020-09-24 04:20:32 +08:00
|
|
|
|
public KeyboardManagerViewModel(ISettingsUtils settingsUtils, ISettingsRepository<GeneralSettings> settingsRepository, Func<string, int> ipcMSGCallBackFunc, Func<List<KeysDataModel>, int> filterRemapKeysList)
|
2020-08-18 01:00:56 +08:00
|
|
|
|
{
|
2020-10-20 04:32:05 +08:00
|
|
|
|
if (settingsRepository == null)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException(nameof(settingsRepository));
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-24 04:20:32 +08:00
|
|
|
|
GeneralSettingsConfig = settingsRepository.SettingsConfig;
|
|
|
|
|
|
2023-01-31 07:00:11 +08:00
|
|
|
|
InitializeEnabledValue();
|
2022-10-26 21:02:31 +08:00
|
|
|
|
|
2020-08-18 06:00:19 +08:00
|
|
|
|
// set the callback functions value to hangle outgoing IPC message.
|
|
|
|
|
SendConfigMSG = ipcMSGCallBackFunc;
|
|
|
|
|
FilterRemapKeysList = filterRemapKeysList;
|
|
|
|
|
|
2020-09-22 01:14:44 +08:00
|
|
|
|
_settingsUtils = settingsUtils ?? throw new ArgumentNullException(nameof(settingsUtils));
|
|
|
|
|
|
|
|
|
|
if (_settingsUtils.SettingsExists(PowerToyName))
|
2020-08-18 01:00:56 +08:00
|
|
|
|
{
|
2020-10-22 03:32:53 +08:00
|
|
|
|
try
|
|
|
|
|
{
|
2021-01-14 20:14:29 +08:00
|
|
|
|
Settings = _settingsUtils.GetSettingsOrDefault<KeyboardManagerSettings>(PowerToyName);
|
2020-10-22 03:32:53 +08:00
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Logger.LogError($"Exception encountered while reading {PowerToyName} settings.", e);
|
|
|
|
|
#if DEBUG
|
|
|
|
|
if (e is ArgumentException || e is ArgumentNullException || e is PathTooLongException)
|
|
|
|
|
{
|
2020-10-23 00:45:48 +08:00
|
|
|
|
throw;
|
2020-10-22 03:32:53 +08:00
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
}
|
2020-08-18 01:00:56 +08:00
|
|
|
|
|
|
|
|
|
// Load profile.
|
|
|
|
|
if (!LoadProfile())
|
|
|
|
|
{
|
2020-08-20 06:59:10 +08:00
|
|
|
|
_profile = new KeyboardManagerProfile();
|
2020-08-18 01:00:56 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-09-24 04:20:32 +08:00
|
|
|
|
Settings = new KeyboardManagerSettings();
|
2020-09-22 01:14:44 +08:00
|
|
|
|
_settingsUtils.SaveSettings(Settings.ToJsonString(), PowerToyName);
|
2020-08-18 01:00:56 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-31 07:00:11 +08:00
|
|
|
|
private void InitializeEnabledValue()
|
|
|
|
|
{
|
|
|
|
|
_enabledGpoRuleConfiguration = GPOWrapper.GetConfiguredKeyboardManagerEnabledValue();
|
|
|
|
|
if (_enabledGpoRuleConfiguration == GpoRuleConfigured.Disabled || _enabledGpoRuleConfiguration == GpoRuleConfigured.Enabled)
|
|
|
|
|
{
|
|
|
|
|
// Get the enabled state from GPO.
|
|
|
|
|
_enabledStateIsGPOConfigured = true;
|
|
|
|
|
_isEnabled = _enabledGpoRuleConfiguration == GpoRuleConfigured.Enabled;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_isEnabled = GeneralSettingsConfig.Enabled.KeyboardManager;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-18 01:00:56 +08:00
|
|
|
|
public bool Enabled
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2022-10-26 21:02:31 +08:00
|
|
|
|
return _isEnabled;
|
2020-08-18 01:00:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
2022-10-26 21:02:31 +08:00
|
|
|
|
if (_enabledStateIsGPOConfigured)
|
2020-08-18 01:00:56 +08:00
|
|
|
|
{
|
2022-10-26 21:02:31 +08:00
|
|
|
|
// If it's GPO configured, shouldn't be able to change this state.
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_isEnabled != value)
|
|
|
|
|
{
|
|
|
|
|
_isEnabled = value;
|
|
|
|
|
|
2020-09-24 04:20:32 +08:00
|
|
|
|
GeneralSettingsConfig.Enabled.KeyboardManager = value;
|
2020-08-18 01:00:56 +08:00
|
|
|
|
OnPropertyChanged(nameof(Enabled));
|
2021-04-27 03:01:38 +08:00
|
|
|
|
|
|
|
|
|
if (!Enabled && editor != null)
|
|
|
|
|
{
|
|
|
|
|
editor.CloseMainWindow();
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-24 04:20:32 +08:00
|
|
|
|
OutGoingGeneralSettings outgoing = new OutGoingGeneralSettings(GeneralSettingsConfig);
|
2020-08-18 01:00:56 +08:00
|
|
|
|
|
2020-08-18 06:00:19 +08:00
|
|
|
|
SendConfigMSG(outgoing.ToString());
|
2020-08-18 01:00:56 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-26 21:02:31 +08:00
|
|
|
|
public bool IsEnabledGpoConfigured
|
|
|
|
|
{
|
|
|
|
|
get => _enabledStateIsGPOConfigured;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-18 01:00:56 +08:00
|
|
|
|
// store remappings
|
|
|
|
|
public List<KeysDataModel> RemapKeys
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2020-08-20 06:59:10 +08:00
|
|
|
|
if (_profile != null)
|
2020-08-18 01:00:56 +08:00
|
|
|
|
{
|
2020-08-20 06:59:10 +08:00
|
|
|
|
return _profile.RemapKeys.InProcessRemapKeys;
|
2020-08-18 01:00:56 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return new List<KeysDataModel>();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static List<AppSpecificKeysDataModel> CombineShortcutLists(List<KeysDataModel> globalShortcutList, List<AppSpecificKeysDataModel> appSpecificShortcutList)
|
|
|
|
|
{
|
2022-11-18 23:34:17 +08:00
|
|
|
|
string allAppsDescription = "All Apps";
|
|
|
|
|
try
|
|
|
|
|
{
|
2023-07-20 07:12:46 +08:00
|
|
|
|
var resourceLoader = Helpers.ResourceLoaderInstance.ResourceLoader;
|
2022-11-18 23:34:17 +08:00
|
|
|
|
allAppsDescription = resourceLoader.GetString("KeyboardManager_All_Apps_Description");
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Logger.LogError("Couldn't get translation for All Apps mention in KBM page.", ex);
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-20 04:32:05 +08:00
|
|
|
|
if (globalShortcutList == null && appSpecificShortcutList == null)
|
|
|
|
|
{
|
|
|
|
|
return new List<AppSpecificKeysDataModel>();
|
|
|
|
|
}
|
|
|
|
|
else if (globalShortcutList == null)
|
|
|
|
|
{
|
|
|
|
|
return appSpecificShortcutList;
|
|
|
|
|
}
|
|
|
|
|
else if (appSpecificShortcutList == null)
|
|
|
|
|
{
|
2022-11-18 23:34:17 +08:00
|
|
|
|
return globalShortcutList.ConvertAll(x => new AppSpecificKeysDataModel { OriginalKeys = x.OriginalKeys, NewRemapKeys = x.NewRemapKeys, TargetApp = allAppsDescription }).ToList();
|
2020-10-20 04:32:05 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2022-11-18 23:34:17 +08:00
|
|
|
|
return globalShortcutList.ConvertAll(x => new AppSpecificKeysDataModel { OriginalKeys = x.OriginalKeys, NewRemapKeys = x.NewRemapKeys, TargetApp = allAppsDescription }).Concat(appSpecificShortcutList).ToList();
|
2020-10-20 04:32:05 +08:00
|
|
|
|
}
|
2020-08-18 01:00:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<AppSpecificKeysDataModel> RemapShortcuts
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2020-08-20 06:59:10 +08:00
|
|
|
|
if (_profile != null)
|
2020-08-18 01:00:56 +08:00
|
|
|
|
{
|
2020-08-20 06:59:10 +08:00
|
|
|
|
return CombineShortcutLists(_profile.RemapShortcuts.GlobalRemapShortcuts, _profile.RemapShortcuts.AppSpecificRemapShortcuts);
|
2020-08-18 01:00:56 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return new List<AppSpecificKeysDataModel>();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-20 06:59:10 +08:00
|
|
|
|
public ICommand RemapKeyboardCommand => _remapKeyboardCommand ?? (_remapKeyboardCommand = new RelayCommand(OnRemapKeyboard));
|
2020-08-18 01:00:56 +08:00
|
|
|
|
|
2020-08-20 06:59:10 +08:00
|
|
|
|
public ICommand EditShortcutCommand => _editShortcutCommand ?? (_editShortcutCommand = new RelayCommand(OnEditShortcut));
|
2020-08-18 01:00:56 +08:00
|
|
|
|
|
[Settings]Adding a Dashboard Panel (#29023)
* Dashboard: modifying page content + adding SW version button.
* Visual tweaks and minor viewmodel changes
* Updated spacing
* Adding Settings icon
* Settiing the Dashboard page as the default one. Adding functionality to switch to settings pages from the Dashboard page. Localizing texts.
* fixing csproj file
* Reimplementing Active modules handling, showing only the active modules (and not having invisible inactive modules).
* Removing unneccessary binding
* Fix text wrapping
* Adding Registry previewer launch, adding activation mode for FindMyMouse and QuickAccent, modify File Locksmith description.
* Spell checker fix typo
* Adding GPO-blocked state, modifying buttons: adding description, icon.
* Modifying dashboard button layout
* Use SettingsCard instead of button
* Restructuring the dashboard panel
* Removing togglebuttons from the left panel. Showing only active modules. Adding key remappings (to KBM)
* Removing settings buttons, removing descriptions, icons from buttons. Add update of remapped keys, shortcuts.
* Refactoring dashboard
* Making list always visible and fixing scrolling behavior
* Adding background gradient to cards
* Removing keyboard manager's key mappings, minor changes in texts, fixing enabled state when GPO-enabled.
* Use ListView instead of ItemsRepeater
* Updates
* removing right panel with all modules. Extending "left" panel with toggleswitches, showing all modules.
* Separate lists
* Adding Flyout with key remappings for KBM module, adding IsLocked property, icons
* Visual tweaks
* Tweaks
* Fixing lock icon margin
* Minor fixes.
* Removing unused resources
* Make Dashboard default when coming from the OOBE General
* Removed the Previous, Next Layout buttons from FancyZones. Added activation information
---------
Co-authored-by: Niels Laute <niels.laute@live.nl>
2023-10-20 20:23:25 +08:00
|
|
|
|
public void OnRemapKeyboard()
|
2020-08-18 01:00:56 +08:00
|
|
|
|
{
|
2021-04-27 03:01:38 +08:00
|
|
|
|
OpenEditor((int)KeyboardManagerEditorType.KeyEditor);
|
2020-08-18 01:00:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
[Settings]Adding a Dashboard Panel (#29023)
* Dashboard: modifying page content + adding SW version button.
* Visual tweaks and minor viewmodel changes
* Updated spacing
* Adding Settings icon
* Settiing the Dashboard page as the default one. Adding functionality to switch to settings pages from the Dashboard page. Localizing texts.
* fixing csproj file
* Reimplementing Active modules handling, showing only the active modules (and not having invisible inactive modules).
* Removing unneccessary binding
* Fix text wrapping
* Adding Registry previewer launch, adding activation mode for FindMyMouse and QuickAccent, modify File Locksmith description.
* Spell checker fix typo
* Adding GPO-blocked state, modifying buttons: adding description, icon.
* Modifying dashboard button layout
* Use SettingsCard instead of button
* Restructuring the dashboard panel
* Removing togglebuttons from the left panel. Showing only active modules. Adding key remappings (to KBM)
* Removing settings buttons, removing descriptions, icons from buttons. Add update of remapped keys, shortcuts.
* Refactoring dashboard
* Making list always visible and fixing scrolling behavior
* Adding background gradient to cards
* Removing keyboard manager's key mappings, minor changes in texts, fixing enabled state when GPO-enabled.
* Use ListView instead of ItemsRepeater
* Updates
* removing right panel with all modules. Extending "left" panel with toggleswitches, showing all modules.
* Separate lists
* Adding Flyout with key remappings for KBM module, adding IsLocked property, icons
* Visual tweaks
* Tweaks
* Fixing lock icon margin
* Minor fixes.
* Removing unused resources
* Make Dashboard default when coming from the OOBE General
* Removed the Previous, Next Layout buttons from FancyZones. Added activation information
---------
Co-authored-by: Niels Laute <niels.laute@live.nl>
2023-10-20 20:23:25 +08:00
|
|
|
|
public void OnEditShortcut()
|
2020-08-18 01:00:56 +08:00
|
|
|
|
{
|
2021-04-27 03:01:38 +08:00
|
|
|
|
OpenEditor((int)KeyboardManagerEditorType.ShortcutEditor);
|
2020-08-18 01:00:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-27 03:01:38 +08:00
|
|
|
|
private static void BringProcessToFront(Process process)
|
2020-08-18 01:00:56 +08:00
|
|
|
|
{
|
2021-04-27 03:01:38 +08:00
|
|
|
|
if (process == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IntPtr handle = process.MainWindowHandle;
|
2021-04-27 07:14:59 +08:00
|
|
|
|
if (NativeMethods.IsIconic(handle))
|
2021-04-27 03:01:38 +08:00
|
|
|
|
{
|
2021-04-27 07:14:59 +08:00
|
|
|
|
NativeMethods.ShowWindow(handle, NativeMethods.SWRESTORE);
|
2021-04-27 03:01:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-27 07:14:59 +08:00
|
|
|
|
NativeMethods.SetForegroundWindow(handle);
|
2020-08-18 01:00:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-27 03:01:38 +08:00
|
|
|
|
private void OpenEditor(int type)
|
2020-08-18 01:00:56 +08:00
|
|
|
|
{
|
2021-04-27 03:01:38 +08:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (editor != null && editor.HasExited)
|
|
|
|
|
{
|
|
|
|
|
Logger.LogInfo($"Previous instance of {PowerToyName} editor exited");
|
|
|
|
|
editor = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (editor != null)
|
|
|
|
|
{
|
|
|
|
|
Logger.LogInfo($"The {PowerToyName} editor instance {editor.Id} exists. Bringing the process to the front");
|
|
|
|
|
BringProcessToFront(editor);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string path = Path.Combine(Environment.CurrentDirectory, KeyboardManagerEditorPath);
|
|
|
|
|
Logger.LogInfo($"Starting {PowerToyName} editor from {path}");
|
|
|
|
|
|
|
|
|
|
// InvariantCulture: type represents the KeyboardManagerEditorType enum value
|
2022-04-20 04:00:28 +08:00
|
|
|
|
editor = Process.Start(path, $"{type.ToString(CultureInfo.InvariantCulture)} {Environment.ProcessId}");
|
2021-04-27 03:01:38 +08:00
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Logger.LogError($"Exception encountered when opening an {PowerToyName} editor", e);
|
|
|
|
|
}
|
2020-08-18 01:00:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-08-18 06:00:19 +08:00
|
|
|
|
public void NotifyFileChanged()
|
2020-08-18 01:00:56 +08:00
|
|
|
|
{
|
2020-08-18 06:00:19 +08:00
|
|
|
|
OnPropertyChanged(nameof(RemapKeys));
|
|
|
|
|
OnPropertyChanged(nameof(RemapShortcuts));
|
2020-08-18 01:00:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-01-31 07:00:11 +08:00
|
|
|
|
public void RefreshEnabledState()
|
|
|
|
|
{
|
|
|
|
|
InitializeEnabledValue();
|
|
|
|
|
OnPropertyChanged(nameof(Enabled));
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-18 06:00:19 +08:00
|
|
|
|
public bool LoadProfile()
|
2020-08-18 01:00:56 +08:00
|
|
|
|
{
|
|
|
|
|
var success = true;
|
2021-04-27 03:01:38 +08:00
|
|
|
|
var readSuccessfully = false;
|
|
|
|
|
|
2022-06-02 17:42:10 +08:00
|
|
|
|
// The KBM process out of runner doesn't create the default.json file if it does not exist.
|
2021-04-27 03:01:38 +08:00
|
|
|
|
string fileName = Settings.Properties.ActiveConfiguration.Value + JsonFileType;
|
2022-06-02 17:42:10 +08:00
|
|
|
|
var profileExists = false;
|
2020-08-18 01:00:56 +08:00
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2021-04-27 03:01:38 +08:00
|
|
|
|
// retry loop for reading
|
|
|
|
|
CancellationTokenSource ts = new CancellationTokenSource();
|
|
|
|
|
Task t = Task.Run(() =>
|
2020-08-18 01:00:56 +08:00
|
|
|
|
{
|
2021-04-27 03:01:38 +08:00
|
|
|
|
while (!readSuccessfully && !ts.IsCancellationRequested)
|
2020-08-18 01:00:56 +08:00
|
|
|
|
{
|
2022-06-02 17:42:10 +08:00
|
|
|
|
profileExists = _settingsUtils.SettingsExists(PowerToyName, fileName);
|
|
|
|
|
if (!profileExists)
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else
|
2020-08-18 01:00:56 +08:00
|
|
|
|
{
|
2021-04-27 03:01:38 +08:00
|
|
|
|
try
|
2020-09-24 04:20:32 +08:00
|
|
|
|
{
|
2021-01-14 20:14:29 +08:00
|
|
|
|
_profile = _settingsUtils.GetSettingsOrDefault<KeyboardManagerProfile>(PowerToyName, fileName);
|
2021-04-27 03:01:38 +08:00
|
|
|
|
readSuccessfully = true;
|
2020-09-24 04:20:32 +08:00
|
|
|
|
}
|
2021-04-27 03:01:38 +08:00
|
|
|
|
catch (Exception e)
|
2020-09-24 04:20:32 +08:00
|
|
|
|
{
|
2021-04-27 03:01:38 +08:00
|
|
|
|
Logger.LogError($"Exception encountered when reading {PowerToyName} settings", e);
|
2020-09-24 04:20:32 +08:00
|
|
|
|
}
|
2020-08-18 01:00:56 +08:00
|
|
|
|
}
|
2021-04-27 03:01:38 +08:00
|
|
|
|
|
|
|
|
|
if (!readSuccessfully)
|
2020-08-18 01:00:56 +08:00
|
|
|
|
{
|
2022-10-13 05:10:56 +08:00
|
|
|
|
Task.Delay(500, ts.Token).Wait(ts.Token);
|
2020-08-18 01:00:56 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-04-27 03:01:38 +08:00
|
|
|
|
});
|
|
|
|
|
|
2022-03-11 01:31:16 +08:00
|
|
|
|
var completedInTime = t.Wait(3000, ts.Token);
|
2021-04-27 03:01:38 +08:00
|
|
|
|
ts.Cancel();
|
|
|
|
|
ts.Dispose();
|
|
|
|
|
|
2022-03-11 01:31:16 +08:00
|
|
|
|
if (readSuccessfully)
|
|
|
|
|
{
|
|
|
|
|
FilterRemapKeysList(_profile?.RemapKeys?.InProcessRemapKeys);
|
|
|
|
|
}
|
|
|
|
|
else
|
2021-04-27 03:01:38 +08:00
|
|
|
|
{
|
|
|
|
|
success = false;
|
2020-08-18 01:00:56 +08:00
|
|
|
|
}
|
2021-04-27 03:01:38 +08:00
|
|
|
|
|
2022-03-11 01:31:16 +08:00
|
|
|
|
if (!completedInTime)
|
|
|
|
|
{
|
|
|
|
|
Logger.LogError($"Timeout encountered when loading {PowerToyName} profile");
|
|
|
|
|
}
|
2020-08-18 01:00:56 +08:00
|
|
|
|
}
|
2020-10-22 03:32:53 +08:00
|
|
|
|
catch (Exception e)
|
2020-08-18 01:00:56 +08:00
|
|
|
|
{
|
|
|
|
|
// Failed to load the configuration.
|
2020-10-22 03:32:53 +08:00
|
|
|
|
Logger.LogError($"Exception encountered when loading {PowerToyName} profile", e);
|
2020-08-18 01:00:56 +08:00
|
|
|
|
success = false;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-02 17:42:10 +08:00
|
|
|
|
if (!profileExists)
|
|
|
|
|
{
|
|
|
|
|
Logger.LogInfo($"Couldn't load {PowerToyName} profile because it doesn't exist");
|
|
|
|
|
}
|
|
|
|
|
else if (!success)
|
2022-03-11 01:31:16 +08:00
|
|
|
|
{
|
|
|
|
|
Logger.LogError($"Couldn't load {PowerToyName} profile");
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-18 01:00:56 +08:00
|
|
|
|
return success;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|