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
|
|
|
|
|
{
|
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;
|
2020-08-15 04:58:48 +08:00
|
|
|
|
|
2020-09-24 04:20:32 +08:00
|
|
|
|
public ShortcutGuideViewModel(ISettingsRepository<GeneralSettings> settingsRepository, ISettingsRepository<ShortcutGuideSettings> moduleSettingsRepository, Func<string, int> ipcMSGCallBackFunc, string configFileSubfolder = "")
|
2020-03-27 23:58:53 +08:00
|
|
|
|
{
|
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;
|
2020-08-20 06:59:10 +08:00
|
|
|
|
_pressTime = Settings.Properties.PressTime.Value;
|
|
|
|
|
_opacity = Settings.Properties.OverlayOpacity.Value;
|
2020-04-20 21:03:26 +08:00
|
|
|
|
|
|
|
|
|
string theme = Settings.Properties.Theme.Value;
|
|
|
|
|
|
|
|
|
|
if (theme == "dark")
|
|
|
|
|
{
|
|
|
|
|
_themeIndex = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (theme == "light")
|
|
|
|
|
{
|
|
|
|
|
_themeIndex = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (theme == "system")
|
|
|
|
|
{
|
|
|
|
|
_themeIndex = 2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-10 08:58:52 +08:00
|
|
|
|
private bool _isEnabled;
|
|
|
|
|
private int _themeIndex;
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int ThemeIndex
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return _themeIndex;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (_themeIndex != value)
|
|
|
|
|
{
|
|
|
|
|
if (value == 0)
|
|
|
|
|
{
|
|
|
|
|
// set theme to dark.
|
|
|
|
|
Settings.Properties.Theme.Value = "dark";
|
|
|
|
|
_themeIndex = value;
|
2020-10-20 04:32:05 +08:00
|
|
|
|
NotifyPropertyChanged();
|
2020-04-20 21:03:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (value == 1)
|
|
|
|
|
{
|
|
|
|
|
// set theme to light.
|
|
|
|
|
Settings.Properties.Theme.Value = "light";
|
|
|
|
|
_themeIndex = value;
|
2020-10-20 04:32:05 +08:00
|
|
|
|
NotifyPropertyChanged();
|
2020-04-20 21:03:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (value == 2)
|
|
|
|
|
{
|
|
|
|
|
// set theme to system default.
|
|
|
|
|
Settings.Properties.Theme.Value = "system";
|
|
|
|
|
_themeIndex = value;
|
2020-10-20 04:32:05 +08:00
|
|
|
|
NotifyPropertyChanged();
|
2020-04-20 21:03:26 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int PressTime
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return _pressTime;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (_pressTime != value)
|
|
|
|
|
{
|
|
|
|
|
_pressTime = value;
|
|
|
|
|
Settings.Properties.PressTime.Value = value;
|
2020-10-20 04:32:05 +08:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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);
|
|
|
|
|
SndShortcutGuideSettings outsettings = new SndShortcutGuideSettings(Settings);
|
|
|
|
|
SndModuleSettings<SndShortcutGuideSettings> ipcMessage = new SndModuleSettings<SndShortcutGuideSettings>(outsettings);
|
2020-08-15 04:58:48 +08:00
|
|
|
|
SendConfigMSG(ipcMessage.ToJsonString());
|
2020-03-27 23:58:53 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-04-11 06:22:07 +08:00
|
|
|
|
}
|