2020-04-08 01:19:14 +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.
|
|
|
|
|
|
2020-08-15 04:58:48 +08:00
|
|
|
|
using System;
|
2020-04-20 21:03:26 +08:00
|
|
|
|
using System.Runtime.CompilerServices;
|
2020-10-23 00:45:48 +08:00
|
|
|
|
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
|
|
|
|
|
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
|
2020-03-27 23:58:53 +08:00
|
|
|
|
|
2020-10-23 00:45:48 +08:00
|
|
|
|
namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
|
2020-03-27 23:58:53 +08:00
|
|
|
|
{
|
|
|
|
|
public class ShortcutGuideViewModel : Observable
|
|
|
|
|
{
|
2021-05-20 20:07:34 +08:00
|
|
|
|
private ISettingsUtils SettingsUtils { get; set; }
|
|
|
|
|
|
2020-09-24 04:20:32 +08:00
|
|
|
|
private GeneralSettings GeneralSettingsConfig { get; set; }
|
2020-09-22 01:14:44 +08:00
|
|
|
|
|
2020-04-20 21:03:26 +08:00
|
|
|
|
private ShortcutGuideSettings Settings { get; set; }
|
|
|
|
|
|
2020-09-24 04:20:32 +08:00
|
|
|
|
private const string ModuleName = ShortcutGuideSettings.ModuleName;
|
2020-04-20 21:03:26 +08:00
|
|
|
|
|
2020-08-15 04:58:48 +08:00
|
|
|
|
private Func<string, int> SendConfigMSG { get; }
|
|
|
|
|
|
2020-08-20 06:59:10 +08:00
|
|
|
|
private string _settingsConfigFileFolder = string.Empty;
|
2021-04-02 22:29:48 +08:00
|
|
|
|
private string _disabledApps;
|
2020-08-15 04:58:48 +08:00
|
|
|
|
|
2021-05-20 20:07:34 +08:00
|
|
|
|
public ShortcutGuideViewModel(ISettingsUtils settingsUtils, ISettingsRepository<GeneralSettings> settingsRepository, ISettingsRepository<ShortcutGuideSettings> moduleSettingsRepository, Func<string, int> ipcMSGCallBackFunc, string configFileSubfolder = "")
|
2020-03-27 23:58:53 +08:00
|
|
|
|
{
|
2021-05-20 20:07:34 +08:00
|
|
|
|
SettingsUtils = settingsUtils;
|
|
|
|
|
|
2020-08-15 04:58:48 +08:00
|
|
|
|
// Update Settings file folder:
|
2020-08-20 06:59:10 +08:00
|
|
|
|
_settingsConfigFileFolder = configFileSubfolder;
|
2020-08-15 04:58:48 +08:00
|
|
|
|
|
2020-09-24 04:20:32 +08:00
|
|
|
|
// To obtain the general PowerToys settings.
|
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;
|
2020-04-20 21:03:26 +08:00
|
|
|
|
|
2020-09-24 04:20:32 +08:00
|
|
|
|
// To obtain the shortcut guide settings, if the file exists.
|
|
|
|
|
// If not, to create a file with the default settings and to return the default configurations.
|
2020-10-20 04:32:05 +08:00
|
|
|
|
if (moduleSettingsRepository == null)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException(nameof(moduleSettingsRepository));
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-24 04:20:32 +08:00
|
|
|
|
Settings = moduleSettingsRepository.SettingsConfig;
|
2020-04-20 21:03:26 +08:00
|
|
|
|
|
2020-08-15 04:58:48 +08:00
|
|
|
|
// set the callback functions value to hangle outgoing IPC message.
|
|
|
|
|
SendConfigMSG = ipcMSGCallBackFunc;
|
|
|
|
|
|
2020-09-24 04:20:32 +08:00
|
|
|
|
_isEnabled = GeneralSettingsConfig.Enabled.ShortcutGuide;
|
2021-09-23 21:23:22 +08:00
|
|
|
|
_useLegacyPressWinKeyBehavior = Settings.Properties.UseLegacyPressWinKeyBehavior.Value;
|
2020-08-20 06:59:10 +08:00
|
|
|
|
_pressTime = Settings.Properties.PressTime.Value;
|
|
|
|
|
_opacity = Settings.Properties.OverlayOpacity.Value;
|
2021-04-02 22:29:48 +08:00
|
|
|
|
_disabledApps = Settings.Properties.DisabledApps.Value;
|
2020-04-20 21:03:26 +08:00
|
|
|
|
|
2021-08-24 01:48:52 +08:00
|
|
|
|
switch (Settings.Properties.Theme.Value)
|
2020-04-20 21:03:26 +08:00
|
|
|
|
{
|
2021-08-24 01:48:52 +08:00
|
|
|
|
case "dark": _themeIndex = 0; break;
|
|
|
|
|
case "light": _themeIndex = 1; break;
|
|
|
|
|
case "system": _themeIndex = 2; break;
|
2020-04-20 21:03:26 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-10 08:58:52 +08:00
|
|
|
|
private bool _isEnabled;
|
|
|
|
|
private int _themeIndex;
|
2021-09-23 21:23:22 +08:00
|
|
|
|
private bool _useLegacyPressWinKeyBehavior;
|
2020-10-10 08:58:52 +08:00
|
|
|
|
private int _pressTime;
|
|
|
|
|
private int _opacity;
|
2020-04-20 21:03:26 +08:00
|
|
|
|
|
|
|
|
|
public bool IsEnabled
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return _isEnabled;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value != _isEnabled)
|
|
|
|
|
{
|
|
|
|
|
_isEnabled = value;
|
2020-09-24 04:20:32 +08:00
|
|
|
|
|
|
|
|
|
// To update the status of shortcut guide in General PowerToy settings.
|
|
|
|
|
GeneralSettingsConfig.Enabled.ShortcutGuide = value;
|
|
|
|
|
OutGoingGeneralSettings snd = new OutGoingGeneralSettings(GeneralSettingsConfig);
|
|
|
|
|
|
2020-08-15 04:58:48 +08:00
|
|
|
|
SendConfigMSG(snd.ToString());
|
2020-10-10 08:58:52 +08:00
|
|
|
|
OnPropertyChanged(nameof(IsEnabled));
|
2020-04-20 21:03:26 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-20 20:07:34 +08:00
|
|
|
|
public HotkeySettings OpenShortcutGuide
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return Settings.Properties.OpenShortcutGuide;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (Settings.Properties.OpenShortcutGuide != value)
|
|
|
|
|
{
|
|
|
|
|
Settings.Properties.OpenShortcutGuide = value;
|
|
|
|
|
NotifyPropertyChanged();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-20 21:03:26 +08:00
|
|
|
|
public int ThemeIndex
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return _themeIndex;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (_themeIndex != value)
|
|
|
|
|
{
|
2021-08-24 01:48:52 +08:00
|
|
|
|
switch (value)
|
2020-04-20 21:03:26 +08:00
|
|
|
|
{
|
2021-08-24 01:48:52 +08:00
|
|
|
|
case 0: Settings.Properties.Theme.Value = "dark"; break;
|
|
|
|
|
case 1: Settings.Properties.Theme.Value = "light"; break;
|
|
|
|
|
case 2: Settings.Properties.Theme.Value = "system"; break;
|
2020-04-20 21:03:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-24 01:48:52 +08:00
|
|
|
|
_themeIndex = value;
|
|
|
|
|
NotifyPropertyChanged();
|
2020-04-20 21:03:26 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int OverlayOpacity
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return _opacity;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (_opacity != value)
|
|
|
|
|
{
|
|
|
|
|
_opacity = value;
|
|
|
|
|
Settings.Properties.OverlayOpacity.Value = value;
|
2020-10-20 04:32:05 +08:00
|
|
|
|
NotifyPropertyChanged();
|
2020-04-20 21:03:26 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-23 21:23:22 +08:00
|
|
|
|
public bool UseLegacyPressWinKeyBehavior
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return _useLegacyPressWinKeyBehavior;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (_useLegacyPressWinKeyBehavior != value)
|
|
|
|
|
{
|
|
|
|
|
_useLegacyPressWinKeyBehavior = value;
|
|
|
|
|
Settings.Properties.UseLegacyPressWinKeyBehavior.Value = value;
|
|
|
|
|
NotifyPropertyChanged();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int PressTime
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return _pressTime;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (_pressTime != value)
|
|
|
|
|
{
|
|
|
|
|
_pressTime = value;
|
|
|
|
|
Settings.Properties.PressTime.Value = value;
|
|
|
|
|
NotifyPropertyChanged();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-02 22:29:48 +08:00
|
|
|
|
public string DisabledApps
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return _disabledApps;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value != _disabledApps)
|
|
|
|
|
{
|
|
|
|
|
_disabledApps = value;
|
|
|
|
|
Settings.Properties.DisabledApps.Value = value;
|
|
|
|
|
NotifyPropertyChanged();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-15 04:58:48 +08:00
|
|
|
|
public string GetSettingsSubPath()
|
|
|
|
|
{
|
2020-08-20 06:59:10 +08:00
|
|
|
|
return _settingsConfigFileFolder + "\\" + ModuleName;
|
2020-08-15 04:58:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-20 04:32:05 +08:00
|
|
|
|
public void NotifyPropertyChanged([CallerMemberName] string propertyName = null)
|
2020-04-20 21:03:26 +08:00
|
|
|
|
{
|
|
|
|
|
OnPropertyChanged(propertyName);
|
2021-05-20 20:07:34 +08:00
|
|
|
|
|
2020-04-20 21:03:26 +08:00
|
|
|
|
SndShortcutGuideSettings outsettings = new SndShortcutGuideSettings(Settings);
|
|
|
|
|
SndModuleSettings<SndShortcutGuideSettings> ipcMessage = new SndModuleSettings<SndShortcutGuideSettings>(outsettings);
|
2020-08-15 04:58:48 +08:00
|
|
|
|
SendConfigMSG(ipcMessage.ToJsonString());
|
2021-05-20 20:07:34 +08:00
|
|
|
|
SettingsUtils.SaveSettings(Settings.ToJsonString(), ModuleName);
|
2020-03-27 23:58:53 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-04-11 06:22:07 +08:00
|
|
|
|
}
|