mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-04 18:26:39 +02:00
[GPO] Add policies for configuring utilities enabled states (#21411)
* Add GPOWrapper headers and C++/WinRT library * Check GPO before starting utilities * Show message on GPO having disabled preview panes. * Don't generate thumbnails if GPO disabled * Fix FancyZonesEditor unable to recognize GPOWrapper * Move settings view models to the settings project * Use GPO to block enabling utilities in Settings * Hide context menu entries when gpo disables utilities * Apply gpo policies when enabling PowerToys on runner * Add version and metadata to dll * Add GPOWrapper to the installer * Fix MSBuild errors on WPF apps by using Projection * Signing * Add gpo files and publish them * Add GPO policies to the bug report tool * Add some documentation for using GPO * Mention support to actual lowest supported version of Windows * Move PowerToys to the root of administrative templates tree * Save policies on Software\Policies\PowerToys * Support both machine and user scopes * Fix documentation to reference computer and user scopes * Mention incompatibility with outlook in gpo * Set a better folder structure for gpo assets * Move PDF Handler warning to the description * Update doc/gpo/README.md Co-authored-by: Heiko <61519853+htcfreek@users.noreply.github.com> * Add actual minimum version of PowerToys to gpo files * Fix identation * Remove GPOWrapper Readme * Add Active Directory instructions to doc Co-authored-by: Heiko <61519853+htcfreek@users.noreply.github.com>
This commit is contained in:
@@ -1,265 +0,0 @@
|
||||
// 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.Globalization;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text.Json;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
|
||||
{
|
||||
public class AlwaysOnTopViewModel : Observable
|
||||
{
|
||||
private ISettingsUtils SettingsUtils { get; set; }
|
||||
|
||||
private GeneralSettings GeneralSettingsConfig { get; set; }
|
||||
|
||||
private AlwaysOnTopSettings Settings { get; set; }
|
||||
|
||||
private Func<string, int> SendConfigMSG { get; }
|
||||
|
||||
public AlwaysOnTopViewModel(ISettingsUtils settingsUtils, ISettingsRepository<GeneralSettings> settingsRepository, ISettingsRepository<AlwaysOnTopSettings> moduleSettingsRepository, Func<string, int> ipcMSGCallBackFunc)
|
||||
{
|
||||
if (settingsUtils == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(settingsUtils));
|
||||
}
|
||||
|
||||
SettingsUtils = settingsUtils;
|
||||
|
||||
// To obtain the general settings configurations of PowerToys Settings.
|
||||
if (settingsRepository == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(settingsRepository));
|
||||
}
|
||||
|
||||
GeneralSettingsConfig = settingsRepository.SettingsConfig;
|
||||
|
||||
// To obtain the settings configurations of AlwaysOnTop.
|
||||
if (moduleSettingsRepository == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(moduleSettingsRepository));
|
||||
}
|
||||
|
||||
Settings = moduleSettingsRepository.SettingsConfig;
|
||||
|
||||
_isEnabled = GeneralSettingsConfig.Enabled.AlwaysOnTop;
|
||||
_hotkey = Settings.Properties.Hotkey.Value;
|
||||
_frameEnabled = Settings.Properties.FrameEnabled.Value;
|
||||
_frameThickness = Settings.Properties.FrameThickness.Value;
|
||||
_frameColor = Settings.Properties.FrameColor.Value;
|
||||
_frameAccentColor = Settings.Properties.FrameAccentColor.Value;
|
||||
_soundEnabled = Settings.Properties.SoundEnabled.Value;
|
||||
_doNotActivateOnGameMode = Settings.Properties.DoNotActivateOnGameMode.Value;
|
||||
_roundCornersEnabled = Settings.Properties.RoundCornersEnabled.Value;
|
||||
_excludedApps = Settings.Properties.ExcludedApps.Value;
|
||||
_windows11 = Helper.Windows11();
|
||||
|
||||
// set the callback functions value to hangle outgoing IPC message.
|
||||
SendConfigMSG = ipcMSGCallBackFunc;
|
||||
}
|
||||
|
||||
public bool IsEnabled
|
||||
{
|
||||
get => _isEnabled;
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _isEnabled)
|
||||
{
|
||||
_isEnabled = value;
|
||||
|
||||
// Set the status in the general settings configuration
|
||||
GeneralSettingsConfig.Enabled.AlwaysOnTop = value;
|
||||
OutGoingGeneralSettings snd = new OutGoingGeneralSettings(GeneralSettingsConfig);
|
||||
|
||||
SendConfigMSG(snd.ToString());
|
||||
OnPropertyChanged(nameof(IsEnabled));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public HotkeySettings Hotkey
|
||||
{
|
||||
get => _hotkey;
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _hotkey)
|
||||
{
|
||||
if (value == null || value.IsEmpty())
|
||||
{
|
||||
_hotkey = AlwaysOnTopProperties.DefaultHotkeyValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
_hotkey = value;
|
||||
}
|
||||
|
||||
Settings.Properties.Hotkey.Value = _hotkey;
|
||||
NotifyPropertyChanged();
|
||||
|
||||
// Using InvariantCulture as this is an IPC message
|
||||
SendConfigMSG(
|
||||
string.Format(
|
||||
CultureInfo.InvariantCulture,
|
||||
"{{ \"powertoys\": {{ \"{0}\": {1} }} }}",
|
||||
AlwaysOnTopSettings.ModuleName,
|
||||
JsonSerializer.Serialize(Settings)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool FrameEnabled
|
||||
{
|
||||
get => _frameEnabled;
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _frameEnabled)
|
||||
{
|
||||
_frameEnabled = value;
|
||||
Settings.Properties.FrameEnabled.Value = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int FrameThickness
|
||||
{
|
||||
get => _frameThickness;
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _frameThickness)
|
||||
{
|
||||
_frameThickness = value;
|
||||
Settings.Properties.FrameThickness.Value = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string FrameColor
|
||||
{
|
||||
get => _frameColor;
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _frameColor)
|
||||
{
|
||||
_frameColor = value;
|
||||
Settings.Properties.FrameColor.Value = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool SoundEnabled
|
||||
{
|
||||
get => _soundEnabled;
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _soundEnabled)
|
||||
{
|
||||
_soundEnabled = value;
|
||||
Settings.Properties.SoundEnabled.Value = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool DoNotActivateOnGameMode
|
||||
{
|
||||
get => _doNotActivateOnGameMode;
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _doNotActivateOnGameMode)
|
||||
{
|
||||
_doNotActivateOnGameMode = value;
|
||||
Settings.Properties.DoNotActivateOnGameMode.Value = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool RoundCornersEnabled
|
||||
{
|
||||
get => _roundCornersEnabled;
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _roundCornersEnabled)
|
||||
{
|
||||
_roundCornersEnabled = value;
|
||||
Settings.Properties.RoundCornersEnabled.Value = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string ExcludedApps
|
||||
{
|
||||
get => _excludedApps;
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _excludedApps)
|
||||
{
|
||||
_excludedApps = value;
|
||||
Settings.Properties.ExcludedApps.Value = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool FrameAccentColor
|
||||
{
|
||||
get => _frameAccentColor;
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _frameAccentColor)
|
||||
{
|
||||
_frameAccentColor = value;
|
||||
Settings.Properties.FrameAccentColor.Value = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool Windows11
|
||||
{
|
||||
get => _windows11;
|
||||
|
||||
set
|
||||
{
|
||||
_windows11 = value;
|
||||
}
|
||||
}
|
||||
|
||||
public void NotifyPropertyChanged([CallerMemberName] string propertyName = null)
|
||||
{
|
||||
OnPropertyChanged(propertyName);
|
||||
SettingsUtils.SaveSettings(Settings.ToJsonString(), AlwaysOnTopSettings.ModuleName);
|
||||
}
|
||||
|
||||
private bool _isEnabled;
|
||||
private HotkeySettings _hotkey;
|
||||
private bool _frameEnabled;
|
||||
private int _frameThickness;
|
||||
private string _frameColor;
|
||||
private bool _frameAccentColor;
|
||||
private bool _soundEnabled;
|
||||
private bool _doNotActivateOnGameMode;
|
||||
private bool _roundCornersEnabled;
|
||||
private string _excludedApps;
|
||||
private bool _windows11;
|
||||
}
|
||||
}
|
||||
@@ -1,157 +0,0 @@
|
||||
// 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.Runtime.CompilerServices;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
|
||||
{
|
||||
public class AwakeViewModel : Observable
|
||||
{
|
||||
private GeneralSettings GeneralSettingsConfig { get; set; }
|
||||
|
||||
private AwakeSettings Settings { get; set; }
|
||||
|
||||
private Func<string, int> SendConfigMSG { get; }
|
||||
|
||||
public AwakeViewModel(ISettingsRepository<GeneralSettings> settingsRepository, ISettingsRepository<AwakeSettings> moduleSettingsRepository, Func<string, int> ipcMSGCallBackFunc)
|
||||
{
|
||||
// To obtain the general settings configurations of PowerToys Settings.
|
||||
if (settingsRepository == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(settingsRepository));
|
||||
}
|
||||
|
||||
GeneralSettingsConfig = settingsRepository.SettingsConfig;
|
||||
|
||||
// To obtain the settings configurations of Fancy zones.
|
||||
if (moduleSettingsRepository == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(moduleSettingsRepository));
|
||||
}
|
||||
|
||||
Settings = moduleSettingsRepository.SettingsConfig;
|
||||
|
||||
_isEnabled = GeneralSettingsConfig.Enabled.Awake;
|
||||
_keepDisplayOn = Settings.Properties.KeepDisplayOn;
|
||||
_mode = Settings.Properties.Mode;
|
||||
_hours = Settings.Properties.Hours;
|
||||
_minutes = Settings.Properties.Minutes;
|
||||
|
||||
// set the callback functions value to hangle outgoing IPC message.
|
||||
SendConfigMSG = ipcMSGCallBackFunc;
|
||||
}
|
||||
|
||||
public bool IsEnabled
|
||||
{
|
||||
get => _isEnabled;
|
||||
set
|
||||
{
|
||||
if (_isEnabled != value)
|
||||
{
|
||||
_isEnabled = value;
|
||||
|
||||
GeneralSettingsConfig.Enabled.Awake = value;
|
||||
OnPropertyChanged(nameof(IsEnabled));
|
||||
OnPropertyChanged(nameof(IsTimeConfigurationEnabled));
|
||||
|
||||
OutGoingGeneralSettings outgoing = new OutGoingGeneralSettings(GeneralSettingsConfig);
|
||||
SendConfigMSG(outgoing.ToString());
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsTimeConfigurationEnabled
|
||||
{
|
||||
get => _mode == AwakeMode.TIMED && _isEnabled;
|
||||
}
|
||||
|
||||
public AwakeMode Mode
|
||||
{
|
||||
get => _mode;
|
||||
set
|
||||
{
|
||||
if (_mode != value)
|
||||
{
|
||||
_mode = value;
|
||||
OnPropertyChanged(nameof(Mode));
|
||||
OnPropertyChanged(nameof(IsTimeConfigurationEnabled));
|
||||
|
||||
Settings.Properties.Mode = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool KeepDisplayOn
|
||||
{
|
||||
get => _keepDisplayOn;
|
||||
set
|
||||
{
|
||||
if (_keepDisplayOn != value)
|
||||
{
|
||||
_keepDisplayOn = value;
|
||||
OnPropertyChanged(nameof(KeepDisplayOn));
|
||||
|
||||
Settings.Properties.KeepDisplayOn = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public uint Hours
|
||||
{
|
||||
get => _hours;
|
||||
set
|
||||
{
|
||||
if (_hours != value)
|
||||
{
|
||||
_hours = value;
|
||||
OnPropertyChanged(nameof(Hours));
|
||||
|
||||
Settings.Properties.Hours = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public uint Minutes
|
||||
{
|
||||
get => _minutes;
|
||||
set
|
||||
{
|
||||
if (_minutes != value)
|
||||
{
|
||||
_minutes = value;
|
||||
OnPropertyChanged(nameof(Minutes));
|
||||
|
||||
Settings.Properties.Minutes = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void NotifyPropertyChanged([CallerMemberName] string propertyName = null)
|
||||
{
|
||||
OnPropertyChanged(propertyName);
|
||||
if (SendConfigMSG != null)
|
||||
{
|
||||
SndAwakeSettings outsettings = new SndAwakeSettings(Settings);
|
||||
SndModuleSettings<SndAwakeSettings> ipcMessage = new SndModuleSettings<SndAwakeSettings>(outsettings);
|
||||
|
||||
string targetMessage = ipcMessage.ToJsonString();
|
||||
SendConfigMSG(targetMessage);
|
||||
}
|
||||
}
|
||||
|
||||
private bool _isEnabled;
|
||||
private uint _hours;
|
||||
private uint _minutes;
|
||||
private bool _keepDisplayOn;
|
||||
private AwakeMode _mode;
|
||||
}
|
||||
}
|
||||
@@ -1,334 +0,0 @@
|
||||
// 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;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
using System.Timers;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Enumerations;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
|
||||
{
|
||||
public class ColorPickerViewModel : Observable, IDisposable
|
||||
{
|
||||
private bool disposedValue;
|
||||
|
||||
// Delay saving of settings in order to avoid calling save multiple times and hitting file in use exception. If there is no other request to save settings in given interval, we proceed to save it, otherwise we schedule saving it after this interval
|
||||
private const int SaveSettingsDelayInMs = 500;
|
||||
|
||||
private GeneralSettings GeneralSettingsConfig { get; set; }
|
||||
|
||||
private readonly ISettingsUtils _settingsUtils;
|
||||
private readonly object _delayedActionLock = new object();
|
||||
|
||||
private readonly ColorPickerSettings _colorPickerSettings;
|
||||
private Timer _delayedTimer;
|
||||
|
||||
private bool _isEnabled;
|
||||
|
||||
private Func<string, int> SendConfigMSG { get; }
|
||||
|
||||
public ColorPickerViewModel(
|
||||
ISettingsUtils settingsUtils,
|
||||
ISettingsRepository<GeneralSettings> settingsRepository,
|
||||
ISettingsRepository<ColorPickerSettings> colorPickerSettingsRepository,
|
||||
Func<string, int> ipcMSGCallBackFunc)
|
||||
{
|
||||
// Obtain the general PowerToy settings configurations
|
||||
if (settingsRepository == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(settingsRepository));
|
||||
}
|
||||
|
||||
SelectableColorRepresentations = new Dictionary<ColorRepresentationType, string>
|
||||
{
|
||||
{ ColorRepresentationType.CMYK, "CMYK - cmyk(100%, 50%, 75%, 0%)" },
|
||||
{ ColorRepresentationType.HEX, "HEX - ffaa00" },
|
||||
{ ColorRepresentationType.HSB, "HSB - hsb(100, 50%, 75%)" },
|
||||
{ ColorRepresentationType.HSI, "HSI - hsi(100, 50%, 75%)" },
|
||||
{ ColorRepresentationType.HSL, "HSL - hsl(100, 50%, 75%)" },
|
||||
{ ColorRepresentationType.HSV, "HSV - hsv(100, 50%, 75%)" },
|
||||
{ ColorRepresentationType.HWB, "HWB - hwb(100, 50%, 75%)" },
|
||||
{ ColorRepresentationType.NCol, "NCol - R10, 50%, 75%" },
|
||||
{ ColorRepresentationType.RGB, "RGB - rgb(100, 50, 75)" },
|
||||
{ ColorRepresentationType.CIELAB, "CIE LAB - CIELab(76, 21, 80)" },
|
||||
{ ColorRepresentationType.CIEXYZ, "CIE XYZ - xyz(56, 50, 7)" },
|
||||
{ ColorRepresentationType.VEC4, "VEC4 - (1.0f, 0.7f, 0f, 1f)" },
|
||||
{ ColorRepresentationType.DecimalValue, "Decimal - 16755200" },
|
||||
};
|
||||
|
||||
GeneralSettingsConfig = settingsRepository.SettingsConfig;
|
||||
|
||||
_settingsUtils = settingsUtils ?? throw new ArgumentNullException(nameof(settingsUtils));
|
||||
|
||||
if (colorPickerSettingsRepository == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(colorPickerSettingsRepository));
|
||||
}
|
||||
|
||||
_colorPickerSettings = colorPickerSettingsRepository.SettingsConfig;
|
||||
|
||||
_isEnabled = GeneralSettingsConfig.Enabled.ColorPicker;
|
||||
|
||||
// set the callback functions value to hangle outgoing IPC message.
|
||||
SendConfigMSG = ipcMSGCallBackFunc;
|
||||
|
||||
_delayedTimer = new Timer();
|
||||
_delayedTimer.Interval = SaveSettingsDelayInMs;
|
||||
_delayedTimer.Elapsed += DelayedTimer_Tick;
|
||||
_delayedTimer.AutoReset = false;
|
||||
|
||||
InitializeColorFormats();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list with all selectable <see cref="ColorRepresentationType"/>s
|
||||
/// </summary>
|
||||
public IReadOnlyDictionary<ColorRepresentationType, string> SelectableColorRepresentations { get; }
|
||||
|
||||
public bool IsEnabled
|
||||
{
|
||||
get => _isEnabled;
|
||||
set
|
||||
{
|
||||
if (_isEnabled != value)
|
||||
{
|
||||
_isEnabled = value;
|
||||
OnPropertyChanged(nameof(IsEnabled));
|
||||
|
||||
// Set the status of ColorPicker in the general settings
|
||||
GeneralSettingsConfig.Enabled.ColorPicker = value;
|
||||
var outgoing = new OutGoingGeneralSettings(GeneralSettingsConfig);
|
||||
|
||||
SendConfigMSG(outgoing.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool ChangeCursor
|
||||
{
|
||||
get => _colorPickerSettings.Properties.ChangeCursor;
|
||||
set
|
||||
{
|
||||
if (_colorPickerSettings.Properties.ChangeCursor != value)
|
||||
{
|
||||
_colorPickerSettings.Properties.ChangeCursor = value;
|
||||
OnPropertyChanged(nameof(ChangeCursor));
|
||||
NotifySettingsChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public HotkeySettings ActivationShortcut
|
||||
{
|
||||
get => _colorPickerSettings.Properties.ActivationShortcut;
|
||||
set
|
||||
{
|
||||
if (_colorPickerSettings.Properties.ActivationShortcut != value)
|
||||
{
|
||||
_colorPickerSettings.Properties.ActivationShortcut = value;
|
||||
OnPropertyChanged(nameof(ActivationShortcut));
|
||||
NotifySettingsChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ColorRepresentationType SelectedColorRepresentationValue
|
||||
{
|
||||
get => _colorPickerSettings.Properties.CopiedColorRepresentation;
|
||||
set
|
||||
{
|
||||
if (_colorPickerSettings.Properties.CopiedColorRepresentation != value)
|
||||
{
|
||||
_colorPickerSettings.Properties.CopiedColorRepresentation = value;
|
||||
OnPropertyChanged(nameof(SelectedColorRepresentationValue));
|
||||
NotifySettingsChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int ActivationBehavior
|
||||
{
|
||||
get
|
||||
{
|
||||
return (int)_colorPickerSettings.Properties.ActivationAction;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != (int)_colorPickerSettings.Properties.ActivationAction)
|
||||
{
|
||||
_colorPickerSettings.Properties.ActivationAction = (ColorPickerActivationAction)value;
|
||||
OnPropertyChanged(nameof(ActivationBehavior));
|
||||
NotifySettingsChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool ShowColorName
|
||||
{
|
||||
get => _colorPickerSettings.Properties.ShowColorName;
|
||||
set
|
||||
{
|
||||
if (_colorPickerSettings.Properties.ShowColorName != value)
|
||||
{
|
||||
_colorPickerSettings.Properties.ShowColorName = value;
|
||||
OnPropertyChanged(nameof(ShowColorName));
|
||||
NotifySettingsChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ObservableCollection<ColorFormatModel> ColorFormats { get; } = new ObservableCollection<ColorFormatModel>();
|
||||
|
||||
private void InitializeColorFormats()
|
||||
{
|
||||
var visibleFormats = _colorPickerSettings.Properties.VisibleColorFormats;
|
||||
var formatsUnordered = new List<ColorFormatModel>();
|
||||
|
||||
var hexFormatName = ColorRepresentationType.HEX.ToString();
|
||||
var rgbFormatName = ColorRepresentationType.RGB.ToString();
|
||||
var hslFormatName = ColorRepresentationType.HSL.ToString();
|
||||
var hsvFormatName = ColorRepresentationType.HSV.ToString();
|
||||
var cmykFormatName = ColorRepresentationType.CMYK.ToString();
|
||||
var hsbFormatName = ColorRepresentationType.HSB.ToString();
|
||||
var hsiFormatName = ColorRepresentationType.HSI.ToString();
|
||||
var hwbFormatName = ColorRepresentationType.HWB.ToString();
|
||||
var ncolFormatName = ColorRepresentationType.NCol.ToString();
|
||||
var cielabFormatName = ColorRepresentationType.CIELAB.ToString();
|
||||
var ciexyzFormatName = ColorRepresentationType.CIEXYZ.ToString();
|
||||
var vec4FormatName = ColorRepresentationType.VEC4.ToString();
|
||||
var decimalFormatName = "Decimal";
|
||||
|
||||
formatsUnordered.Add(new ColorFormatModel(hexFormatName, "ef68ff", visibleFormats.ContainsKey(hexFormatName) && visibleFormats[hexFormatName]));
|
||||
formatsUnordered.Add(new ColorFormatModel(rgbFormatName, "rgb(239, 104, 255)", visibleFormats.ContainsKey(rgbFormatName) && visibleFormats[rgbFormatName]));
|
||||
formatsUnordered.Add(new ColorFormatModel(hslFormatName, "hsl(294, 100%, 70%)", visibleFormats.ContainsKey(hslFormatName) && visibleFormats[hslFormatName]));
|
||||
formatsUnordered.Add(new ColorFormatModel(hsvFormatName, "hsv(294, 59%, 100%)", visibleFormats.ContainsKey(hsvFormatName) && visibleFormats[hsvFormatName]));
|
||||
formatsUnordered.Add(new ColorFormatModel(cmykFormatName, "cmyk(6%, 59%, 0%, 0%)", visibleFormats.ContainsKey(cmykFormatName) && visibleFormats[cmykFormatName]));
|
||||
formatsUnordered.Add(new ColorFormatModel(hsbFormatName, "hsb(100, 50%, 75%)", visibleFormats.ContainsKey(hsbFormatName) && visibleFormats[hsbFormatName]));
|
||||
formatsUnordered.Add(new ColorFormatModel(hsiFormatName, "hsi(100, 50%, 75%)", visibleFormats.ContainsKey(hsiFormatName) && visibleFormats[hsiFormatName]));
|
||||
formatsUnordered.Add(new ColorFormatModel(hwbFormatName, "hwb(100, 50%, 75%)", visibleFormats.ContainsKey(hwbFormatName) && visibleFormats[hwbFormatName]));
|
||||
formatsUnordered.Add(new ColorFormatModel(ncolFormatName, "R10, 50%, 75%", visibleFormats.ContainsKey(ncolFormatName) && visibleFormats[ncolFormatName]));
|
||||
formatsUnordered.Add(new ColorFormatModel(cielabFormatName, "CIELab(66, 72, -52)", visibleFormats.ContainsKey(cielabFormatName) && visibleFormats[cielabFormatName]));
|
||||
formatsUnordered.Add(new ColorFormatModel(ciexyzFormatName, "XYZ(59, 35, 98)", visibleFormats.ContainsKey(ciexyzFormatName) && visibleFormats[ciexyzFormatName]));
|
||||
formatsUnordered.Add(new ColorFormatModel(vec4FormatName, "(0.94f, 0.41f, 1.00f, 1f)", visibleFormats.ContainsKey(vec4FormatName) && visibleFormats[vec4FormatName]));
|
||||
formatsUnordered.Add(new ColorFormatModel(decimalFormatName, "15689983", visibleFormats.ContainsKey(decimalFormatName) && visibleFormats[decimalFormatName]));
|
||||
|
||||
foreach (var storedColorFormat in _colorPickerSettings.Properties.VisibleColorFormats)
|
||||
{
|
||||
var predefinedFormat = formatsUnordered.FirstOrDefault(it => it.Name == storedColorFormat.Key);
|
||||
if (predefinedFormat != null)
|
||||
{
|
||||
predefinedFormat.PropertyChanged += ColorFormat_PropertyChanged;
|
||||
ColorFormats.Add(predefinedFormat);
|
||||
formatsUnordered.Remove(predefinedFormat);
|
||||
}
|
||||
}
|
||||
|
||||
// settings file might not have all formats listed, add remaining ones we support
|
||||
foreach (var remainingColorFormat in formatsUnordered)
|
||||
{
|
||||
remainingColorFormat.PropertyChanged += ColorFormat_PropertyChanged;
|
||||
ColorFormats.Add(remainingColorFormat);
|
||||
}
|
||||
|
||||
// Reordering colors with buttons: disable first and last buttons
|
||||
ColorFormats[0].CanMoveUp = false;
|
||||
ColorFormats[ColorFormats.Count - 1].CanMoveDown = false;
|
||||
|
||||
ColorFormats.CollectionChanged += ColorFormats_CollectionChanged;
|
||||
}
|
||||
|
||||
private void ColorFormats_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
|
||||
{
|
||||
// Reordering colors with buttons: update buttons availability depending on order
|
||||
if (ColorFormats.Count > 0)
|
||||
{
|
||||
foreach (var color in ColorFormats)
|
||||
{
|
||||
color.CanMoveUp = true;
|
||||
color.CanMoveDown = true;
|
||||
}
|
||||
|
||||
ColorFormats[0].CanMoveUp = false;
|
||||
ColorFormats[ColorFormats.Count - 1].CanMoveDown = false;
|
||||
}
|
||||
|
||||
UpdateColorFormats();
|
||||
ScheduleSavingOfSettings();
|
||||
}
|
||||
|
||||
private void ColorFormat_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
|
||||
{
|
||||
UpdateColorFormats();
|
||||
ScheduleSavingOfSettings();
|
||||
}
|
||||
|
||||
private void ScheduleSavingOfSettings()
|
||||
{
|
||||
lock (_delayedActionLock)
|
||||
{
|
||||
if (_delayedTimer.Enabled)
|
||||
{
|
||||
_delayedTimer.Stop();
|
||||
}
|
||||
|
||||
_delayedTimer.Start();
|
||||
}
|
||||
}
|
||||
|
||||
private void DelayedTimer_Tick(object sender, EventArgs e)
|
||||
{
|
||||
lock (_delayedActionLock)
|
||||
{
|
||||
_delayedTimer.Stop();
|
||||
NotifySettingsChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateColorFormats()
|
||||
{
|
||||
_colorPickerSettings.Properties.VisibleColorFormats.Clear();
|
||||
foreach (var colorFormat in ColorFormats)
|
||||
{
|
||||
_colorPickerSettings.Properties.VisibleColorFormats.Add(colorFormat.Name, colorFormat.IsShown);
|
||||
}
|
||||
}
|
||||
|
||||
private void NotifySettingsChanged()
|
||||
{
|
||||
// Using InvariantCulture as this is an IPC message
|
||||
SendConfigMSG(
|
||||
string.Format(
|
||||
CultureInfo.InvariantCulture,
|
||||
"{{ \"powertoys\": {{ \"{0}\": {1} }} }}",
|
||||
ColorPickerSettings.ModuleName,
|
||||
JsonSerializer.Serialize(_colorPickerSettings)));
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (!disposedValue)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
_delayedTimer.Dispose();
|
||||
}
|
||||
|
||||
disposedValue = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(disposing: true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,861 +0,0 @@
|
||||
// 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.Runtime.CompilerServices;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.ViewModels.Commands;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
|
||||
{
|
||||
public class FancyZonesViewModel : Observable
|
||||
{
|
||||
private ISettingsUtils SettingsUtils { get; set; }
|
||||
|
||||
private GeneralSettings GeneralSettingsConfig { get; set; }
|
||||
|
||||
private const string ModuleName = FancyZonesSettings.ModuleName;
|
||||
|
||||
public ButtonClickCommand LaunchEditorEventHandler { get; set; }
|
||||
|
||||
private FancyZonesSettings Settings { get; set; }
|
||||
|
||||
private Func<string, int> SendConfigMSG { get; }
|
||||
|
||||
private string settingsConfigFileFolder = string.Empty;
|
||||
|
||||
private bool _windows11;
|
||||
|
||||
private enum MoveWindowBehaviour
|
||||
{
|
||||
MoveWindowBasedOnZoneIndex = 0,
|
||||
MoveWindowBasedOnPosition,
|
||||
}
|
||||
|
||||
private enum OverlappingZonesAlgorithm
|
||||
{
|
||||
Smallest = 0,
|
||||
Largest = 1,
|
||||
Positional = 2,
|
||||
}
|
||||
|
||||
public FancyZonesViewModel(SettingsUtils settingsUtils, ISettingsRepository<GeneralSettings> settingsRepository, ISettingsRepository<FancyZonesSettings> moduleSettingsRepository, Func<string, int> ipcMSGCallBackFunc, string configFileSubfolder = "")
|
||||
{
|
||||
if (settingsUtils == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(settingsUtils));
|
||||
}
|
||||
|
||||
SettingsUtils = settingsUtils;
|
||||
|
||||
// To obtain the general settings configurations of PowerToys Settings.
|
||||
if (settingsRepository == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(settingsRepository));
|
||||
}
|
||||
|
||||
GeneralSettingsConfig = settingsRepository.SettingsConfig;
|
||||
settingsConfigFileFolder = configFileSubfolder;
|
||||
|
||||
// To obtain the settings configurations of Fancy zones.
|
||||
if (moduleSettingsRepository == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(moduleSettingsRepository));
|
||||
}
|
||||
|
||||
Settings = moduleSettingsRepository.SettingsConfig;
|
||||
|
||||
LaunchEditorEventHandler = new ButtonClickCommand(LaunchEditor);
|
||||
|
||||
_shiftDrag = Settings.Properties.FancyzonesShiftDrag.Value;
|
||||
_mouseSwitch = Settings.Properties.FancyzonesMouseSwitch.Value;
|
||||
_overrideSnapHotkeys = Settings.Properties.FancyzonesOverrideSnapHotkeys.Value;
|
||||
_moveWindowsAcrossMonitors = Settings.Properties.FancyzonesMoveWindowsAcrossMonitors.Value;
|
||||
_moveWindowBehaviour = Settings.Properties.FancyzonesMoveWindowsBasedOnPosition.Value ? MoveWindowBehaviour.MoveWindowBasedOnPosition : MoveWindowBehaviour.MoveWindowBasedOnZoneIndex;
|
||||
_overlappingZonesAlgorithm = (OverlappingZonesAlgorithm)Settings.Properties.FancyzonesOverlappingZonesAlgorithm.Value;
|
||||
_displayChangemoveWindows = Settings.Properties.FancyzonesDisplayChangeMoveWindows.Value;
|
||||
_zoneSetChangeMoveWindows = Settings.Properties.FancyzonesZoneSetChangeMoveWindows.Value;
|
||||
_appLastZoneMoveWindows = Settings.Properties.FancyzonesAppLastZoneMoveWindows.Value;
|
||||
_openWindowOnActiveMonitor = Settings.Properties.FancyzonesOpenWindowOnActiveMonitor.Value;
|
||||
_restoreSize = Settings.Properties.FancyzonesRestoreSize.Value;
|
||||
_quickLayoutSwitch = Settings.Properties.FancyzonesQuickLayoutSwitch.Value;
|
||||
_flashZonesOnQuickLayoutSwitch = Settings.Properties.FancyzonesFlashZonesOnQuickSwitch.Value;
|
||||
_useCursorPosEditorStartupScreen = Settings.Properties.UseCursorposEditorStartupscreen.Value;
|
||||
_showOnAllMonitors = Settings.Properties.FancyzonesShowOnAllMonitors.Value;
|
||||
_spanZonesAcrossMonitors = Settings.Properties.FancyzonesSpanZonesAcrossMonitors.Value;
|
||||
_makeDraggedWindowTransparent = Settings.Properties.FancyzonesMakeDraggedWindowTransparent.Value;
|
||||
_allowPopupWindowSnap = Settings.Properties.FancyzonesAllowPopupWindowSnap.Value;
|
||||
_allowChildWindowSnap = Settings.Properties.FancyzonesAllowChildWindowSnap.Value;
|
||||
_disableRoundCornersOnSnap = Settings.Properties.FancyzonesDisableRoundCornersOnSnap.Value;
|
||||
_highlightOpacity = Settings.Properties.FancyzonesHighlightOpacity.Value;
|
||||
_excludedApps = Settings.Properties.FancyzonesExcludedApps.Value;
|
||||
_systemTheme = Settings.Properties.FancyzonesSystemTheme.Value;
|
||||
_showZoneNumber = Settings.Properties.FancyzonesShowZoneNumber.Value;
|
||||
EditorHotkey = Settings.Properties.FancyzonesEditorHotkey.Value;
|
||||
_windowSwitching = Settings.Properties.FancyzonesWindowSwitching.Value;
|
||||
NextTabHotkey = Settings.Properties.FancyzonesNextTabHotkey.Value;
|
||||
PrevTabHotkey = Settings.Properties.FancyzonesPrevTabHotkey.Value;
|
||||
|
||||
// set the callback functions value to hangle outgoing IPC message.
|
||||
SendConfigMSG = ipcMSGCallBackFunc;
|
||||
|
||||
string inactiveColor = Settings.Properties.FancyzonesInActiveColor.Value;
|
||||
_zoneInActiveColor = !string.IsNullOrEmpty(inactiveColor) ? inactiveColor : ConfigDefaults.DefaultFancyZonesInActiveColor;
|
||||
|
||||
string borderColor = Settings.Properties.FancyzonesBorderColor.Value;
|
||||
_zoneBorderColor = !string.IsNullOrEmpty(borderColor) ? borderColor : ConfigDefaults.DefaultFancyzonesBorderColor;
|
||||
|
||||
string highlightColor = Settings.Properties.FancyzonesZoneHighlightColor.Value;
|
||||
_zoneHighlightColor = !string.IsNullOrEmpty(highlightColor) ? highlightColor : ConfigDefaults.DefaultFancyZonesZoneHighlightColor;
|
||||
|
||||
string numberColor = Settings.Properties.FancyzonesNumberColor.Value;
|
||||
_zoneNumberColor = !string.IsNullOrEmpty(numberColor) ? numberColor : ConfigDefaults.DefaultFancyzonesNumberColor;
|
||||
|
||||
_isEnabled = GeneralSettingsConfig.Enabled.FancyZones;
|
||||
_windows11 = Helper.Windows11();
|
||||
|
||||
// Disable setting on windows 10
|
||||
if (!_windows11 && DisableRoundCornersOnWindowSnap)
|
||||
{
|
||||
DisableRoundCornersOnWindowSnap = false;
|
||||
}
|
||||
}
|
||||
|
||||
private bool _isEnabled;
|
||||
private bool _shiftDrag;
|
||||
private bool _mouseSwitch;
|
||||
private bool _overrideSnapHotkeys;
|
||||
private bool _moveWindowsAcrossMonitors;
|
||||
private MoveWindowBehaviour _moveWindowBehaviour;
|
||||
private OverlappingZonesAlgorithm _overlappingZonesAlgorithm;
|
||||
private bool _displayChangemoveWindows;
|
||||
private bool _zoneSetChangeMoveWindows;
|
||||
private bool _appLastZoneMoveWindows;
|
||||
private bool _openWindowOnActiveMonitor;
|
||||
private bool _spanZonesAcrossMonitors;
|
||||
private bool _restoreSize;
|
||||
private bool _quickLayoutSwitch;
|
||||
private bool _flashZonesOnQuickLayoutSwitch;
|
||||
private bool _useCursorPosEditorStartupScreen;
|
||||
private bool _showOnAllMonitors;
|
||||
private bool _makeDraggedWindowTransparent;
|
||||
private bool _systemTheme;
|
||||
private bool _showZoneNumber;
|
||||
private bool _allowPopupWindowSnap;
|
||||
private bool _allowChildWindowSnap;
|
||||
private bool _disableRoundCornersOnSnap;
|
||||
|
||||
private int _highlightOpacity;
|
||||
private string _excludedApps;
|
||||
private HotkeySettings _editorHotkey;
|
||||
private bool _windowSwitching;
|
||||
private HotkeySettings _nextTabHotkey;
|
||||
private HotkeySettings _prevTabHotkey;
|
||||
private string _zoneInActiveColor;
|
||||
private string _zoneBorderColor;
|
||||
private string _zoneHighlightColor;
|
||||
private string _zoneNumberColor;
|
||||
|
||||
public bool IsEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
return _isEnabled;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _isEnabled)
|
||||
{
|
||||
_isEnabled = value;
|
||||
|
||||
// Set the status of FancyZones in the general settings configuration
|
||||
GeneralSettingsConfig.Enabled.FancyZones = value;
|
||||
OutGoingGeneralSettings snd = new OutGoingGeneralSettings(GeneralSettingsConfig);
|
||||
|
||||
SendConfigMSG(snd.ToString());
|
||||
OnPropertyChanged(nameof(IsEnabled));
|
||||
OnPropertyChanged(nameof(SnapHotkeysCategoryEnabled));
|
||||
OnPropertyChanged(nameof(QuickSwitchEnabled));
|
||||
OnPropertyChanged(nameof(WindowSwitchingCategoryEnabled));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool SnapHotkeysCategoryEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
return _isEnabled && _overrideSnapHotkeys;
|
||||
}
|
||||
}
|
||||
|
||||
public bool QuickSwitchEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
return _isEnabled && _quickLayoutSwitch;
|
||||
}
|
||||
}
|
||||
|
||||
public bool WindowSwitchingCategoryEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
return _isEnabled && _windowSwitching;
|
||||
}
|
||||
}
|
||||
|
||||
public bool ShiftDrag
|
||||
{
|
||||
get
|
||||
{
|
||||
return _shiftDrag;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _shiftDrag)
|
||||
{
|
||||
_shiftDrag = value;
|
||||
Settings.Properties.FancyzonesShiftDrag.Value = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool MouseSwitch
|
||||
{
|
||||
get
|
||||
{
|
||||
return _mouseSwitch;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _mouseSwitch)
|
||||
{
|
||||
_mouseSwitch = value;
|
||||
Settings.Properties.FancyzonesMouseSwitch.Value = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string GetSettingsSubPath()
|
||||
{
|
||||
return settingsConfigFileFolder + "\\" + ModuleName;
|
||||
}
|
||||
|
||||
public bool OverrideSnapHotkeys
|
||||
{
|
||||
get
|
||||
{
|
||||
return _overrideSnapHotkeys;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _overrideSnapHotkeys)
|
||||
{
|
||||
_overrideSnapHotkeys = value;
|
||||
Settings.Properties.FancyzonesOverrideSnapHotkeys.Value = value;
|
||||
NotifyPropertyChanged();
|
||||
OnPropertyChanged(nameof(SnapHotkeysCategoryEnabled));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool MoveWindowsAcrossMonitors
|
||||
{
|
||||
get
|
||||
{
|
||||
return _moveWindowsAcrossMonitors;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _moveWindowsAcrossMonitors)
|
||||
{
|
||||
_moveWindowsAcrossMonitors = value;
|
||||
Settings.Properties.FancyzonesMoveWindowsAcrossMonitors.Value = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool MoveWindowsBasedOnPosition
|
||||
{
|
||||
get
|
||||
{
|
||||
return _moveWindowBehaviour == MoveWindowBehaviour.MoveWindowBasedOnPosition;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
var settingsValue = Settings.Properties.FancyzonesMoveWindowsBasedOnPosition.Value;
|
||||
if (value != settingsValue)
|
||||
{
|
||||
_moveWindowBehaviour = value ? MoveWindowBehaviour.MoveWindowBasedOnPosition : MoveWindowBehaviour.MoveWindowBasedOnZoneIndex;
|
||||
Settings.Properties.FancyzonesMoveWindowsBasedOnPosition.Value = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool MoveWindowsBasedOnZoneIndex
|
||||
{
|
||||
get
|
||||
{
|
||||
return _moveWindowBehaviour == MoveWindowBehaviour.MoveWindowBasedOnZoneIndex;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
var settingsValue = Settings.Properties.FancyzonesMoveWindowsBasedOnPosition.Value;
|
||||
if (value == settingsValue)
|
||||
{
|
||||
_moveWindowBehaviour = value ? MoveWindowBehaviour.MoveWindowBasedOnZoneIndex : MoveWindowBehaviour.MoveWindowBasedOnPosition;
|
||||
Settings.Properties.FancyzonesMoveWindowsBasedOnPosition.Value = !value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int OverlappingZonesAlgorithmIndex
|
||||
{
|
||||
get
|
||||
{
|
||||
return (int)_overlappingZonesAlgorithm;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != (int)_overlappingZonesAlgorithm)
|
||||
{
|
||||
_overlappingZonesAlgorithm = (OverlappingZonesAlgorithm)value;
|
||||
Settings.Properties.FancyzonesOverlappingZonesAlgorithm.Value = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool DisplayChangeMoveWindows
|
||||
{
|
||||
get
|
||||
{
|
||||
return _displayChangemoveWindows;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _displayChangemoveWindows)
|
||||
{
|
||||
_displayChangemoveWindows = value;
|
||||
Settings.Properties.FancyzonesDisplayChangeMoveWindows.Value = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool ZoneSetChangeMoveWindows
|
||||
{
|
||||
get
|
||||
{
|
||||
return _zoneSetChangeMoveWindows;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _zoneSetChangeMoveWindows)
|
||||
{
|
||||
_zoneSetChangeMoveWindows = value;
|
||||
Settings.Properties.FancyzonesZoneSetChangeMoveWindows.Value = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool AppLastZoneMoveWindows
|
||||
{
|
||||
get
|
||||
{
|
||||
return _appLastZoneMoveWindows;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _appLastZoneMoveWindows)
|
||||
{
|
||||
_appLastZoneMoveWindows = value;
|
||||
Settings.Properties.FancyzonesAppLastZoneMoveWindows.Value = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool OpenWindowOnActiveMonitor
|
||||
{
|
||||
get
|
||||
{
|
||||
return _openWindowOnActiveMonitor;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _openWindowOnActiveMonitor)
|
||||
{
|
||||
_openWindowOnActiveMonitor = value;
|
||||
Settings.Properties.FancyzonesOpenWindowOnActiveMonitor.Value = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool RestoreSize
|
||||
{
|
||||
get
|
||||
{
|
||||
return _restoreSize;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _restoreSize)
|
||||
{
|
||||
_restoreSize = value;
|
||||
Settings.Properties.FancyzonesRestoreSize.Value = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool QuickLayoutSwitch
|
||||
{
|
||||
get
|
||||
{
|
||||
return _quickLayoutSwitch;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _quickLayoutSwitch)
|
||||
{
|
||||
_quickLayoutSwitch = value;
|
||||
Settings.Properties.FancyzonesQuickLayoutSwitch.Value = value;
|
||||
NotifyPropertyChanged();
|
||||
OnPropertyChanged(nameof(QuickSwitchEnabled));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool FlashZonesOnQuickSwitch
|
||||
{
|
||||
get
|
||||
{
|
||||
return _flashZonesOnQuickLayoutSwitch;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _flashZonesOnQuickLayoutSwitch)
|
||||
{
|
||||
_flashZonesOnQuickLayoutSwitch = value;
|
||||
Settings.Properties.FancyzonesFlashZonesOnQuickSwitch.Value = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool UseCursorPosEditorStartupScreen
|
||||
{
|
||||
get
|
||||
{
|
||||
return _useCursorPosEditorStartupScreen;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _useCursorPosEditorStartupScreen)
|
||||
{
|
||||
_useCursorPosEditorStartupScreen = value;
|
||||
Settings.Properties.UseCursorposEditorStartupscreen.Value = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool ShowOnAllMonitors
|
||||
{
|
||||
get
|
||||
{
|
||||
return _showOnAllMonitors;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _showOnAllMonitors)
|
||||
{
|
||||
_showOnAllMonitors = value;
|
||||
Settings.Properties.FancyzonesShowOnAllMonitors.Value = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool SpanZonesAcrossMonitors
|
||||
{
|
||||
get
|
||||
{
|
||||
return _spanZonesAcrossMonitors;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _spanZonesAcrossMonitors)
|
||||
{
|
||||
_spanZonesAcrossMonitors = value;
|
||||
Settings.Properties.FancyzonesSpanZonesAcrossMonitors.Value = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool MakeDraggedWindowsTransparent
|
||||
{
|
||||
get
|
||||
{
|
||||
return _makeDraggedWindowTransparent;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _makeDraggedWindowTransparent)
|
||||
{
|
||||
_makeDraggedWindowTransparent = value;
|
||||
Settings.Properties.FancyzonesMakeDraggedWindowTransparent.Value = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool SystemTheme
|
||||
{
|
||||
get
|
||||
{
|
||||
return _systemTheme;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _systemTheme)
|
||||
{
|
||||
_systemTheme = value;
|
||||
Settings.Properties.FancyzonesSystemTheme.Value = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool ShowZoneNumber
|
||||
{
|
||||
get
|
||||
{
|
||||
return _showZoneNumber;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _showZoneNumber)
|
||||
{
|
||||
_showZoneNumber = value;
|
||||
Settings.Properties.FancyzonesShowZoneNumber.Value = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool AllowPopupWindowSnap
|
||||
{
|
||||
get
|
||||
{
|
||||
return _allowPopupWindowSnap;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _allowPopupWindowSnap)
|
||||
{
|
||||
_allowPopupWindowSnap = value;
|
||||
Settings.Properties.FancyzonesAllowPopupWindowSnap.Value = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool AllowChildWindowSnap
|
||||
{
|
||||
get
|
||||
{
|
||||
return _allowChildWindowSnap;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _allowChildWindowSnap)
|
||||
{
|
||||
_allowChildWindowSnap = value;
|
||||
Settings.Properties.FancyzonesAllowChildWindowSnap.Value = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool DisableRoundCornersOnWindowSnap
|
||||
{
|
||||
get
|
||||
{
|
||||
return _disableRoundCornersOnSnap;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (_disableRoundCornersOnSnap != value)
|
||||
{
|
||||
_disableRoundCornersOnSnap = value;
|
||||
Settings.Properties.FancyzonesDisableRoundCornersOnSnap.Value = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// For the following setters we use OrdinalIgnoreCase string comparison since
|
||||
// we expect value to be a hex code.
|
||||
public string ZoneHighlightColor
|
||||
{
|
||||
get
|
||||
{
|
||||
return _zoneHighlightColor;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
value = SettingsUtilities.ToRGBHex(value);
|
||||
if (!value.Equals(_zoneHighlightColor, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
_zoneHighlightColor = value;
|
||||
Settings.Properties.FancyzonesZoneHighlightColor.Value = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string ZoneBorderColor
|
||||
{
|
||||
get
|
||||
{
|
||||
return _zoneBorderColor;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
value = SettingsUtilities.ToRGBHex(value);
|
||||
if (!value.Equals(_zoneBorderColor, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
_zoneBorderColor = value;
|
||||
Settings.Properties.FancyzonesBorderColor.Value = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string ZoneInActiveColor
|
||||
{
|
||||
get
|
||||
{
|
||||
return _zoneInActiveColor;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
value = SettingsUtilities.ToRGBHex(value);
|
||||
if (!value.Equals(_zoneInActiveColor, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
_zoneInActiveColor = value;
|
||||
Settings.Properties.FancyzonesInActiveColor.Value = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string ZoneNumberColor
|
||||
{
|
||||
get
|
||||
{
|
||||
return _zoneNumberColor;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
value = SettingsUtilities.ToRGBHex(value);
|
||||
if (!value.Equals(_zoneNumberColor, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
_zoneNumberColor = value;
|
||||
Settings.Properties.FancyzonesNumberColor.Value = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int HighlightOpacity
|
||||
{
|
||||
get
|
||||
{
|
||||
return _highlightOpacity;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _highlightOpacity)
|
||||
{
|
||||
_highlightOpacity = value;
|
||||
Settings.Properties.FancyzonesHighlightOpacity.Value = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public HotkeySettings EditorHotkey
|
||||
{
|
||||
get
|
||||
{
|
||||
return _editorHotkey;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _editorHotkey)
|
||||
{
|
||||
if (value == null || value.IsEmpty())
|
||||
{
|
||||
_editorHotkey = FZConfigProperties.DefaultEditorHotkeyValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
_editorHotkey = value;
|
||||
}
|
||||
|
||||
Settings.Properties.FancyzonesEditorHotkey.Value = _editorHotkey;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool WindowSwitching
|
||||
{
|
||||
get
|
||||
{
|
||||
return _windowSwitching;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _windowSwitching)
|
||||
{
|
||||
_windowSwitching = value;
|
||||
|
||||
Settings.Properties.FancyzonesWindowSwitching.Value = _windowSwitching;
|
||||
NotifyPropertyChanged();
|
||||
OnPropertyChanged(nameof(WindowSwitchingCategoryEnabled));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public HotkeySettings NextTabHotkey
|
||||
{
|
||||
get
|
||||
{
|
||||
return _nextTabHotkey;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _nextTabHotkey)
|
||||
{
|
||||
if (value == null || value.IsEmpty())
|
||||
{
|
||||
_nextTabHotkey = FZConfigProperties.DefaultNextTabHotkeyValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
_nextTabHotkey = value;
|
||||
}
|
||||
|
||||
Settings.Properties.FancyzonesNextTabHotkey.Value = _nextTabHotkey;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public HotkeySettings PrevTabHotkey
|
||||
{
|
||||
get
|
||||
{
|
||||
return _prevTabHotkey;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _prevTabHotkey)
|
||||
{
|
||||
if (value == null || value.IsEmpty())
|
||||
{
|
||||
_prevTabHotkey = FZConfigProperties.DefaultPrevTabHotkeyValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
_prevTabHotkey = value;
|
||||
}
|
||||
|
||||
Settings.Properties.FancyzonesPrevTabHotkey.Value = _prevTabHotkey;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string ExcludedApps
|
||||
{
|
||||
get
|
||||
{
|
||||
return _excludedApps;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _excludedApps)
|
||||
{
|
||||
_excludedApps = value;
|
||||
Settings.Properties.FancyzonesExcludedApps.Value = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool Windows11 => _windows11;
|
||||
|
||||
private void LaunchEditor()
|
||||
{
|
||||
// send message to launch the zones editor;
|
||||
SendConfigMSG("{\"action\":{\"FancyZones\":{\"action_name\":\"ToggledFZEditor\", \"value\":\"\"}}}");
|
||||
}
|
||||
|
||||
public void NotifyPropertyChanged([CallerMemberName] string propertyName = null)
|
||||
{
|
||||
OnPropertyChanged(propertyName);
|
||||
SettingsUtils.SaveSettings(Settings.ToJsonString(), GetSettingsSubPath());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,889 +0,0 @@
|
||||
// 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.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.IO.Abstractions;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.ViewModels.Commands;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
|
||||
{
|
||||
public class GeneralViewModel : Observable
|
||||
{
|
||||
private GeneralSettings GeneralSettingsConfig { get; set; }
|
||||
|
||||
private UpdatingSettings UpdatingSettingsConfig { get; set; }
|
||||
|
||||
public ButtonClickCommand CheckForUpdatesEventHandler { get; set; }
|
||||
|
||||
public object ResourceLoader { get; set; }
|
||||
|
||||
private Action HideBackupAndRestoreMessageAreaAction { get; set; }
|
||||
|
||||
private Action<int> DoBackupAndRestoreDryRun { get; set; }
|
||||
|
||||
public ButtonClickCommand BackupConfigsEventHandler { get; set; }
|
||||
|
||||
public ButtonClickCommand RestoreConfigsEventHandler { get; set; }
|
||||
|
||||
public ButtonClickCommand RefreshBackupStatusEventHandler { get; set; }
|
||||
|
||||
public ButtonClickCommand SelectSettingBackupDirEventHandler { get; set; }
|
||||
|
||||
public ButtonClickCommand RestartElevatedButtonEventHandler { get; set; }
|
||||
|
||||
public ButtonClickCommand UpdateNowButtonEventHandler { get; set; }
|
||||
|
||||
public Func<string, int> UpdateUIThemeCallBack { get; }
|
||||
|
||||
public Func<string, int> SendConfigMSG { get; }
|
||||
|
||||
public Func<string, int> SendRestartAsAdminConfigMSG { get; }
|
||||
|
||||
public Func<string, int> SendCheckForUpdatesConfigMSG { get; }
|
||||
|
||||
public string RunningAsUserDefaultText { get; set; }
|
||||
|
||||
public string RunningAsAdminDefaultText { get; set; }
|
||||
|
||||
private string _settingsConfigFileFolder = string.Empty;
|
||||
|
||||
private IFileSystemWatcher _fileWatcher;
|
||||
|
||||
private Func<Task<string>> PickSingleFolderDialog { get; }
|
||||
|
||||
private SettingsBackupAndRestoreUtils settingsBackupAndRestoreUtils = SettingsBackupAndRestoreUtils.Instance;
|
||||
|
||||
public GeneralViewModel(ISettingsRepository<GeneralSettings> settingsRepository, string runAsAdminText, string runAsUserText, bool isElevated, bool isAdmin, Func<string, int> updateTheme, Func<string, int> ipcMSGCallBackFunc, Func<string, int> ipcMSGRestartAsAdminMSGCallBackFunc, Func<string, int> ipcMSGCheckForUpdatesCallBackFunc, string configFileSubfolder = "", Action dispatcherAction = null, Action hideBackupAndRestoreMessageAreaAction = null, Action<int> doBackupAndRestoreDryRun = null, Func<Task<string>> pickSingleFolderDialog = null, object resourceLoader = null)
|
||||
{
|
||||
CheckForUpdatesEventHandler = new ButtonClickCommand(CheckForUpdatesClick);
|
||||
RestartElevatedButtonEventHandler = new ButtonClickCommand(RestartElevated);
|
||||
UpdateNowButtonEventHandler = new ButtonClickCommand(UpdateNowClick);
|
||||
BackupConfigsEventHandler = new ButtonClickCommand(BackupConfigsClick);
|
||||
SelectSettingBackupDirEventHandler = new ButtonClickCommand(SelectSettingBackupDir);
|
||||
RestoreConfigsEventHandler = new ButtonClickCommand(RestoreConfigsClick);
|
||||
RefreshBackupStatusEventHandler = new ButtonClickCommand(RefreshBackupStatusEventHandlerClick);
|
||||
HideBackupAndRestoreMessageAreaAction = hideBackupAndRestoreMessageAreaAction;
|
||||
DoBackupAndRestoreDryRun = doBackupAndRestoreDryRun;
|
||||
PickSingleFolderDialog = pickSingleFolderDialog;
|
||||
ResourceLoader = resourceLoader;
|
||||
|
||||
// To obtain the general settings configuration of PowerToys if it exists, else to create a new file and return the default configurations.
|
||||
if (settingsRepository == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(settingsRepository));
|
||||
}
|
||||
|
||||
GeneralSettingsConfig = settingsRepository.SettingsConfig;
|
||||
UpdatingSettingsConfig = UpdatingSettings.LoadSettings();
|
||||
if (UpdatingSettingsConfig == null)
|
||||
{
|
||||
UpdatingSettingsConfig = new UpdatingSettings();
|
||||
}
|
||||
|
||||
// set the callback functions value to hangle outgoing IPC message.
|
||||
SendConfigMSG = ipcMSGCallBackFunc;
|
||||
SendCheckForUpdatesConfigMSG = ipcMSGCheckForUpdatesCallBackFunc;
|
||||
SendRestartAsAdminConfigMSG = ipcMSGRestartAsAdminMSGCallBackFunc;
|
||||
|
||||
// set the callback function value to update the UI theme.
|
||||
UpdateUIThemeCallBack = updateTheme;
|
||||
|
||||
UpdateUIThemeCallBack(GeneralSettingsConfig.Theme);
|
||||
|
||||
// Update Settings file folder:
|
||||
_settingsConfigFileFolder = configFileSubfolder;
|
||||
|
||||
// Using Invariant here as these are internal strings and the analyzer
|
||||
// expects strings to be normalized to uppercase. While the theme names
|
||||
// are represented in lowercase everywhere else, we'll use uppercase
|
||||
// normalization for switch statements
|
||||
switch (GeneralSettingsConfig.Theme.ToUpperInvariant())
|
||||
{
|
||||
case "DARK":
|
||||
_themeIndex = 0;
|
||||
break;
|
||||
case "LIGHT":
|
||||
_themeIndex = 1;
|
||||
break;
|
||||
case "SYSTEM":
|
||||
_themeIndex = 2;
|
||||
break;
|
||||
}
|
||||
|
||||
_startup = GeneralSettingsConfig.Startup;
|
||||
_autoDownloadUpdates = GeneralSettingsConfig.AutoDownloadUpdates;
|
||||
|
||||
_isElevated = isElevated;
|
||||
_runElevated = GeneralSettingsConfig.RunElevated;
|
||||
|
||||
RunningAsUserDefaultText = runAsUserText;
|
||||
RunningAsAdminDefaultText = runAsAdminText;
|
||||
|
||||
_isAdmin = isAdmin;
|
||||
|
||||
_updatingState = UpdatingSettingsConfig.State;
|
||||
_newAvailableVersion = UpdatingSettingsConfig.NewVersion;
|
||||
_newAvailableVersionLink = UpdatingSettingsConfig.ReleasePageLink;
|
||||
_updateCheckedDate = UpdatingSettingsConfig.LastCheckedDateLocalized;
|
||||
|
||||
if (dispatcherAction != null)
|
||||
{
|
||||
_fileWatcher = Helper.GetFileWatcher(string.Empty, UpdatingSettings.SettingsFile, dispatcherAction);
|
||||
}
|
||||
}
|
||||
|
||||
private bool _startup;
|
||||
private bool _isElevated;
|
||||
private bool _runElevated;
|
||||
private bool _isAdmin;
|
||||
private int _themeIndex;
|
||||
|
||||
private bool _autoDownloadUpdates;
|
||||
|
||||
private UpdatingSettings.UpdatingState _updatingState = UpdatingSettings.UpdatingState.UpToDate;
|
||||
private string _newAvailableVersion = string.Empty;
|
||||
private string _newAvailableVersionLink = string.Empty;
|
||||
private string _updateCheckedDate = string.Empty;
|
||||
|
||||
private bool _isNewVersionDownloading;
|
||||
private bool _isNewVersionChecked;
|
||||
|
||||
private bool _settingsBackupRestoreMessageVisible;
|
||||
private string _settingsBackupMessage;
|
||||
private string _backupRestoreMessageSeverity;
|
||||
|
||||
// Gets or sets a value indicating whether run powertoys on start-up.
|
||||
public bool Startup
|
||||
{
|
||||
get
|
||||
{
|
||||
return _startup;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (_startup != value)
|
||||
{
|
||||
_startup = value;
|
||||
GeneralSettingsConfig.Startup = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string RunningAsText
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!IsElevated)
|
||||
{
|
||||
return RunningAsUserDefaultText;
|
||||
}
|
||||
else
|
||||
{
|
||||
return RunningAsAdminDefaultText;
|
||||
}
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
OnPropertyChanged("RunningAsAdminText");
|
||||
}
|
||||
}
|
||||
|
||||
// Gets or sets a value indicating whether the powertoy elevated.
|
||||
public bool IsElevated
|
||||
{
|
||||
get
|
||||
{
|
||||
return _isElevated;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (_isElevated != value)
|
||||
{
|
||||
_isElevated = value;
|
||||
OnPropertyChanged(nameof(IsElevated));
|
||||
OnPropertyChanged(nameof(IsAdminButtonEnabled));
|
||||
OnPropertyChanged("RunningAsAdminText");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsAdminButtonEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
return !IsElevated;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
OnPropertyChanged(nameof(IsAdminButtonEnabled));
|
||||
}
|
||||
}
|
||||
|
||||
// Gets or sets a value indicating whether powertoys should run elevated.
|
||||
public bool RunElevated
|
||||
{
|
||||
get
|
||||
{
|
||||
return _runElevated;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (_runElevated != value)
|
||||
{
|
||||
_runElevated = value;
|
||||
GeneralSettingsConfig.RunElevated = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Gets a value indicating whether the user is part of administrators group.
|
||||
public bool IsAdmin
|
||||
{
|
||||
get
|
||||
{
|
||||
return _isAdmin;
|
||||
}
|
||||
}
|
||||
|
||||
public bool AutoDownloadUpdates
|
||||
{
|
||||
get
|
||||
{
|
||||
return _autoDownloadUpdates;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (_autoDownloadUpdates != value)
|
||||
{
|
||||
_autoDownloadUpdates = value;
|
||||
GeneralSettingsConfig.AutoDownloadUpdates = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static bool AutoUpdatesEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
return Helper.GetProductVersion() != "v0.0.1";
|
||||
}
|
||||
}
|
||||
|
||||
public string SettingsBackupAndRestoreDir
|
||||
{
|
||||
get
|
||||
{
|
||||
return settingsBackupAndRestoreUtils.GetSettingsBackupAndRestoreDir();
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (settingsBackupAndRestoreUtils.GetSettingsBackupAndRestoreDir() != value)
|
||||
{
|
||||
SettingsBackupAndRestoreUtils.SetRegSettingsBackupAndRestoreItem("SettingsBackupAndRestoreDir", value);
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int ThemeIndex
|
||||
{
|
||||
get
|
||||
{
|
||||
return _themeIndex;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (_themeIndex != value)
|
||||
{
|
||||
switch (value)
|
||||
{
|
||||
case 0: GeneralSettingsConfig.Theme = "dark"; break;
|
||||
case 1: GeneralSettingsConfig.Theme = "light"; break;
|
||||
case 2: GeneralSettingsConfig.Theme = "system"; break;
|
||||
}
|
||||
|
||||
_themeIndex = value;
|
||||
|
||||
try
|
||||
{
|
||||
UpdateUIThemeCallBack(GeneralSettingsConfig.Theme);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.LogError("Exception encountered when changing Settings theme", e);
|
||||
}
|
||||
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string PowerToysVersion
|
||||
{
|
||||
get
|
||||
{
|
||||
return Helper.GetProductVersion();
|
||||
}
|
||||
}
|
||||
|
||||
public string UpdateCheckedDate
|
||||
{
|
||||
get
|
||||
{
|
||||
RequestUpdateCheckedDate();
|
||||
return _updateCheckedDate;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (_updateCheckedDate != value)
|
||||
{
|
||||
_updateCheckedDate = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string LastSettingsBackupDate
|
||||
{
|
||||
get
|
||||
{
|
||||
try
|
||||
{
|
||||
var manifest = settingsBackupAndRestoreUtils.GetLatestSettingsBackupManifest();
|
||||
if (manifest != null)
|
||||
{
|
||||
if (manifest["CreateDateTime"] != null)
|
||||
{
|
||||
if (DateTime.TryParse(manifest["CreateDateTime"].ToString(), CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal, out var theDateTime))
|
||||
{
|
||||
return theDateTime.ToString("G", CultureInfo.CurrentCulture);
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.LogError("Failed to parse time from backup");
|
||||
return GetResourceString("General_SettingsBackupAndRestore_FailedToParseTime");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return GetResourceString("General_SettingsBackupAndRestore_UnknownBackupTime");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return GetResourceString("General_SettingsBackupAndRestore_NoBackupFound");
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.LogError("Error getting LastSettingsBackupDate", e);
|
||||
return GetResourceString("General_SettingsBackupAndRestore_UnknownBackupTime");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string CurrentSettingMatchText
|
||||
{
|
||||
get
|
||||
{
|
||||
try
|
||||
{
|
||||
var results = settingsBackupAndRestoreUtils.GetLastBackupSettingsResults();
|
||||
|
||||
var resultText = string.Empty;
|
||||
|
||||
if (!results.lastRan.HasValue)
|
||||
{
|
||||
// not ran since started.
|
||||
return GetResourceString("General_SettingsBackupAndRestore_CurrentSettingsNoChecked"); // "Current Settings Unknown";
|
||||
}
|
||||
else
|
||||
{
|
||||
if (results.success)
|
||||
{
|
||||
if (results.lastBackupExists)
|
||||
{
|
||||
// if true, it means a backup would have been made
|
||||
resultText = GetResourceString("General_SettingsBackupAndRestore_CurrentSettingsDiffer"); // "Current Settings Differ";
|
||||
}
|
||||
else
|
||||
{
|
||||
// would have done the backup, but there also was not an existing one there.
|
||||
resultText = GetResourceString("General_SettingsBackupAndRestore_NoBackupFound");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (results.hadError)
|
||||
{
|
||||
// if false and error we don't really know
|
||||
resultText = GetResourceString("General_SettingsBackupAndRestore_CurrentSettingsUnknown"); // "Current Settings Unknown";
|
||||
}
|
||||
else
|
||||
{
|
||||
// if false, it means a backup would not have been needed/made
|
||||
resultText = GetResourceString("General_SettingsBackupAndRestore_CurrentSettingsMatch"); // "Current Settings Match";
|
||||
}
|
||||
}
|
||||
|
||||
return $"{resultText} {GetResourceString("General_SettingsBackupAndRestore_CurrentSettingsStatusAt")} {results.lastRan.Value.ToLocalTime().ToString("G", CultureInfo.CurrentCulture)}";
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.LogError("Error getting CurrentSettingMatchText", e);
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string LastSettingsBackupSource
|
||||
{
|
||||
get
|
||||
{
|
||||
try
|
||||
{
|
||||
var manifest = settingsBackupAndRestoreUtils.GetLatestSettingsBackupManifest();
|
||||
if (manifest != null)
|
||||
{
|
||||
if (manifest["BackupSource"] != null)
|
||||
{
|
||||
if (manifest["BackupSource"].ToString().Equals(Environment.MachineName, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return GetResourceString("General_SettingsBackupAndRestore_ThisMachine");
|
||||
}
|
||||
else
|
||||
{
|
||||
return manifest["BackupSource"].ToString();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return GetResourceString("General_SettingsBackupAndRestore_UnknownBackupSource");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return GetResourceString("General_SettingsBackupAndRestore_NoBackupFound");
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.LogError("Error getting LastSettingsBackupSource", e);
|
||||
return GetResourceString("General_SettingsBackupAndRestore_UnknownBackupSource");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string LastSettingsBackupFileName
|
||||
{
|
||||
get
|
||||
{
|
||||
try
|
||||
{
|
||||
var fileName = settingsBackupAndRestoreUtils.GetLatestBackupFileName();
|
||||
return !string.IsNullOrEmpty(fileName) ? fileName : GetResourceString("General_SettingsBackupAndRestore_NoBackupFound");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.LogError("Error getting LastSettingsBackupFileName", e);
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public UpdatingSettings.UpdatingState PowerToysUpdatingState
|
||||
{
|
||||
get
|
||||
{
|
||||
return _updatingState;
|
||||
}
|
||||
|
||||
private set
|
||||
{
|
||||
if (value != _updatingState)
|
||||
{
|
||||
_updatingState = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string PowerToysNewAvailableVersion
|
||||
{
|
||||
get
|
||||
{
|
||||
return _newAvailableVersion;
|
||||
}
|
||||
|
||||
private set
|
||||
{
|
||||
if (value != _newAvailableVersion)
|
||||
{
|
||||
_newAvailableVersion = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string PowerToysNewAvailableVersionLink
|
||||
{
|
||||
get
|
||||
{
|
||||
return _newAvailableVersionLink;
|
||||
}
|
||||
|
||||
private set
|
||||
{
|
||||
if (value != _newAvailableVersionLink)
|
||||
{
|
||||
_newAvailableVersionLink = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsNewVersionDownloading
|
||||
{
|
||||
get
|
||||
{
|
||||
return _isNewVersionDownloading;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _isNewVersionDownloading)
|
||||
{
|
||||
_isNewVersionDownloading = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsNewVersionCheckedAndUpToDate
|
||||
{
|
||||
get
|
||||
{
|
||||
return _isNewVersionChecked;
|
||||
}
|
||||
}
|
||||
|
||||
public bool SettingsBackupRestoreMessageVisible
|
||||
{
|
||||
get
|
||||
{
|
||||
return _settingsBackupRestoreMessageVisible;
|
||||
}
|
||||
}
|
||||
|
||||
public string BackupRestoreMessageSeverity
|
||||
{
|
||||
get
|
||||
{
|
||||
return _backupRestoreMessageSeverity;
|
||||
}
|
||||
}
|
||||
|
||||
public string SettingsBackupMessage
|
||||
{
|
||||
get
|
||||
{
|
||||
return _settingsBackupMessage;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsDownloadAllowed
|
||||
{
|
||||
get
|
||||
{
|
||||
return AutoUpdatesEnabled && !IsNewVersionDownloading;
|
||||
}
|
||||
}
|
||||
|
||||
public void NotifyPropertyChanged([CallerMemberName] string propertyName = null, bool reDoBackupDryRun = true)
|
||||
{
|
||||
// Notify UI of property change
|
||||
OnPropertyChanged(propertyName);
|
||||
|
||||
OutGoingGeneralSettings outsettings = new OutGoingGeneralSettings(GeneralSettingsConfig);
|
||||
|
||||
SendConfigMSG(outsettings.ToString());
|
||||
|
||||
if (reDoBackupDryRun && DoBackupAndRestoreDryRun != null)
|
||||
{
|
||||
DoBackupAndRestoreDryRun(500);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Method <c>SelectSettingBackupDir</c> opens folder browser to select a backup and retore location.
|
||||
/// </summary>
|
||||
private async void SelectSettingBackupDir()
|
||||
{
|
||||
var currentDir = settingsBackupAndRestoreUtils.GetSettingsBackupAndRestoreDir();
|
||||
|
||||
var newPath = await PickSingleFolderDialog();
|
||||
|
||||
if (!string.IsNullOrEmpty(newPath))
|
||||
{
|
||||
SettingsBackupAndRestoreDir = newPath;
|
||||
NotifyAllBackupAndRestoreProperties();
|
||||
}
|
||||
}
|
||||
|
||||
private void RefreshBackupStatusEventHandlerClick()
|
||||
{
|
||||
DoBackupAndRestoreDryRun(0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Method <c>RestoreConfigsClick</c> starts the restore.
|
||||
/// </summary>
|
||||
private void RestoreConfigsClick()
|
||||
{
|
||||
string settingsBackupAndRestoreDir = settingsBackupAndRestoreUtils.GetSettingsBackupAndRestoreDir();
|
||||
|
||||
if (string.IsNullOrEmpty(settingsBackupAndRestoreDir))
|
||||
{
|
||||
SelectSettingBackupDir();
|
||||
}
|
||||
|
||||
var results = SettingsUtils.RestoreSettings();
|
||||
_backupRestoreMessageSeverity = results.severity;
|
||||
|
||||
if (!results.success)
|
||||
{
|
||||
_settingsBackupRestoreMessageVisible = true;
|
||||
|
||||
_settingsBackupMessage = GetResourceString(results.message);
|
||||
|
||||
NotifyAllBackupAndRestoreProperties();
|
||||
|
||||
HideBackupAndRestoreMessageAreaAction();
|
||||
}
|
||||
else
|
||||
{
|
||||
// make sure not to do NotifyPropertyChanged here, else it will persist the configs from memory and
|
||||
// undo the settings restore.
|
||||
SettingsBackupAndRestoreUtils.SetRegSettingsBackupAndRestoreItem("LastSettingsRestoreDate", DateTime.UtcNow.ToString("u", CultureInfo.InvariantCulture));
|
||||
|
||||
Restart();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Method <c>BackupConfigsClick</c> starts the backup.
|
||||
/// </summary>
|
||||
private void BackupConfigsClick()
|
||||
{
|
||||
string settingsBackupAndRestoreDir = settingsBackupAndRestoreUtils.GetSettingsBackupAndRestoreDir();
|
||||
|
||||
if (string.IsNullOrEmpty(settingsBackupAndRestoreDir))
|
||||
{
|
||||
SelectSettingBackupDir();
|
||||
}
|
||||
|
||||
var results = SettingsUtils.BackupSettings();
|
||||
|
||||
_settingsBackupRestoreMessageVisible = true;
|
||||
_backupRestoreMessageSeverity = results.severity;
|
||||
_settingsBackupMessage = GetResourceString(results.message);
|
||||
|
||||
// now we do a dry run to get the results for "setting match"
|
||||
var settingsUtils = new SettingsUtils();
|
||||
var appBasePath = Path.GetDirectoryName(settingsUtils.GetSettingsFilePath());
|
||||
settingsBackupAndRestoreUtils.BackupSettings(appBasePath, settingsBackupAndRestoreDir, true);
|
||||
|
||||
NotifyAllBackupAndRestoreProperties();
|
||||
|
||||
HideBackupAndRestoreMessageAreaAction();
|
||||
}
|
||||
|
||||
public void NotifyAllBackupAndRestoreProperties()
|
||||
{
|
||||
NotifyPropertyChanged(nameof(LastSettingsBackupDate), false);
|
||||
NotifyPropertyChanged(nameof(LastSettingsBackupSource), false);
|
||||
NotifyPropertyChanged(nameof(LastSettingsBackupFileName), false);
|
||||
NotifyPropertyChanged(nameof(CurrentSettingMatchText), false);
|
||||
NotifyPropertyChanged(nameof(SettingsBackupMessage), false);
|
||||
NotifyPropertyChanged(nameof(BackupRestoreMessageSeverity), false);
|
||||
NotifyPropertyChanged(nameof(SettingsBackupRestoreMessageVisible), false);
|
||||
}
|
||||
|
||||
// callback function to launch the URL to check for updates.
|
||||
private void CheckForUpdatesClick()
|
||||
{
|
||||
RefreshUpdatingState();
|
||||
IsNewVersionDownloading = string.IsNullOrEmpty(UpdatingSettingsConfig.DownloadedInstallerFilename);
|
||||
NotifyPropertyChanged(nameof(IsDownloadAllowed));
|
||||
|
||||
if (_isNewVersionChecked)
|
||||
{
|
||||
_isNewVersionChecked = !IsNewVersionDownloading;
|
||||
NotifyPropertyChanged(nameof(IsNewVersionCheckedAndUpToDate));
|
||||
}
|
||||
|
||||
GeneralSettingsConfig.CustomActionName = "check_for_updates";
|
||||
|
||||
OutGoingGeneralSettings outsettings = new OutGoingGeneralSettings(GeneralSettingsConfig);
|
||||
GeneralSettingsCustomAction customaction = new GeneralSettingsCustomAction(outsettings);
|
||||
|
||||
SendCheckForUpdatesConfigMSG(customaction.ToString());
|
||||
}
|
||||
|
||||
private void UpdateNowClick()
|
||||
{
|
||||
IsNewVersionDownloading = string.IsNullOrEmpty(UpdatingSettingsConfig.DownloadedInstallerFilename);
|
||||
NotifyPropertyChanged(nameof(IsDownloadAllowed));
|
||||
|
||||
Process.Start(new ProcessStartInfo(Helper.GetPowerToysInstallationFolder() + "\\PowerToys.exe") { Arguments = "powertoys://update_now/" });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Class <c>GetResourceString</c> gets a localized text.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// To do: see if there is a betting way to do this, there should be. It does allow us to return missing localization in a way that makes it obvious they were missed.
|
||||
/// </remarks>
|
||||
public string GetResourceString(string resource)
|
||||
{
|
||||
if (ResourceLoader != null)
|
||||
{
|
||||
var type = ResourceLoader.GetType();
|
||||
MethodInfo methodInfo = type.GetMethod("GetString");
|
||||
object classInstance = Activator.CreateInstance(type, null);
|
||||
object[] parametersArray = new object[] { resource };
|
||||
var result = (string)methodInfo.Invoke(ResourceLoader, parametersArray);
|
||||
if (string.IsNullOrEmpty(result))
|
||||
{
|
||||
return resource.ToUpperInvariant() + "!!!";
|
||||
}
|
||||
else
|
||||
{
|
||||
return result;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return resource;
|
||||
}
|
||||
}
|
||||
|
||||
public void RequestUpdateCheckedDate()
|
||||
{
|
||||
GeneralSettingsConfig.CustomActionName = "request_update_state_date";
|
||||
|
||||
OutGoingGeneralSettings outsettings = new OutGoingGeneralSettings(GeneralSettingsConfig);
|
||||
GeneralSettingsCustomAction customaction = new GeneralSettingsCustomAction(outsettings);
|
||||
|
||||
SendCheckForUpdatesConfigMSG(customaction.ToString());
|
||||
}
|
||||
|
||||
public void RestartElevated()
|
||||
{
|
||||
GeneralSettingsConfig.CustomActionName = "restart_elevation";
|
||||
|
||||
OutGoingGeneralSettings outsettings = new OutGoingGeneralSettings(GeneralSettingsConfig);
|
||||
GeneralSettingsCustomAction customaction = new GeneralSettingsCustomAction(outsettings);
|
||||
|
||||
SendRestartAsAdminConfigMSG(customaction.ToString());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Class <c>Restart</c> begin a restart and signal we want to maintain elevation
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Other restarts either raised or lowered elevation
|
||||
/// </remarks>
|
||||
public void Restart()
|
||||
{
|
||||
GeneralSettingsConfig.CustomActionName = "restart_maintain_elevation";
|
||||
|
||||
OutGoingGeneralSettings outsettings = new OutGoingGeneralSettings(GeneralSettingsConfig);
|
||||
GeneralSettingsCustomAction customaction = new GeneralSettingsCustomAction(outsettings);
|
||||
|
||||
var dataToSend = customaction.ToString();
|
||||
dataToSend = JsonSerializer.Serialize(new { action = new { general = new { action_name = "restart_maintain_elevation" } } });
|
||||
SendRestartAsAdminConfigMSG(dataToSend);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Class <c>HideBackupAndRestoreMessageArea</c> hides the backup/restore message area
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// We want to have it go away after a short period.
|
||||
/// </remarks>
|
||||
public void HideBackupAndRestoreMessageArea()
|
||||
{
|
||||
_settingsBackupRestoreMessageVisible = false;
|
||||
NotifyAllBackupAndRestoreProperties();
|
||||
}
|
||||
|
||||
public void RefreshUpdatingState()
|
||||
{
|
||||
object oLock = new object();
|
||||
lock (oLock)
|
||||
{
|
||||
var config = UpdatingSettings.LoadSettings();
|
||||
|
||||
// Retry loading if failed
|
||||
for (int i = 0; i < 3 && config == null; i++)
|
||||
{
|
||||
System.Threading.Thread.Sleep(100);
|
||||
config = UpdatingSettings.LoadSettings();
|
||||
}
|
||||
|
||||
if (config == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
UpdatingSettingsConfig = config;
|
||||
|
||||
if (PowerToysUpdatingState != config.State)
|
||||
{
|
||||
IsNewVersionDownloading = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
bool dateChanged = UpdateCheckedDate == UpdatingSettingsConfig.LastCheckedDateLocalized;
|
||||
bool fileDownloaded = string.IsNullOrEmpty(UpdatingSettingsConfig.DownloadedInstallerFilename);
|
||||
IsNewVersionDownloading = !(dateChanged || fileDownloaded);
|
||||
}
|
||||
|
||||
PowerToysUpdatingState = UpdatingSettingsConfig.State;
|
||||
PowerToysNewAvailableVersion = UpdatingSettingsConfig.NewVersion;
|
||||
PowerToysNewAvailableVersionLink = UpdatingSettingsConfig.ReleasePageLink;
|
||||
UpdateCheckedDate = UpdatingSettingsConfig.LastCheckedDateLocalized;
|
||||
|
||||
_isNewVersionChecked = PowerToysUpdatingState == UpdatingSettings.UpdatingState.UpToDate && !IsNewVersionDownloading;
|
||||
NotifyPropertyChanged(nameof(IsNewVersionCheckedAndUpToDate));
|
||||
|
||||
NotifyPropertyChanged(nameof(IsDownloadAllowed));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,115 +0,0 @@
|
||||
// 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.Runtime.CompilerServices;
|
||||
using Microsoft.PowerToys.Settings.UI.Library;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.ViewModels.Commands;
|
||||
using Settings.UI.Library.Enumerations;
|
||||
|
||||
namespace Settings.UI.Library.ViewModels
|
||||
{
|
||||
public class HostsViewModel : Observable
|
||||
{
|
||||
private bool _isElevated;
|
||||
|
||||
private ISettingsUtils SettingsUtils { get; set; }
|
||||
|
||||
private GeneralSettings GeneralSettingsConfig { get; set; }
|
||||
|
||||
private HostsSettings Settings { get; set; }
|
||||
|
||||
private Func<string, int> SendConfigMSG { get; }
|
||||
|
||||
public ButtonClickCommand LaunchEventHandler => new ButtonClickCommand(Launch);
|
||||
|
||||
public bool IsEnabled
|
||||
{
|
||||
get => GeneralSettingsConfig.Enabled.Hosts;
|
||||
|
||||
set
|
||||
{
|
||||
if (value != GeneralSettingsConfig.Enabled.Hosts)
|
||||
{
|
||||
// Set the status in the general settings configuration
|
||||
GeneralSettingsConfig.Enabled.Hosts = value;
|
||||
OutGoingGeneralSettings snd = new OutGoingGeneralSettings(GeneralSettingsConfig);
|
||||
|
||||
SendConfigMSG(snd.ToString());
|
||||
OnPropertyChanged(nameof(IsEnabled));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool LaunchAdministratorEnabled => IsEnabled && !_isElevated;
|
||||
|
||||
public bool ShowStartupWarning
|
||||
{
|
||||
get => Settings.Properties.ShowStartupWarning;
|
||||
set
|
||||
{
|
||||
if (value != Settings.Properties.ShowStartupWarning)
|
||||
{
|
||||
Settings.Properties.ShowStartupWarning = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool LaunchAdministrator
|
||||
{
|
||||
get => Settings.Properties.LaunchAdministrator;
|
||||
set
|
||||
{
|
||||
if (value != Settings.Properties.LaunchAdministrator)
|
||||
{
|
||||
Settings.Properties.LaunchAdministrator = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int AdditionalLinesPosition
|
||||
{
|
||||
get => (int)Settings.Properties.AdditionalLinesPosition;
|
||||
set
|
||||
{
|
||||
if (value != (int)Settings.Properties.AdditionalLinesPosition)
|
||||
{
|
||||
Settings.Properties.AdditionalLinesPosition = (AdditionalLinesPosition)value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public HostsViewModel(ISettingsUtils settingsUtils, ISettingsRepository<GeneralSettings> settingsRepository, ISettingsRepository<HostsSettings> moduleSettingsRepository, Func<string, int> ipcMSGCallBackFunc, bool isElevated)
|
||||
{
|
||||
SettingsUtils = settingsUtils;
|
||||
GeneralSettingsConfig = settingsRepository.SettingsConfig;
|
||||
Settings = moduleSettingsRepository.SettingsConfig;
|
||||
SendConfigMSG = ipcMSGCallBackFunc;
|
||||
_isElevated = isElevated;
|
||||
}
|
||||
|
||||
public void Launch()
|
||||
{
|
||||
var actionName = "Launch";
|
||||
|
||||
if (!_isElevated && LaunchAdministrator)
|
||||
{
|
||||
actionName = "LaunchAdministrator";
|
||||
}
|
||||
|
||||
SendConfigMSG("{\"action\":{\"Hosts\":{\"action_name\":\"" + actionName + "\", \"value\":\"\"}}}");
|
||||
}
|
||||
|
||||
public void NotifyPropertyChanged([CallerMemberName] string propertyName = null)
|
||||
{
|
||||
OnPropertyChanged(propertyName);
|
||||
SettingsUtils.SaveSettings(Settings.ToJsonString(), HostsSettings.ModuleName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,398 +0,0 @@
|
||||
// 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.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
|
||||
{
|
||||
public class ImageResizerViewModel : Observable
|
||||
{
|
||||
private GeneralSettings GeneralSettingsConfig { get; set; }
|
||||
|
||||
private readonly ISettingsUtils _settingsUtils;
|
||||
|
||||
private ImageResizerSettings Settings { get; set; }
|
||||
|
||||
private const string ModuleName = ImageResizerSettings.ModuleName;
|
||||
|
||||
private Func<string, int> SendConfigMSG { get; }
|
||||
|
||||
public ImageResizerViewModel(ISettingsUtils settingsUtils, ISettingsRepository<GeneralSettings> settingsRepository, Func<string, int> ipcMSGCallBackFunc, Func<string, string> resourceLoader)
|
||||
{
|
||||
_settingsUtils = settingsUtils ?? throw new ArgumentNullException(nameof(settingsUtils));
|
||||
|
||||
// To obtain the general settings configurations of PowerToys.
|
||||
if (settingsRepository == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(settingsRepository));
|
||||
}
|
||||
|
||||
GeneralSettingsConfig = settingsRepository.SettingsConfig;
|
||||
|
||||
try
|
||||
{
|
||||
Settings = _settingsUtils.GetSettings<ImageResizerSettings>(ModuleName);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.LogError($"Exception encountered while reading {ModuleName} settings.", e);
|
||||
#if DEBUG
|
||||
if (e is ArgumentException || e is ArgumentNullException || e is PathTooLongException)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
#endif
|
||||
Settings = new ImageResizerSettings(resourceLoader);
|
||||
_settingsUtils.SaveSettings(Settings.ToJsonString(), ModuleName);
|
||||
}
|
||||
|
||||
// set the callback functions value to hangle outgoing IPC message.
|
||||
SendConfigMSG = ipcMSGCallBackFunc;
|
||||
|
||||
_isEnabled = GeneralSettingsConfig.Enabled.ImageResizer;
|
||||
_advancedSizes = Settings.Properties.ImageresizerSizes.Value;
|
||||
_jpegQualityLevel = Settings.Properties.ImageresizerJpegQualityLevel.Value;
|
||||
_pngInterlaceOption = Settings.Properties.ImageresizerPngInterlaceOption.Value;
|
||||
_tiffCompressOption = Settings.Properties.ImageresizerTiffCompressOption.Value;
|
||||
_fileName = Settings.Properties.ImageresizerFileName.Value;
|
||||
_keepDateModified = Settings.Properties.ImageresizerKeepDateModified.Value;
|
||||
_encoderGuidId = GetEncoderIndex(Settings.Properties.ImageresizerFallbackEncoder.Value);
|
||||
|
||||
int i = 0;
|
||||
foreach (ImageSize size in _advancedSizes)
|
||||
{
|
||||
size.Id = i;
|
||||
i++;
|
||||
size.PropertyChanged += SizePropertyChanged;
|
||||
}
|
||||
}
|
||||
|
||||
private bool _isEnabled;
|
||||
private ObservableCollection<ImageSize> _advancedSizes = new ObservableCollection<ImageSize>();
|
||||
private int _jpegQualityLevel;
|
||||
private int _pngInterlaceOption;
|
||||
private int _tiffCompressOption;
|
||||
private string _fileName;
|
||||
private bool _keepDateModified;
|
||||
private int _encoderGuidId;
|
||||
|
||||
public bool IsListViewFocusRequested { get; set; }
|
||||
|
||||
public bool IsEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
return _isEnabled;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _isEnabled)
|
||||
{
|
||||
// To set the status of ImageResizer in the General PowerToys settings.
|
||||
_isEnabled = value;
|
||||
GeneralSettingsConfig.Enabled.ImageResizer = value;
|
||||
OutGoingGeneralSettings snd = new OutGoingGeneralSettings(GeneralSettingsConfig);
|
||||
|
||||
SendConfigMSG(snd.ToString());
|
||||
OnPropertyChanged(nameof(IsEnabled));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ObservableCollection<ImageSize> Sizes
|
||||
{
|
||||
get
|
||||
{
|
||||
return _advancedSizes;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
SavesImageSizes(value);
|
||||
_advancedSizes = value;
|
||||
OnPropertyChanged(nameof(Sizes));
|
||||
}
|
||||
}
|
||||
|
||||
public int JPEGQualityLevel
|
||||
{
|
||||
get
|
||||
{
|
||||
return _jpegQualityLevel;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (_jpegQualityLevel != value)
|
||||
{
|
||||
_jpegQualityLevel = value;
|
||||
Settings.Properties.ImageresizerJpegQualityLevel.Value = value;
|
||||
_settingsUtils.SaveSettings(Settings.ToJsonString(), ModuleName);
|
||||
OnPropertyChanged(nameof(JPEGQualityLevel));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int PngInterlaceOption
|
||||
{
|
||||
get
|
||||
{
|
||||
return _pngInterlaceOption;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (_pngInterlaceOption != value)
|
||||
{
|
||||
_pngInterlaceOption = value;
|
||||
Settings.Properties.ImageresizerPngInterlaceOption.Value = value;
|
||||
_settingsUtils.SaveSettings(Settings.ToJsonString(), ModuleName);
|
||||
OnPropertyChanged(nameof(PngInterlaceOption));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int TiffCompressOption
|
||||
{
|
||||
get
|
||||
{
|
||||
return _tiffCompressOption;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (_tiffCompressOption != value)
|
||||
{
|
||||
_tiffCompressOption = value;
|
||||
Settings.Properties.ImageresizerTiffCompressOption.Value = value;
|
||||
_settingsUtils.SaveSettings(Settings.ToJsonString(), ModuleName);
|
||||
OnPropertyChanged(nameof(TiffCompressOption));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string FileName
|
||||
{
|
||||
get
|
||||
{
|
||||
return _fileName;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(value))
|
||||
{
|
||||
_fileName = value;
|
||||
Settings.Properties.ImageresizerFileName.Value = value;
|
||||
_settingsUtils.SaveSettings(Settings.ToJsonString(), ModuleName);
|
||||
OnPropertyChanged(nameof(FileName));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool KeepDateModified
|
||||
{
|
||||
get
|
||||
{
|
||||
return _keepDateModified;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_keepDateModified = value;
|
||||
Settings.Properties.ImageresizerKeepDateModified.Value = value;
|
||||
_settingsUtils.SaveSettings(Settings.ToJsonString(), ModuleName);
|
||||
OnPropertyChanged(nameof(KeepDateModified));
|
||||
}
|
||||
}
|
||||
|
||||
public int Encoder
|
||||
{
|
||||
get
|
||||
{
|
||||
return _encoderGuidId;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (_encoderGuidId != value)
|
||||
{
|
||||
_encoderGuidId = value;
|
||||
_settingsUtils.SaveSettings(Settings.Properties.ImageresizerSizes.ToJsonString(), ModuleName, "sizes.json");
|
||||
Settings.Properties.ImageresizerFallbackEncoder.Value = GetEncoderGuid(value);
|
||||
_settingsUtils.SaveSettings(Settings.ToJsonString(), ModuleName);
|
||||
OnPropertyChanged(nameof(Encoder));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string EncoderGuid
|
||||
{
|
||||
get
|
||||
{
|
||||
return ImageResizerViewModel.GetEncoderGuid(_encoderGuidId);
|
||||
}
|
||||
}
|
||||
|
||||
public void AddRow(string sizeNamePrefix)
|
||||
{
|
||||
/// This is a fallback validation to eliminate the warning "CA1062:Validate arguments of public methods" when using the parameter (variable) "sizeNamePrefix" in the code.
|
||||
/// If the parameter is unexpectedly empty or null, we fill the parameter with a non-localized string.
|
||||
/// Normally the parameter "sizeNamePrefix" can't be null or empty because it is filled with a localized string when we call this method from <see cref="UI.Views.ImageResizerPage.AddSizeButton_Click"/>.
|
||||
sizeNamePrefix = string.IsNullOrEmpty(sizeNamePrefix) ? "New Size" : sizeNamePrefix;
|
||||
|
||||
ObservableCollection<ImageSize> imageSizes = Sizes;
|
||||
int maxId = imageSizes.Count > 0 ? imageSizes.OrderBy(x => x.Id).Last().Id : -1;
|
||||
string sizeName = GenerateNameForNewSize(imageSizes, sizeNamePrefix);
|
||||
|
||||
ImageSize newSize = new ImageSize(maxId + 1, sizeName, ResizeFit.Fit, 854, 480, ResizeUnit.Pixel);
|
||||
newSize.PropertyChanged += SizePropertyChanged;
|
||||
imageSizes.Add(newSize);
|
||||
_advancedSizes = imageSizes;
|
||||
SavesImageSizes(imageSizes);
|
||||
|
||||
// Set the focus requested flag to indicate that an add operation has occurred during the ContainerContentChanging event
|
||||
IsListViewFocusRequested = true;
|
||||
}
|
||||
|
||||
public void DeleteImageSize(int id)
|
||||
{
|
||||
ImageSize size = _advancedSizes.First(x => x.Id == id);
|
||||
ObservableCollection<ImageSize> imageSizes = Sizes;
|
||||
imageSizes.Remove(size);
|
||||
|
||||
_advancedSizes = imageSizes;
|
||||
SavesImageSizes(imageSizes);
|
||||
}
|
||||
|
||||
public void SavesImageSizes(ObservableCollection<ImageSize> imageSizes)
|
||||
{
|
||||
_settingsUtils.SaveSettings(Settings.Properties.ImageresizerSizes.ToJsonString(), ModuleName, "sizes.json");
|
||||
Settings.Properties.ImageresizerSizes = new ImageResizerSizes(imageSizes);
|
||||
_settingsUtils.SaveSettings(Settings.ToJsonString(), ModuleName);
|
||||
}
|
||||
|
||||
public static string GetEncoderGuid(int value)
|
||||
{
|
||||
// PNG Encoder guid
|
||||
if (value == 0)
|
||||
{
|
||||
return "1b7cfaf4-713f-473c-bbcd-6137425faeaf";
|
||||
}
|
||||
|
||||
// Bitmap Encoder guid
|
||||
else if (value == 1)
|
||||
{
|
||||
return "0af1d87e-fcfe-4188-bdeb-a7906471cbe3";
|
||||
}
|
||||
|
||||
// JPEG Encoder guid
|
||||
else if (value == 2)
|
||||
{
|
||||
return "19e4a5aa-5662-4fc5-a0c0-1758028e1057";
|
||||
}
|
||||
|
||||
// Tiff encoder guid.
|
||||
else if (value == 3)
|
||||
{
|
||||
return "163bcc30-e2e9-4f0b-961d-a3e9fdb788a3";
|
||||
}
|
||||
|
||||
// Tiff encoder guid.
|
||||
else if (value == 4)
|
||||
{
|
||||
return "57a37caa-367a-4540-916b-f183c5093a4b";
|
||||
}
|
||||
|
||||
// Gif encoder guid.
|
||||
else if (value == 5)
|
||||
{
|
||||
return "1f8a5601-7d4d-4cbd-9c82-1bc8d4eeb9a5";
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static int GetEncoderIndex(string value)
|
||||
{
|
||||
// PNG Encoder guid
|
||||
if (value == "1b7cfaf4-713f-473c-bbcd-6137425faeaf")
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Bitmap Encoder guid
|
||||
else if (value == "0af1d87e-fcfe-4188-bdeb-a7906471cbe3")
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
// JPEG Encoder guid
|
||||
else if (value == "19e4a5aa-5662-4fc5-a0c0-1758028e1057")
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
// Tiff encoder guid.
|
||||
else if (value == "163bcc30-e2e9-4f0b-961d-a3e9fdb788a3")
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
|
||||
// Tiff encoder guid.
|
||||
else if (value == "57a37caa-367a-4540-916b-f183c5093a4b")
|
||||
{
|
||||
return 4;
|
||||
}
|
||||
|
||||
// Gif encoder guid.
|
||||
else if (value == "1f8a5601-7d4d-4cbd-9c82-1bc8d4eeb9a5")
|
||||
{
|
||||
return 5;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
public void SizePropertyChanged(object sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
ImageSize modifiedSize = (ImageSize)sender;
|
||||
ObservableCollection<ImageSize> imageSizes = Sizes;
|
||||
imageSizes.First(x => x.Id == modifiedSize.Id).Update(modifiedSize);
|
||||
_advancedSizes = imageSizes;
|
||||
SavesImageSizes(imageSizes);
|
||||
}
|
||||
|
||||
private static string GenerateNameForNewSize(in ObservableCollection<ImageSize> sizesList, in string namePrefix)
|
||||
{
|
||||
int newSizeCounter = 0;
|
||||
|
||||
foreach (ImageSize imgSize in sizesList)
|
||||
{
|
||||
string name = imgSize.Name;
|
||||
|
||||
if (name.StartsWith(namePrefix, StringComparison.InvariantCulture))
|
||||
{
|
||||
if (int.TryParse(name.AsSpan(namePrefix.Length), out int number))
|
||||
{
|
||||
if (newSizeCounter < number)
|
||||
{
|
||||
newSizeCounter = number;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $"{namePrefix} {++newSizeCounter}";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,315 +0,0 @@
|
||||
// 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;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.ViewModels.Commands;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
|
||||
{
|
||||
public class KeyboardManagerViewModel : Observable
|
||||
{
|
||||
private GeneralSettings GeneralSettingsConfig { get; set; }
|
||||
|
||||
private readonly ISettingsUtils _settingsUtils;
|
||||
|
||||
private const string PowerToyName = KeyboardManagerSettings.ModuleName;
|
||||
private const string JsonFileType = ".json";
|
||||
|
||||
private const string KeyboardManagerEditorPath = "modules\\KeyboardManager\\KeyboardManagerEditor\\PowerToys.KeyboardManagerEditor.exe";
|
||||
private Process editor;
|
||||
|
||||
private enum KeyboardManagerEditorType
|
||||
{
|
||||
KeyEditor = 0,
|
||||
ShortcutEditor,
|
||||
}
|
||||
|
||||
public KeyboardManagerSettings Settings { get; set; }
|
||||
|
||||
private ICommand _remapKeyboardCommand;
|
||||
private ICommand _editShortcutCommand;
|
||||
private KeyboardManagerProfile _profile;
|
||||
|
||||
private Func<string, int> SendConfigMSG { get; }
|
||||
|
||||
private Func<List<KeysDataModel>, int> FilterRemapKeysList { get; }
|
||||
|
||||
public KeyboardManagerViewModel(ISettingsUtils settingsUtils, ISettingsRepository<GeneralSettings> settingsRepository, Func<string, int> ipcMSGCallBackFunc, Func<List<KeysDataModel>, int> filterRemapKeysList)
|
||||
{
|
||||
if (settingsRepository == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(settingsRepository));
|
||||
}
|
||||
|
||||
GeneralSettingsConfig = settingsRepository.SettingsConfig;
|
||||
|
||||
// set the callback functions value to hangle outgoing IPC message.
|
||||
SendConfigMSG = ipcMSGCallBackFunc;
|
||||
FilterRemapKeysList = filterRemapKeysList;
|
||||
|
||||
_settingsUtils = settingsUtils ?? throw new ArgumentNullException(nameof(settingsUtils));
|
||||
|
||||
if (_settingsUtils.SettingsExists(PowerToyName))
|
||||
{
|
||||
try
|
||||
{
|
||||
Settings = _settingsUtils.GetSettingsOrDefault<KeyboardManagerSettings>(PowerToyName);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.LogError($"Exception encountered while reading {PowerToyName} settings.", e);
|
||||
#if DEBUG
|
||||
if (e is ArgumentException || e is ArgumentNullException || e is PathTooLongException)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// Load profile.
|
||||
if (!LoadProfile())
|
||||
{
|
||||
_profile = new KeyboardManagerProfile();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Settings = new KeyboardManagerSettings();
|
||||
_settingsUtils.SaveSettings(Settings.ToJsonString(), PowerToyName);
|
||||
}
|
||||
}
|
||||
|
||||
public bool Enabled
|
||||
{
|
||||
get
|
||||
{
|
||||
return GeneralSettingsConfig.Enabled.KeyboardManager;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (GeneralSettingsConfig.Enabled.KeyboardManager != value)
|
||||
{
|
||||
GeneralSettingsConfig.Enabled.KeyboardManager = value;
|
||||
OnPropertyChanged(nameof(Enabled));
|
||||
|
||||
if (!Enabled && editor != null)
|
||||
{
|
||||
editor.CloseMainWindow();
|
||||
}
|
||||
|
||||
OutGoingGeneralSettings outgoing = new OutGoingGeneralSettings(GeneralSettingsConfig);
|
||||
|
||||
SendConfigMSG(outgoing.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// store remappings
|
||||
public List<KeysDataModel> RemapKeys
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_profile != null)
|
||||
{
|
||||
return _profile.RemapKeys.InProcessRemapKeys;
|
||||
}
|
||||
else
|
||||
{
|
||||
return new List<KeysDataModel>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static List<AppSpecificKeysDataModel> CombineShortcutLists(List<KeysDataModel> globalShortcutList, List<AppSpecificKeysDataModel> appSpecificShortcutList)
|
||||
{
|
||||
if (globalShortcutList == null && appSpecificShortcutList == null)
|
||||
{
|
||||
return new List<AppSpecificKeysDataModel>();
|
||||
}
|
||||
else if (globalShortcutList == null)
|
||||
{
|
||||
return appSpecificShortcutList;
|
||||
}
|
||||
else if (appSpecificShortcutList == null)
|
||||
{
|
||||
return globalShortcutList.ConvertAll(x => new AppSpecificKeysDataModel { OriginalKeys = x.OriginalKeys, NewRemapKeys = x.NewRemapKeys, TargetApp = "All Apps" }).ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
return globalShortcutList.ConvertAll(x => new AppSpecificKeysDataModel { OriginalKeys = x.OriginalKeys, NewRemapKeys = x.NewRemapKeys, TargetApp = "All Apps" }).Concat(appSpecificShortcutList).ToList();
|
||||
}
|
||||
}
|
||||
|
||||
public List<AppSpecificKeysDataModel> RemapShortcuts
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_profile != null)
|
||||
{
|
||||
return CombineShortcutLists(_profile.RemapShortcuts.GlobalRemapShortcuts, _profile.RemapShortcuts.AppSpecificRemapShortcuts);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new List<AppSpecificKeysDataModel>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ICommand RemapKeyboardCommand => _remapKeyboardCommand ?? (_remapKeyboardCommand = new RelayCommand(OnRemapKeyboard));
|
||||
|
||||
public ICommand EditShortcutCommand => _editShortcutCommand ?? (_editShortcutCommand = new RelayCommand(OnEditShortcut));
|
||||
|
||||
private void OnRemapKeyboard()
|
||||
{
|
||||
OpenEditor((int)KeyboardManagerEditorType.KeyEditor);
|
||||
}
|
||||
|
||||
private void OnEditShortcut()
|
||||
{
|
||||
OpenEditor((int)KeyboardManagerEditorType.ShortcutEditor);
|
||||
}
|
||||
|
||||
private static void BringProcessToFront(Process process)
|
||||
{
|
||||
if (process == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
IntPtr handle = process.MainWindowHandle;
|
||||
if (NativeMethods.IsIconic(handle))
|
||||
{
|
||||
NativeMethods.ShowWindow(handle, NativeMethods.SWRESTORE);
|
||||
}
|
||||
|
||||
NativeMethods.SetForegroundWindow(handle);
|
||||
}
|
||||
|
||||
private void OpenEditor(int type)
|
||||
{
|
||||
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
|
||||
editor = Process.Start(path, $"{type.ToString(CultureInfo.InvariantCulture)} {Environment.ProcessId}");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.LogError($"Exception encountered when opening an {PowerToyName} editor", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void NotifyFileChanged()
|
||||
{
|
||||
OnPropertyChanged(nameof(RemapKeys));
|
||||
OnPropertyChanged(nameof(RemapShortcuts));
|
||||
}
|
||||
|
||||
public bool LoadProfile()
|
||||
{
|
||||
var success = true;
|
||||
var readSuccessfully = false;
|
||||
|
||||
// The KBM process out of runner doesn't create the default.json file if it does not exist.
|
||||
string fileName = Settings.Properties.ActiveConfiguration.Value + JsonFileType;
|
||||
var profileExists = false;
|
||||
|
||||
try
|
||||
{
|
||||
// retry loop for reading
|
||||
CancellationTokenSource ts = new CancellationTokenSource();
|
||||
Task t = Task.Run(() =>
|
||||
{
|
||||
while (!readSuccessfully && !ts.IsCancellationRequested)
|
||||
{
|
||||
profileExists = _settingsUtils.SettingsExists(PowerToyName, fileName);
|
||||
if (!profileExists)
|
||||
{
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
_profile = _settingsUtils.GetSettingsOrDefault<KeyboardManagerProfile>(PowerToyName, fileName);
|
||||
readSuccessfully = true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.LogError($"Exception encountered when reading {PowerToyName} settings", e);
|
||||
}
|
||||
}
|
||||
|
||||
if (!readSuccessfully)
|
||||
{
|
||||
Task.Delay(500, ts.Token).Wait(ts.Token);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var completedInTime = t.Wait(3000, ts.Token);
|
||||
ts.Cancel();
|
||||
ts.Dispose();
|
||||
|
||||
if (readSuccessfully)
|
||||
{
|
||||
FilterRemapKeysList(_profile?.RemapKeys?.InProcessRemapKeys);
|
||||
}
|
||||
else
|
||||
{
|
||||
success = false;
|
||||
}
|
||||
|
||||
if (!completedInTime)
|
||||
{
|
||||
Logger.LogError($"Timeout encountered when loading {PowerToyName} profile");
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// Failed to load the configuration.
|
||||
Logger.LogError($"Exception encountered when loading {PowerToyName} profile", e);
|
||||
success = false;
|
||||
}
|
||||
|
||||
if (!profileExists)
|
||||
{
|
||||
Logger.LogInfo($"Couldn't load {PowerToyName} profile because it doesn't exist");
|
||||
}
|
||||
else if (!success)
|
||||
{
|
||||
Logger.LogError($"Couldn't load {PowerToyName} profile");
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,210 +0,0 @@
|
||||
// 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.Globalization;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text.Json;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
|
||||
{
|
||||
public class MeasureToolViewModel : Observable
|
||||
{
|
||||
private ISettingsUtils SettingsUtils { get; set; }
|
||||
|
||||
private GeneralSettings GeneralSettingsConfig { get; set; }
|
||||
|
||||
private MeasureToolSettings Settings { get; set; }
|
||||
|
||||
public MeasureToolViewModel(ISettingsUtils settingsUtils, ISettingsRepository<GeneralSettings> settingsRepository, ISettingsRepository<MeasureToolSettings> measureToolSettingsRepository, Func<string, int> ipcMSGCallBackFunc)
|
||||
{
|
||||
SettingsUtils = settingsUtils;
|
||||
|
||||
if (settingsRepository == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(settingsRepository));
|
||||
}
|
||||
|
||||
GeneralSettingsConfig = settingsRepository.SettingsConfig;
|
||||
|
||||
if (measureToolSettingsRepository == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(measureToolSettingsRepository));
|
||||
}
|
||||
|
||||
Settings = measureToolSettingsRepository.SettingsConfig;
|
||||
|
||||
SendConfigMSG = ipcMSGCallBackFunc;
|
||||
}
|
||||
|
||||
public bool IsEnabled
|
||||
{
|
||||
get => GeneralSettingsConfig.Enabled.MeasureTool;
|
||||
set
|
||||
{
|
||||
if (GeneralSettingsConfig.Enabled.MeasureTool != value)
|
||||
{
|
||||
GeneralSettingsConfig.Enabled.MeasureTool = value;
|
||||
OnPropertyChanged(nameof(IsEnabled));
|
||||
|
||||
OutGoingGeneralSettings outgoing = new OutGoingGeneralSettings(GeneralSettingsConfig);
|
||||
SendConfigMSG(outgoing.ToString());
|
||||
|
||||
NotifyPropertyChanged();
|
||||
NotifyPropertyChanged(nameof(ShowContinuousCaptureWarning));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool ContinuousCapture
|
||||
{
|
||||
get
|
||||
{
|
||||
return Settings.Properties.ContinuousCapture;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (Settings.Properties.ContinuousCapture != value)
|
||||
{
|
||||
Settings.Properties.ContinuousCapture = value;
|
||||
NotifyPropertyChanged();
|
||||
NotifyPropertyChanged(nameof(ShowContinuousCaptureWarning));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool DrawFeetOnCross
|
||||
{
|
||||
get
|
||||
{
|
||||
return Settings.Properties.DrawFeetOnCross;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (Settings.Properties.DrawFeetOnCross != value)
|
||||
{
|
||||
Settings.Properties.DrawFeetOnCross = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string CrossColor
|
||||
{
|
||||
get
|
||||
{
|
||||
return Settings.Properties.MeasureCrossColor.Value;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
value = (value != null) ? SettingsUtilities.ToRGBHex(value) : "#FF4500";
|
||||
if (!value.Equals(Settings.Properties.MeasureCrossColor.Value, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
Settings.Properties.MeasureCrossColor.Value = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool PerColorChannelEdgeDetection
|
||||
{
|
||||
get
|
||||
{
|
||||
return Settings.Properties.PerColorChannelEdgeDetection;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (Settings.Properties.PerColorChannelEdgeDetection != value)
|
||||
{
|
||||
Settings.Properties.PerColorChannelEdgeDetection = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int UnitsOfMeasure
|
||||
{
|
||||
get
|
||||
{
|
||||
return Settings.Properties.UnitsOfMeasure.Value;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (Settings.Properties.UnitsOfMeasure.Value != value)
|
||||
{
|
||||
Settings.Properties.UnitsOfMeasure.Value = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int PixelTolerance
|
||||
{
|
||||
get
|
||||
{
|
||||
return Settings.Properties.PixelTolerance.Value;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (Settings.Properties.PixelTolerance.Value != value)
|
||||
{
|
||||
Settings.Properties.PixelTolerance.Value = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public HotkeySettings ActivationShortcut
|
||||
{
|
||||
get
|
||||
{
|
||||
return Settings.Properties.ActivationShortcut;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (Settings.Properties.ActivationShortcut != value)
|
||||
{
|
||||
Settings.Properties.ActivationShortcut = value;
|
||||
|
||||
NotifyPropertyChanged();
|
||||
|
||||
SendConfigMSG(
|
||||
string.Format(
|
||||
CultureInfo.InvariantCulture,
|
||||
"{{ \"powertoys\": {{ \"{0}\": {1} }} }}",
|
||||
MeasureToolSettings.ModuleName,
|
||||
JsonSerializer.Serialize(Settings)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void NotifyPropertyChanged([CallerMemberName] string propertyName = null)
|
||||
{
|
||||
OnPropertyChanged(propertyName);
|
||||
if (propertyName == nameof(ShowContinuousCaptureWarning))
|
||||
{
|
||||
// Don't trigger a settings update if the changed property is for visual notification.
|
||||
return;
|
||||
}
|
||||
|
||||
SettingsUtils.SaveSettings(Settings.ToJsonString(), MeasureToolSettings.ModuleName);
|
||||
}
|
||||
|
||||
public bool ShowContinuousCaptureWarning
|
||||
{
|
||||
get => IsEnabled && ContinuousCapture;
|
||||
}
|
||||
|
||||
private Func<string, int> SendConfigMSG { get; }
|
||||
}
|
||||
}
|
||||
@@ -1,661 +0,0 @@
|
||||
// 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.Runtime.CompilerServices;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
|
||||
{
|
||||
public class MouseUtilsViewModel : Observable
|
||||
{
|
||||
private ISettingsUtils SettingsUtils { get; set; }
|
||||
|
||||
private GeneralSettings GeneralSettingsConfig { get; set; }
|
||||
|
||||
private FindMyMouseSettings FindMyMouseSettingsConfig { get; set; }
|
||||
|
||||
private MouseHighlighterSettings MouseHighlighterSettingsConfig { get; set; }
|
||||
|
||||
private MousePointerCrosshairsSettings MousePointerCrosshairsSettingsConfig { get; set; }
|
||||
|
||||
public MouseUtilsViewModel(ISettingsUtils settingsUtils, ISettingsRepository<GeneralSettings> settingsRepository, ISettingsRepository<FindMyMouseSettings> findMyMouseSettingsRepository, ISettingsRepository<MouseHighlighterSettings> mouseHighlighterSettingsRepository, ISettingsRepository<MousePointerCrosshairsSettings> mousePointerCrosshairsSettingsRepository, Func<string, int> ipcMSGCallBackFunc)
|
||||
{
|
||||
SettingsUtils = settingsUtils;
|
||||
|
||||
// To obtain the general settings configurations of PowerToys Settings.
|
||||
if (settingsRepository == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(settingsRepository));
|
||||
}
|
||||
|
||||
GeneralSettingsConfig = settingsRepository.SettingsConfig;
|
||||
|
||||
_isFindMyMouseEnabled = GeneralSettingsConfig.Enabled.FindMyMouse;
|
||||
|
||||
_isMouseHighlighterEnabled = GeneralSettingsConfig.Enabled.MouseHighlighter;
|
||||
|
||||
_isMousePointerCrosshairsEnabled = GeneralSettingsConfig.Enabled.MousePointerCrosshairs;
|
||||
|
||||
// To obtain the find my mouse settings, if the file exists.
|
||||
// If not, to create a file with the default settings and to return the default configurations.
|
||||
if (findMyMouseSettingsRepository == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(findMyMouseSettingsRepository));
|
||||
}
|
||||
|
||||
FindMyMouseSettingsConfig = findMyMouseSettingsRepository.SettingsConfig;
|
||||
_findMyMouseActivationMethod = FindMyMouseSettingsConfig.Properties.ActivationMethod.Value;
|
||||
_findMyMouseDoNotActivateOnGameMode = FindMyMouseSettingsConfig.Properties.DoNotActivateOnGameMode.Value;
|
||||
|
||||
string backgroundColor = FindMyMouseSettingsConfig.Properties.BackgroundColor.Value;
|
||||
_findMyMouseBackgroundColor = !string.IsNullOrEmpty(backgroundColor) ? backgroundColor : "#000000";
|
||||
|
||||
string spotlightColor = FindMyMouseSettingsConfig.Properties.SpotlightColor.Value;
|
||||
_findMyMouseSpotlightColor = !string.IsNullOrEmpty(spotlightColor) ? spotlightColor : "#FFFFFF";
|
||||
|
||||
_findMyMouseOverlayOpacity = FindMyMouseSettingsConfig.Properties.OverlayOpacity.Value;
|
||||
_findMyMouseSpotlightRadius = FindMyMouseSettingsConfig.Properties.SpotlightRadius.Value;
|
||||
_findMyMouseAnimationDurationMs = FindMyMouseSettingsConfig.Properties.AnimationDurationMs.Value;
|
||||
_findMyMouseSpotlightInitialZoom = FindMyMouseSettingsConfig.Properties.SpotlightInitialZoom.Value;
|
||||
_findMyMouseExcludedApps = FindMyMouseSettingsConfig.Properties.ExcludedApps.Value;
|
||||
_findMyMouseShakingMinimumDistance = FindMyMouseSettingsConfig.Properties.ShakingMinimumDistance.Value;
|
||||
|
||||
if (mouseHighlighterSettingsRepository == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(mouseHighlighterSettingsRepository));
|
||||
}
|
||||
|
||||
MouseHighlighterSettingsConfig = mouseHighlighterSettingsRepository.SettingsConfig;
|
||||
string leftClickColor = MouseHighlighterSettingsConfig.Properties.LeftButtonClickColor.Value;
|
||||
_highlighterLeftButtonClickColor = !string.IsNullOrEmpty(leftClickColor) ? leftClickColor : "#FFFF00";
|
||||
|
||||
string rightClickColor = MouseHighlighterSettingsConfig.Properties.RightButtonClickColor.Value;
|
||||
_highlighterRightButtonClickColor = !string.IsNullOrEmpty(rightClickColor) ? rightClickColor : "#0000FF";
|
||||
|
||||
_highlighterOpacity = MouseHighlighterSettingsConfig.Properties.HighlightOpacity.Value;
|
||||
_highlighterRadius = MouseHighlighterSettingsConfig.Properties.HighlightRadius.Value;
|
||||
_highlightFadeDelayMs = MouseHighlighterSettingsConfig.Properties.HighlightFadeDelayMs.Value;
|
||||
_highlightFadeDurationMs = MouseHighlighterSettingsConfig.Properties.HighlightFadeDurationMs.Value;
|
||||
|
||||
if (mousePointerCrosshairsSettingsRepository == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(mousePointerCrosshairsSettingsRepository));
|
||||
}
|
||||
|
||||
MousePointerCrosshairsSettingsConfig = mousePointerCrosshairsSettingsRepository.SettingsConfig;
|
||||
|
||||
string crosshairsColor = MousePointerCrosshairsSettingsConfig.Properties.CrosshairsColor.Value;
|
||||
_mousePointerCrosshairsColor = !string.IsNullOrEmpty(crosshairsColor) ? crosshairsColor : "#FF0000";
|
||||
|
||||
string crosshairsBorderColor = MousePointerCrosshairsSettingsConfig.Properties.CrosshairsBorderColor.Value;
|
||||
_mousePointerCrosshairsBorderColor = !string.IsNullOrEmpty(crosshairsBorderColor) ? crosshairsBorderColor : "#FFFFFF";
|
||||
|
||||
_mousePointerCrosshairsOpacity = MousePointerCrosshairsSettingsConfig.Properties.CrosshairsOpacity.Value;
|
||||
_mousePointerCrosshairsRadius = MousePointerCrosshairsSettingsConfig.Properties.CrosshairsRadius.Value;
|
||||
_mousePointerCrosshairsThickness = MousePointerCrosshairsSettingsConfig.Properties.CrosshairsThickness.Value;
|
||||
_mousePointerCrosshairsBorderSize = MousePointerCrosshairsSettingsConfig.Properties.CrosshairsBorderSize.Value;
|
||||
|
||||
// set the callback functions value to handle outgoing IPC message.
|
||||
SendConfigMSG = ipcMSGCallBackFunc;
|
||||
}
|
||||
|
||||
public bool IsFindMyMouseEnabled
|
||||
{
|
||||
get => _isFindMyMouseEnabled;
|
||||
set
|
||||
{
|
||||
if (_isFindMyMouseEnabled != value)
|
||||
{
|
||||
_isFindMyMouseEnabled = value;
|
||||
|
||||
GeneralSettingsConfig.Enabled.FindMyMouse = value;
|
||||
OnPropertyChanged(nameof(IsFindMyMouseEnabled));
|
||||
|
||||
OutGoingGeneralSettings outgoing = new OutGoingGeneralSettings(GeneralSettingsConfig);
|
||||
SendConfigMSG(outgoing.ToString());
|
||||
|
||||
NotifyFindMyMousePropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int FindMyMouseActivationMethod
|
||||
{
|
||||
get
|
||||
{
|
||||
return _findMyMouseActivationMethod;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _findMyMouseActivationMethod)
|
||||
{
|
||||
_findMyMouseActivationMethod = value;
|
||||
FindMyMouseSettingsConfig.Properties.ActivationMethod.Value = value;
|
||||
NotifyFindMyMousePropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool FindMyMouseDoNotActivateOnGameMode
|
||||
{
|
||||
get
|
||||
{
|
||||
return _findMyMouseDoNotActivateOnGameMode;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (_findMyMouseDoNotActivateOnGameMode != value)
|
||||
{
|
||||
_findMyMouseDoNotActivateOnGameMode = value;
|
||||
FindMyMouseSettingsConfig.Properties.DoNotActivateOnGameMode.Value = value;
|
||||
NotifyFindMyMousePropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string FindMyMouseBackgroundColor
|
||||
{
|
||||
get
|
||||
{
|
||||
return _findMyMouseBackgroundColor;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
value = (value != null) ? SettingsUtilities.ToRGBHex(value) : "#000000";
|
||||
if (!value.Equals(_findMyMouseBackgroundColor, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
_findMyMouseBackgroundColor = value;
|
||||
FindMyMouseSettingsConfig.Properties.BackgroundColor.Value = value;
|
||||
NotifyFindMyMousePropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string FindMyMouseSpotlightColor
|
||||
{
|
||||
get
|
||||
{
|
||||
return _findMyMouseSpotlightColor;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
value = (value != null) ? SettingsUtilities.ToRGBHex(value) : "#FFFFFF";
|
||||
if (!value.Equals(_findMyMouseSpotlightColor, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
_findMyMouseSpotlightColor = value;
|
||||
FindMyMouseSettingsConfig.Properties.SpotlightColor.Value = value;
|
||||
NotifyFindMyMousePropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int FindMyMouseOverlayOpacity
|
||||
{
|
||||
get
|
||||
{
|
||||
return _findMyMouseOverlayOpacity;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _findMyMouseOverlayOpacity)
|
||||
{
|
||||
_findMyMouseOverlayOpacity = value;
|
||||
FindMyMouseSettingsConfig.Properties.OverlayOpacity.Value = value;
|
||||
NotifyFindMyMousePropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int FindMyMouseSpotlightRadius
|
||||
{
|
||||
get
|
||||
{
|
||||
return _findMyMouseSpotlightRadius;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _findMyMouseSpotlightRadius)
|
||||
{
|
||||
_findMyMouseSpotlightRadius = value;
|
||||
FindMyMouseSettingsConfig.Properties.SpotlightRadius.Value = value;
|
||||
NotifyFindMyMousePropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int FindMyMouseAnimationDurationMs
|
||||
{
|
||||
get
|
||||
{
|
||||
return _findMyMouseAnimationDurationMs;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _findMyMouseAnimationDurationMs)
|
||||
{
|
||||
_findMyMouseAnimationDurationMs = value;
|
||||
FindMyMouseSettingsConfig.Properties.AnimationDurationMs.Value = value;
|
||||
NotifyFindMyMousePropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int FindMyMouseSpotlightInitialZoom
|
||||
{
|
||||
get
|
||||
{
|
||||
return _findMyMouseSpotlightInitialZoom;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _findMyMouseSpotlightInitialZoom)
|
||||
{
|
||||
_findMyMouseSpotlightInitialZoom = value;
|
||||
FindMyMouseSettingsConfig.Properties.SpotlightInitialZoom.Value = value;
|
||||
NotifyFindMyMousePropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string FindMyMouseExcludedApps
|
||||
{
|
||||
get
|
||||
{
|
||||
return _findMyMouseExcludedApps;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _findMyMouseExcludedApps)
|
||||
{
|
||||
_findMyMouseExcludedApps = value;
|
||||
FindMyMouseSettingsConfig.Properties.ExcludedApps.Value = value;
|
||||
NotifyFindMyMousePropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int FindMyMouseShakingMinimumDistance
|
||||
{
|
||||
get
|
||||
{
|
||||
return _findMyMouseShakingMinimumDistance;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _findMyMouseShakingMinimumDistance)
|
||||
{
|
||||
_findMyMouseShakingMinimumDistance = value;
|
||||
FindMyMouseSettingsConfig.Properties.ShakingMinimumDistance.Value = value;
|
||||
NotifyFindMyMousePropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void NotifyFindMyMousePropertyChanged([CallerMemberName] string propertyName = null)
|
||||
{
|
||||
OnPropertyChanged(propertyName);
|
||||
|
||||
SndFindMyMouseSettings outsettings = new SndFindMyMouseSettings(FindMyMouseSettingsConfig);
|
||||
SndModuleSettings<SndFindMyMouseSettings> ipcMessage = new SndModuleSettings<SndFindMyMouseSettings>(outsettings);
|
||||
SendConfigMSG(ipcMessage.ToJsonString());
|
||||
SettingsUtils.SaveSettings(FindMyMouseSettingsConfig.ToJsonString(), FindMyMouseSettings.ModuleName);
|
||||
}
|
||||
|
||||
public bool IsMouseHighlighterEnabled
|
||||
{
|
||||
get => _isMouseHighlighterEnabled;
|
||||
set
|
||||
{
|
||||
if (_isMouseHighlighterEnabled != value)
|
||||
{
|
||||
_isMouseHighlighterEnabled = value;
|
||||
|
||||
GeneralSettingsConfig.Enabled.MouseHighlighter = value;
|
||||
OnPropertyChanged(nameof(_isMouseHighlighterEnabled));
|
||||
|
||||
OutGoingGeneralSettings outgoing = new OutGoingGeneralSettings(GeneralSettingsConfig);
|
||||
SendConfigMSG(outgoing.ToString());
|
||||
|
||||
NotifyMouseHighlighterPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public HotkeySettings MouseHighlighterActivationShortcut
|
||||
{
|
||||
get
|
||||
{
|
||||
return MouseHighlighterSettingsConfig.Properties.ActivationShortcut;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (MouseHighlighterSettingsConfig.Properties.ActivationShortcut != value)
|
||||
{
|
||||
MouseHighlighterSettingsConfig.Properties.ActivationShortcut = value;
|
||||
NotifyMouseHighlighterPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string MouseHighlighterLeftButtonClickColor
|
||||
{
|
||||
get
|
||||
{
|
||||
return _highlighterLeftButtonClickColor;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
value = SettingsUtilities.ToRGBHex(value);
|
||||
if (!value.Equals(_highlighterLeftButtonClickColor, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
_highlighterLeftButtonClickColor = value;
|
||||
MouseHighlighterSettingsConfig.Properties.LeftButtonClickColor.Value = value;
|
||||
NotifyMouseHighlighterPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string MouseHighlighterRightButtonClickColor
|
||||
{
|
||||
get
|
||||
{
|
||||
return _highlighterRightButtonClickColor;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
value = SettingsUtilities.ToRGBHex(value);
|
||||
if (!value.Equals(_highlighterRightButtonClickColor, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
_highlighterRightButtonClickColor = value;
|
||||
MouseHighlighterSettingsConfig.Properties.RightButtonClickColor.Value = value;
|
||||
NotifyMouseHighlighterPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int MouseHighlighterOpacity
|
||||
{
|
||||
get
|
||||
{
|
||||
return _highlighterOpacity;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _highlighterOpacity)
|
||||
{
|
||||
_highlighterOpacity = value;
|
||||
MouseHighlighterSettingsConfig.Properties.HighlightOpacity.Value = value;
|
||||
NotifyMouseHighlighterPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int MouseHighlighterRadius
|
||||
{
|
||||
get
|
||||
{
|
||||
return _highlighterRadius;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _highlighterRadius)
|
||||
{
|
||||
_highlighterRadius = value;
|
||||
MouseHighlighterSettingsConfig.Properties.HighlightRadius.Value = value;
|
||||
NotifyMouseHighlighterPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int MouseHighlighterFadeDelayMs
|
||||
{
|
||||
get
|
||||
{
|
||||
return _highlightFadeDelayMs;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _highlightFadeDelayMs)
|
||||
{
|
||||
_highlightFadeDelayMs = value;
|
||||
MouseHighlighterSettingsConfig.Properties.HighlightFadeDelayMs.Value = value;
|
||||
NotifyMouseHighlighterPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int MouseHighlighterFadeDurationMs
|
||||
{
|
||||
get
|
||||
{
|
||||
return _highlightFadeDurationMs;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _highlightFadeDurationMs)
|
||||
{
|
||||
_highlightFadeDurationMs = value;
|
||||
MouseHighlighterSettingsConfig.Properties.HighlightFadeDurationMs.Value = value;
|
||||
NotifyMouseHighlighterPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void NotifyMouseHighlighterPropertyChanged([CallerMemberName] string propertyName = null)
|
||||
{
|
||||
OnPropertyChanged(propertyName);
|
||||
|
||||
SndMouseHighlighterSettings outsettings = new SndMouseHighlighterSettings(MouseHighlighterSettingsConfig);
|
||||
SndModuleSettings<SndMouseHighlighterSettings> ipcMessage = new SndModuleSettings<SndMouseHighlighterSettings>(outsettings);
|
||||
SendConfigMSG(ipcMessage.ToJsonString());
|
||||
SettingsUtils.SaveSettings(MouseHighlighterSettingsConfig.ToJsonString(), MouseHighlighterSettings.ModuleName);
|
||||
}
|
||||
|
||||
public bool IsMousePointerCrosshairsEnabled
|
||||
{
|
||||
get => _isMousePointerCrosshairsEnabled;
|
||||
set
|
||||
{
|
||||
if (_isMousePointerCrosshairsEnabled != value)
|
||||
{
|
||||
_isMousePointerCrosshairsEnabled = value;
|
||||
|
||||
GeneralSettingsConfig.Enabled.MousePointerCrosshairs = value;
|
||||
OnPropertyChanged(nameof(_isMousePointerCrosshairsEnabled));
|
||||
|
||||
OutGoingGeneralSettings outgoing = new OutGoingGeneralSettings(GeneralSettingsConfig);
|
||||
SendConfigMSG(outgoing.ToString());
|
||||
|
||||
NotifyMousePointerCrosshairsPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public HotkeySettings MousePointerCrosshairsActivationShortcut
|
||||
{
|
||||
get
|
||||
{
|
||||
return MousePointerCrosshairsSettingsConfig.Properties.ActivationShortcut;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (MousePointerCrosshairsSettingsConfig.Properties.ActivationShortcut != value)
|
||||
{
|
||||
MousePointerCrosshairsSettingsConfig.Properties.ActivationShortcut = value;
|
||||
NotifyMousePointerCrosshairsPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string MousePointerCrosshairsColor
|
||||
{
|
||||
get
|
||||
{
|
||||
return _mousePointerCrosshairsColor;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
value = SettingsUtilities.ToRGBHex(value);
|
||||
if (!value.Equals(_mousePointerCrosshairsColor, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
_mousePointerCrosshairsColor = value;
|
||||
MousePointerCrosshairsSettingsConfig.Properties.CrosshairsColor.Value = value;
|
||||
NotifyMousePointerCrosshairsPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int MousePointerCrosshairsOpacity
|
||||
{
|
||||
get
|
||||
{
|
||||
return _mousePointerCrosshairsOpacity;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _mousePointerCrosshairsOpacity)
|
||||
{
|
||||
_mousePointerCrosshairsOpacity = value;
|
||||
MousePointerCrosshairsSettingsConfig.Properties.CrosshairsOpacity.Value = value;
|
||||
NotifyMousePointerCrosshairsPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int MousePointerCrosshairsRadius
|
||||
{
|
||||
get
|
||||
{
|
||||
return _mousePointerCrosshairsRadius;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _mousePointerCrosshairsRadius)
|
||||
{
|
||||
_mousePointerCrosshairsRadius = value;
|
||||
MousePointerCrosshairsSettingsConfig.Properties.CrosshairsRadius.Value = value;
|
||||
NotifyMousePointerCrosshairsPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int MousePointerCrosshairsThickness
|
||||
{
|
||||
get
|
||||
{
|
||||
return _mousePointerCrosshairsThickness;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _mousePointerCrosshairsThickness)
|
||||
{
|
||||
_mousePointerCrosshairsThickness = value;
|
||||
MousePointerCrosshairsSettingsConfig.Properties.CrosshairsThickness.Value = value;
|
||||
NotifyMousePointerCrosshairsPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string MousePointerCrosshairsBorderColor
|
||||
{
|
||||
get
|
||||
{
|
||||
return _mousePointerCrosshairsBorderColor;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
value = SettingsUtilities.ToRGBHex(value);
|
||||
if (!value.Equals(_mousePointerCrosshairsBorderColor, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
_mousePointerCrosshairsBorderColor = value;
|
||||
MousePointerCrosshairsSettingsConfig.Properties.CrosshairsBorderColor.Value = value;
|
||||
NotifyMousePointerCrosshairsPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int MousePointerCrosshairsBorderSize
|
||||
{
|
||||
get
|
||||
{
|
||||
return _mousePointerCrosshairsBorderSize;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _mousePointerCrosshairsBorderSize)
|
||||
{
|
||||
_mousePointerCrosshairsBorderSize = value;
|
||||
MousePointerCrosshairsSettingsConfig.Properties.CrosshairsBorderSize.Value = value;
|
||||
NotifyMousePointerCrosshairsPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void NotifyMousePointerCrosshairsPropertyChanged([CallerMemberName] string propertyName = null)
|
||||
{
|
||||
OnPropertyChanged(propertyName);
|
||||
|
||||
SndMousePointerCrosshairsSettings outsettings = new SndMousePointerCrosshairsSettings(MousePointerCrosshairsSettingsConfig);
|
||||
SndModuleSettings<SndMousePointerCrosshairsSettings> ipcMessage = new SndModuleSettings<SndMousePointerCrosshairsSettings>(outsettings);
|
||||
SendConfigMSG(ipcMessage.ToJsonString());
|
||||
SettingsUtils.SaveSettings(MousePointerCrosshairsSettingsConfig.ToJsonString(), MousePointerCrosshairsSettings.ModuleName);
|
||||
}
|
||||
|
||||
private Func<string, int> SendConfigMSG { get; }
|
||||
|
||||
private bool _isFindMyMouseEnabled;
|
||||
private int _findMyMouseActivationMethod;
|
||||
private bool _findMyMouseDoNotActivateOnGameMode;
|
||||
private string _findMyMouseBackgroundColor;
|
||||
private string _findMyMouseSpotlightColor;
|
||||
private int _findMyMouseOverlayOpacity;
|
||||
private int _findMyMouseSpotlightRadius;
|
||||
private int _findMyMouseAnimationDurationMs;
|
||||
private int _findMyMouseSpotlightInitialZoom;
|
||||
private string _findMyMouseExcludedApps;
|
||||
private int _findMyMouseShakingMinimumDistance;
|
||||
|
||||
private bool _isMouseHighlighterEnabled;
|
||||
private string _highlighterLeftButtonClickColor;
|
||||
private string _highlighterRightButtonClickColor;
|
||||
private int _highlighterOpacity;
|
||||
private int _highlighterRadius;
|
||||
private int _highlightFadeDelayMs;
|
||||
private int _highlightFadeDurationMs;
|
||||
|
||||
private bool _isMousePointerCrosshairsEnabled;
|
||||
private string _mousePointerCrosshairsColor;
|
||||
private int _mousePointerCrosshairsOpacity;
|
||||
private int _mousePointerCrosshairsRadius;
|
||||
private int _mousePointerCrosshairsThickness;
|
||||
private string _mousePointerCrosshairsBorderColor;
|
||||
private int _mousePointerCrosshairsBorderSize;
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
// 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.ComponentModel;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
|
||||
{
|
||||
public class PluginAdditionalOptionViewModel : INotifyPropertyChanged
|
||||
{
|
||||
private PluginAdditionalOption _additionalOption;
|
||||
|
||||
internal PluginAdditionalOptionViewModel(PluginAdditionalOption additionalOption)
|
||||
{
|
||||
_additionalOption = additionalOption;
|
||||
}
|
||||
|
||||
public string DisplayLabel { get => _additionalOption.DisplayLabel; }
|
||||
|
||||
public string DisplayDescription { get => _additionalOption.DisplayDescription; }
|
||||
|
||||
public bool Value
|
||||
{
|
||||
get => _additionalOption.Value;
|
||||
set
|
||||
{
|
||||
if (value != _additionalOption.Value)
|
||||
{
|
||||
_additionalOption.Value = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
private void NotifyPropertyChanged([CallerMemberName] string propertyName = "")
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,199 +0,0 @@
|
||||
// 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.Runtime.CompilerServices;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Enumerations;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
|
||||
{
|
||||
public class PowerAccentViewModel : Observable
|
||||
{
|
||||
private GeneralSettings GeneralSettingsConfig { get; set; }
|
||||
|
||||
private readonly PowerAccentSettings _powerAccentSettings;
|
||||
|
||||
private readonly ISettingsUtils _settingsUtils;
|
||||
|
||||
// These should be in the same order as the ComboBoxItems in PowerAccentPage.xaml
|
||||
private readonly string[] _languageOptions =
|
||||
{
|
||||
"ALL",
|
||||
"CUR",
|
||||
"CZ",
|
||||
"FR",
|
||||
"DE",
|
||||
"HU",
|
||||
"IS",
|
||||
"IT",
|
||||
"MI",
|
||||
"PI",
|
||||
"PL",
|
||||
"PT",
|
||||
"RO",
|
||||
"SK",
|
||||
"SP",
|
||||
"TK",
|
||||
};
|
||||
|
||||
private readonly string[] _toolbarOptions =
|
||||
{
|
||||
"Top center",
|
||||
"Bottom center",
|
||||
"Left",
|
||||
"Right",
|
||||
"Top right corner",
|
||||
"Top left corner",
|
||||
"Bottom right corner",
|
||||
"Bottom left corner",
|
||||
"Center",
|
||||
};
|
||||
|
||||
private Func<string, int> SendConfigMSG { get; }
|
||||
|
||||
public PowerAccentViewModel(ISettingsUtils settingsUtils, ISettingsRepository<GeneralSettings> settingsRepository, Func<string, int> ipcMSGCallBackFunc)
|
||||
{
|
||||
// To obtain the general settings configurations of PowerToys Settings.
|
||||
if (settingsRepository == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(settingsRepository));
|
||||
}
|
||||
|
||||
_settingsUtils = settingsUtils ?? throw new ArgumentNullException(nameof(settingsUtils));
|
||||
GeneralSettingsConfig = settingsRepository.SettingsConfig;
|
||||
|
||||
_isEnabled = GeneralSettingsConfig.Enabled.PowerAccent;
|
||||
if (_settingsUtils.SettingsExists(PowerAccentSettings.ModuleName))
|
||||
{
|
||||
_powerAccentSettings = _settingsUtils.GetSettingsOrDefault<PowerAccentSettings>(PowerAccentSettings.ModuleName);
|
||||
}
|
||||
else
|
||||
{
|
||||
_powerAccentSettings = new PowerAccentSettings();
|
||||
}
|
||||
|
||||
_inputTimeMs = _powerAccentSettings.Properties.InputTime.Value;
|
||||
|
||||
_selectedLangIndex = Array.IndexOf(_languageOptions, _powerAccentSettings.Properties.SelectedLang.Value);
|
||||
|
||||
_toolbarPositionIndex = Array.IndexOf(_toolbarOptions, _powerAccentSettings.Properties.ToolbarPosition.Value);
|
||||
|
||||
// set the callback functions value to hangle outgoing IPC message.
|
||||
SendConfigMSG = ipcMSGCallBackFunc;
|
||||
}
|
||||
|
||||
public bool IsEnabled
|
||||
{
|
||||
get => _isEnabled;
|
||||
set
|
||||
{
|
||||
if (_isEnabled != value)
|
||||
{
|
||||
_isEnabled = value;
|
||||
|
||||
GeneralSettingsConfig.Enabled.PowerAccent = value;
|
||||
OnPropertyChanged(nameof(IsEnabled));
|
||||
OutGoingGeneralSettings outgoing = new OutGoingGeneralSettings(GeneralSettingsConfig);
|
||||
SendConfigMSG(outgoing.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int ActivationKey
|
||||
{
|
||||
get
|
||||
{
|
||||
return (int)_powerAccentSettings.Properties.ActivationKey;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != (int)_powerAccentSettings.Properties.ActivationKey)
|
||||
{
|
||||
_powerAccentSettings.Properties.ActivationKey = (PowerAccentActivationKey)value;
|
||||
OnPropertyChanged(nameof(ActivationKey));
|
||||
RaisePropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int _inputTimeMs = 200;
|
||||
|
||||
public int InputTimeMs
|
||||
{
|
||||
get
|
||||
{
|
||||
return _inputTimeMs;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _inputTimeMs)
|
||||
{
|
||||
_inputTimeMs = value;
|
||||
_powerAccentSettings.Properties.InputTime.Value = value;
|
||||
OnPropertyChanged(nameof(InputTimeMs));
|
||||
RaisePropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int _toolbarPositionIndex;
|
||||
|
||||
public int ToolbarPositionIndex
|
||||
{
|
||||
get
|
||||
{
|
||||
return _toolbarPositionIndex;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (_toolbarPositionIndex != value)
|
||||
{
|
||||
_toolbarPositionIndex = value;
|
||||
_powerAccentSettings.Properties.ToolbarPosition.Value = _toolbarOptions[value];
|
||||
RaisePropertyChanged(nameof(ToolbarPositionIndex));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int _selectedLangIndex;
|
||||
|
||||
public int SelectedLangIndex
|
||||
{
|
||||
get
|
||||
{
|
||||
return _selectedLangIndex;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (_selectedLangIndex != value)
|
||||
{
|
||||
_selectedLangIndex = value;
|
||||
_powerAccentSettings.Properties.SelectedLang.Value = _languageOptions[value];
|
||||
RaisePropertyChanged(nameof(SelectedLangIndex));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void RaisePropertyChanged([CallerMemberName] string propertyName = null)
|
||||
{
|
||||
// Notify UI of property change
|
||||
OnPropertyChanged(propertyName);
|
||||
|
||||
if (SendConfigMSG != null)
|
||||
{
|
||||
SndPowerAccentSettings snd = new SndPowerAccentSettings(_powerAccentSettings);
|
||||
SndModuleSettings<SndPowerAccentSettings> ipcMessage = new SndModuleSettings<SndPowerAccentSettings>(snd);
|
||||
SendConfigMSG(ipcMessage.ToJsonString());
|
||||
}
|
||||
}
|
||||
|
||||
private bool _isEnabled;
|
||||
}
|
||||
}
|
||||
@@ -1,187 +0,0 @@
|
||||
// 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;
|
||||
using System.ComponentModel;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
|
||||
{
|
||||
public class PowerLauncherPluginViewModel : INotifyPropertyChanged
|
||||
{
|
||||
private readonly PowerLauncherPluginSettings settings;
|
||||
private readonly Func<bool> isDark;
|
||||
|
||||
public PowerLauncherPluginViewModel(PowerLauncherPluginSettings settings, Func<bool> isDark)
|
||||
{
|
||||
if (settings == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(settings), "PowerLauncherPluginSettings object is null");
|
||||
}
|
||||
|
||||
this.settings = settings;
|
||||
this.isDark = isDark;
|
||||
foreach (var item in AdditionalOptions)
|
||||
{
|
||||
item.PropertyChanged += (object sender, PropertyChangedEventArgs e) =>
|
||||
{
|
||||
NotifyPropertyChanged(nameof(AdditionalOptions));
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public string Id { get => settings.Id; }
|
||||
|
||||
public string Name { get => settings.Name; }
|
||||
|
||||
public string Description { get => settings.Description; }
|
||||
|
||||
public string Author { get => settings.Author; }
|
||||
|
||||
public bool Disabled
|
||||
{
|
||||
get
|
||||
{
|
||||
return settings.Disabled;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (settings.Disabled != value)
|
||||
{
|
||||
settings.Disabled = value;
|
||||
NotifyPropertyChanged();
|
||||
NotifyPropertyChanged(nameof(ShowNotAccessibleWarning));
|
||||
NotifyPropertyChanged(nameof(Enabled));
|
||||
NotifyPropertyChanged(nameof(DisabledOpacity));
|
||||
NotifyPropertyChanged(nameof(IsGlobalAndEnabled));
|
||||
NotifyPropertyChanged(nameof(ShowBadgeOnPluginSettingError));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool Enabled => !Disabled;
|
||||
|
||||
public double DisabledOpacity => Disabled ? 0.5 : 1;
|
||||
|
||||
public bool IsGlobalAndEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
return IsGlobal && Enabled;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsGlobal
|
||||
{
|
||||
get
|
||||
{
|
||||
return settings.IsGlobal;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (settings.IsGlobal != value)
|
||||
{
|
||||
settings.IsGlobal = value;
|
||||
NotifyPropertyChanged();
|
||||
NotifyPropertyChanged(nameof(ShowNotAccessibleWarning));
|
||||
NotifyPropertyChanged(nameof(IsGlobalAndEnabled));
|
||||
NotifyPropertyChanged(nameof(ShowBadgeOnPluginSettingError));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int WeightBoost
|
||||
{
|
||||
get
|
||||
{
|
||||
return settings.WeightBoost;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (settings.WeightBoost != value)
|
||||
{
|
||||
settings.WeightBoost = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string ActionKeyword
|
||||
{
|
||||
get
|
||||
{
|
||||
return settings.ActionKeyword;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (settings.ActionKeyword != value)
|
||||
{
|
||||
settings.ActionKeyword = value;
|
||||
NotifyPropertyChanged();
|
||||
NotifyPropertyChanged(nameof(ShowNotAccessibleWarning));
|
||||
NotifyPropertyChanged(nameof(ShowBadgeOnPluginSettingError));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerable<PluginAdditionalOptionViewModel> _additionalOptions;
|
||||
|
||||
public IEnumerable<PluginAdditionalOptionViewModel> AdditionalOptions
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_additionalOptions == null)
|
||||
{
|
||||
_additionalOptions = settings.AdditionalOptions.Select(x => new PluginAdditionalOptionViewModel(x)).ToList();
|
||||
}
|
||||
|
||||
return _additionalOptions;
|
||||
}
|
||||
}
|
||||
|
||||
public bool ShowAdditionalOptions
|
||||
{
|
||||
get => AdditionalOptions.Any();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{Name}. {Description}";
|
||||
}
|
||||
|
||||
public string IconPath
|
||||
{
|
||||
get
|
||||
{
|
||||
var path = isDark() ? settings.IconPathDark : settings.IconPathLight;
|
||||
path = Path.Combine(Directory.GetCurrentDirectory(), @"modules\launcher\Plugins", path);
|
||||
return path;
|
||||
}
|
||||
}
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
private void NotifyPropertyChanged([CallerMemberName] string propertyName = "")
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
|
||||
public bool ShowNotAccessibleWarning
|
||||
{
|
||||
get => !Disabled && !IsGlobal && string.IsNullOrWhiteSpace(ActionKeyword);
|
||||
}
|
||||
|
||||
public bool ShowBadgeOnPluginSettingError
|
||||
{
|
||||
get => !Disabled && ShowNotAccessibleWarning;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,560 +0,0 @@
|
||||
// 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.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text.Json;
|
||||
using System.Windows.Input;
|
||||
using ManagedCommon;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.ViewModels.Commands;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
|
||||
{
|
||||
public class PowerLauncherViewModel : Observable
|
||||
{
|
||||
private int _themeIndex;
|
||||
private int _monitorPositionIndex;
|
||||
|
||||
private string _searchText;
|
||||
|
||||
private GeneralSettings GeneralSettingsConfig { get; set; }
|
||||
|
||||
private PowerLauncherSettings settings;
|
||||
|
||||
public delegate void SendCallback(PowerLauncherSettings settings);
|
||||
|
||||
private readonly SendCallback callback;
|
||||
|
||||
private readonly Func<bool> isDark;
|
||||
|
||||
private Func<string, int> SendConfigMSG { get; }
|
||||
|
||||
public PowerLauncherViewModel(
|
||||
PowerLauncherSettings settings,
|
||||
ISettingsRepository<GeneralSettings> settingsRepository,
|
||||
Func<string, int> ipcMSGCallBackFunc,
|
||||
Func<bool> isDark)
|
||||
{
|
||||
if (settings == null)
|
||||
{
|
||||
throw new ArgumentException("settings argument can not be null");
|
||||
}
|
||||
|
||||
this.settings = settings;
|
||||
this.isDark = isDark;
|
||||
|
||||
// To obtain the general Settings configurations of PowerToys
|
||||
if (settingsRepository == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(settingsRepository));
|
||||
}
|
||||
|
||||
GeneralSettingsConfig = settingsRepository.SettingsConfig;
|
||||
|
||||
// set the callback functions value to hangle outgoing IPC message.
|
||||
SendConfigMSG = ipcMSGCallBackFunc;
|
||||
callback = (PowerLauncherSettings s) =>
|
||||
{
|
||||
// Propagate changes to Power Launcher through IPC
|
||||
// Using InvariantCulture as this is an IPC message
|
||||
SendConfigMSG(
|
||||
string.Format(
|
||||
CultureInfo.InvariantCulture,
|
||||
"{{ \"powertoys\": {{ \"{0}\": {1} }} }}",
|
||||
PowerLauncherSettings.ModuleName,
|
||||
JsonSerializer.Serialize(s)));
|
||||
};
|
||||
|
||||
switch (settings.Properties.Theme)
|
||||
{
|
||||
case Theme.Dark:
|
||||
_themeIndex = 0;
|
||||
break;
|
||||
case Theme.Light:
|
||||
_themeIndex = 1;
|
||||
break;
|
||||
case Theme.System:
|
||||
_themeIndex = 2;
|
||||
break;
|
||||
}
|
||||
|
||||
switch (settings.Properties.Position)
|
||||
{
|
||||
case StartupPosition.Cursor:
|
||||
_monitorPositionIndex = 0;
|
||||
break;
|
||||
case StartupPosition.PrimaryMonitor:
|
||||
_monitorPositionIndex = 1;
|
||||
break;
|
||||
case StartupPosition.Focus:
|
||||
_monitorPositionIndex = 2;
|
||||
break;
|
||||
}
|
||||
|
||||
SearchPluginsCommand = new RelayCommand(SearchPlugins);
|
||||
}
|
||||
|
||||
private void OnPluginInfoChange(object sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
if (
|
||||
e.PropertyName == nameof(PowerLauncherPluginViewModel.ShowNotAccessibleWarning)
|
||||
|| e.PropertyName == nameof(PowerLauncherPluginViewModel.ShowBadgeOnPluginSettingError)
|
||||
)
|
||||
{
|
||||
// Don't trigger a settings update if the changed property is for visual notification.
|
||||
return;
|
||||
}
|
||||
|
||||
OnPropertyChanged(nameof(ShowAllPluginsDisabledWarning));
|
||||
UpdateSettings();
|
||||
}
|
||||
|
||||
public PowerLauncherViewModel(PowerLauncherSettings settings, SendCallback callback)
|
||||
{
|
||||
this.settings = settings;
|
||||
this.callback = callback;
|
||||
}
|
||||
|
||||
private void UpdateSettings([CallerMemberName] string propertyName = null)
|
||||
{
|
||||
// Notify UI of property change
|
||||
OnPropertyChanged(propertyName);
|
||||
|
||||
callback(settings);
|
||||
}
|
||||
|
||||
public bool EnablePowerLauncher
|
||||
{
|
||||
get
|
||||
{
|
||||
return GeneralSettingsConfig.Enabled.PowerLauncher;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (GeneralSettingsConfig.Enabled.PowerLauncher != value)
|
||||
{
|
||||
GeneralSettingsConfig.Enabled.PowerLauncher = value;
|
||||
OnPropertyChanged(nameof(EnablePowerLauncher));
|
||||
OnPropertyChanged(nameof(ShowAllPluginsDisabledWarning));
|
||||
OnPropertyChanged(nameof(ShowPluginsLoadingMessage));
|
||||
OutGoingGeneralSettings outgoing = new OutGoingGeneralSettings(GeneralSettingsConfig);
|
||||
SendConfigMSG(outgoing.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string SearchResultPreference
|
||||
{
|
||||
get
|
||||
{
|
||||
return settings.Properties.SearchResultPreference;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (settings.Properties.SearchResultPreference != value)
|
||||
{
|
||||
settings.Properties.SearchResultPreference = value;
|
||||
UpdateSettings();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string SearchTypePreference
|
||||
{
|
||||
get
|
||||
{
|
||||
return settings.Properties.SearchTypePreference;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (settings.Properties.SearchTypePreference != value)
|
||||
{
|
||||
settings.Properties.SearchTypePreference = value;
|
||||
UpdateSettings();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int MaximumNumberOfResults
|
||||
{
|
||||
get
|
||||
{
|
||||
return settings.Properties.MaximumNumberOfResults;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (settings.Properties.MaximumNumberOfResults != value)
|
||||
{
|
||||
settings.Properties.MaximumNumberOfResults = value;
|
||||
UpdateSettings();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int ThemeIndex
|
||||
{
|
||||
get
|
||||
{
|
||||
return _themeIndex;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
switch (value)
|
||||
{
|
||||
case 0: settings.Properties.Theme = Theme.Dark; break;
|
||||
case 1: settings.Properties.Theme = Theme.Light; break;
|
||||
case 2: settings.Properties.Theme = Theme.System; break;
|
||||
}
|
||||
|
||||
_themeIndex = value;
|
||||
UpdateSettings();
|
||||
}
|
||||
}
|
||||
|
||||
public int MonitorPositionIndex
|
||||
{
|
||||
get
|
||||
{
|
||||
return _monitorPositionIndex;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (_monitorPositionIndex != value)
|
||||
{
|
||||
switch (value)
|
||||
{
|
||||
case 0: settings.Properties.Position = StartupPosition.Cursor; break;
|
||||
case 1: settings.Properties.Position = StartupPosition.PrimaryMonitor; break;
|
||||
case 2: settings.Properties.Position = StartupPosition.Focus; break;
|
||||
}
|
||||
|
||||
_monitorPositionIndex = value;
|
||||
UpdateSettings();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string SearchText
|
||||
{
|
||||
get
|
||||
{
|
||||
return _searchText;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (_searchText != value)
|
||||
{
|
||||
_searchText = value;
|
||||
OnPropertyChanged(nameof(SearchText));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ICommand SearchPluginsCommand { get; }
|
||||
|
||||
public HotkeySettings OpenPowerLauncher
|
||||
{
|
||||
get
|
||||
{
|
||||
return settings.Properties.OpenPowerLauncher;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (settings.Properties.OpenPowerLauncher != value)
|
||||
{
|
||||
settings.Properties.OpenPowerLauncher = value;
|
||||
UpdateSettings();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool UseCentralizedKeyboardHook
|
||||
{
|
||||
get
|
||||
{
|
||||
return settings.Properties.UseCentralizedKeyboardHook;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (settings.Properties.UseCentralizedKeyboardHook != value)
|
||||
{
|
||||
settings.Properties.UseCentralizedKeyboardHook = value;
|
||||
UpdateSettings();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool SearchQueryResultsWithDelay
|
||||
{
|
||||
get
|
||||
{
|
||||
return settings.Properties.SearchQueryResultsWithDelay;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (settings.Properties.SearchQueryResultsWithDelay != value)
|
||||
{
|
||||
settings.Properties.SearchQueryResultsWithDelay = value;
|
||||
UpdateSettings();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int SearchInputDelayFast
|
||||
{
|
||||
get
|
||||
{
|
||||
return settings.Properties.SearchInputDelayFast;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (settings.Properties.SearchInputDelayFast != value)
|
||||
{
|
||||
settings.Properties.SearchInputDelayFast = value;
|
||||
UpdateSettings();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int SearchInputDelay
|
||||
{
|
||||
get
|
||||
{
|
||||
return settings.Properties.SearchInputDelay;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (settings.Properties.SearchInputDelay != value)
|
||||
{
|
||||
settings.Properties.SearchInputDelay = value;
|
||||
UpdateSettings();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool SearchQueryTuningEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
return settings.Properties.SearchQueryTuningEnabled;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (settings.Properties.SearchQueryTuningEnabled != value)
|
||||
{
|
||||
settings.Properties.SearchQueryTuningEnabled = value;
|
||||
UpdateSettings();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool SearchWaitForSlowResults
|
||||
{
|
||||
get
|
||||
{
|
||||
return settings.Properties.SearchWaitForSlowResults;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (settings.Properties.SearchWaitForSlowResults != value)
|
||||
{
|
||||
settings.Properties.SearchWaitForSlowResults = value;
|
||||
UpdateSettings();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int SearchClickedItemWeight
|
||||
{
|
||||
get
|
||||
{
|
||||
return settings.Properties.SearchClickedItemWeight;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (settings.Properties.SearchClickedItemWeight != value)
|
||||
{
|
||||
settings.Properties.SearchClickedItemWeight = value;
|
||||
UpdateSettings();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public HotkeySettings OpenFileLocation
|
||||
{
|
||||
get
|
||||
{
|
||||
return settings.Properties.OpenFileLocation;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (settings.Properties.OpenFileLocation != value)
|
||||
{
|
||||
settings.Properties.OpenFileLocation = value;
|
||||
UpdateSettings();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public HotkeySettings CopyPathLocation
|
||||
{
|
||||
get
|
||||
{
|
||||
return settings.Properties.CopyPathLocation;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (settings.Properties.CopyPathLocation != value)
|
||||
{
|
||||
settings.Properties.CopyPathLocation = value;
|
||||
UpdateSettings();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool OverrideWinRKey
|
||||
{
|
||||
get
|
||||
{
|
||||
return settings.Properties.OverrideWinkeyR;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (settings.Properties.OverrideWinkeyR != value)
|
||||
{
|
||||
settings.Properties.OverrideWinkeyR = value;
|
||||
UpdateSettings();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool OverrideWinSKey
|
||||
{
|
||||
get
|
||||
{
|
||||
return settings.Properties.OverrideWinkeyS;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (settings.Properties.OverrideWinkeyS != value)
|
||||
{
|
||||
settings.Properties.OverrideWinkeyS = value;
|
||||
UpdateSettings();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool IgnoreHotkeysInFullScreen
|
||||
{
|
||||
get
|
||||
{
|
||||
return settings.Properties.IgnoreHotkeysInFullscreen;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (settings.Properties.IgnoreHotkeysInFullscreen != value)
|
||||
{
|
||||
settings.Properties.IgnoreHotkeysInFullscreen = value;
|
||||
UpdateSettings();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool ClearInputOnLaunch
|
||||
{
|
||||
get
|
||||
{
|
||||
return settings.Properties.ClearInputOnLaunch;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (settings.Properties.ClearInputOnLaunch != value)
|
||||
{
|
||||
settings.Properties.ClearInputOnLaunch = value;
|
||||
UpdateSettings();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private ObservableCollection<PowerLauncherPluginViewModel> _plugins;
|
||||
|
||||
public ObservableCollection<PowerLauncherPluginViewModel> Plugins
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_plugins == null)
|
||||
{
|
||||
_plugins = new ObservableCollection<PowerLauncherPluginViewModel>(settings.Plugins.Select(x => new PowerLauncherPluginViewModel(x, isDark)));
|
||||
foreach (var plugin in Plugins)
|
||||
{
|
||||
plugin.PropertyChanged += OnPluginInfoChange;
|
||||
}
|
||||
}
|
||||
|
||||
return _plugins;
|
||||
}
|
||||
}
|
||||
|
||||
public bool ShowAllPluginsDisabledWarning
|
||||
{
|
||||
get => EnablePowerLauncher && settings.Plugins.Any() && settings.Plugins.All(x => x.Disabled);
|
||||
}
|
||||
|
||||
public bool ShowPluginsLoadingMessage
|
||||
{
|
||||
get => EnablePowerLauncher && !Plugins.Any();
|
||||
}
|
||||
|
||||
public bool IsUpToDate(PowerLauncherSettings settings)
|
||||
{
|
||||
return this.settings.Equals(settings);
|
||||
}
|
||||
|
||||
public void SearchPlugins()
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(SearchText))
|
||||
{
|
||||
var plugins = settings.Plugins.Where(p => p.Name.StartsWith(SearchText, StringComparison.OrdinalIgnoreCase) || p.Name.IndexOf($" {SearchText}", StringComparison.OrdinalIgnoreCase) > 0);
|
||||
_plugins = new ObservableCollection<PowerLauncherPluginViewModel>(plugins.Select(x => new PowerLauncherPluginViewModel(x, isDark)));
|
||||
foreach (var plugin in _plugins)
|
||||
{
|
||||
plugin.PropertyChanged += OnPluginInfoChange;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_plugins = null;
|
||||
}
|
||||
|
||||
OnPropertyChanged(nameof(Plugins));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,160 +0,0 @@
|
||||
// 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.Globalization;
|
||||
using System.Text.Json;
|
||||
using System.Timers;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
|
||||
{
|
||||
public class PowerOcrViewModel : Observable, IDisposable
|
||||
{
|
||||
private bool disposedValue;
|
||||
|
||||
// Delay saving of settings in order to avoid calling save multiple times and hitting file in use exception. If there is no other request to save settings in given interval, we proceed to save it, otherwise we schedule saving it after this interval
|
||||
private const int SaveSettingsDelayInMs = 500;
|
||||
|
||||
private GeneralSettings GeneralSettingsConfig { get; set; }
|
||||
|
||||
private readonly ISettingsUtils _settingsUtils;
|
||||
private readonly object _delayedActionLock = new object();
|
||||
|
||||
private readonly PowerOcrSettings _powerOcrSettings;
|
||||
private Timer _delayedTimer;
|
||||
|
||||
private bool _isEnabled;
|
||||
|
||||
private Func<string, int> SendConfigMSG { get; }
|
||||
|
||||
public PowerOcrViewModel(
|
||||
ISettingsUtils settingsUtils,
|
||||
ISettingsRepository<GeneralSettings> settingsRepository,
|
||||
ISettingsRepository<PowerOcrSettings> powerOcrsettingsRepository,
|
||||
Func<string, int> ipcMSGCallBackFunc)
|
||||
{
|
||||
// To obtain the general settings configurations of PowerToys Settings.
|
||||
if (settingsRepository == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(settingsRepository));
|
||||
}
|
||||
|
||||
GeneralSettingsConfig = settingsRepository.SettingsConfig;
|
||||
|
||||
// To obtain the settings configurations of Fancy zones.
|
||||
if (settingsRepository == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(settingsRepository));
|
||||
}
|
||||
|
||||
_settingsUtils = settingsUtils ?? throw new ArgumentNullException(nameof(settingsUtils));
|
||||
|
||||
if (powerOcrsettingsRepository == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(powerOcrsettingsRepository));
|
||||
}
|
||||
|
||||
_powerOcrSettings = powerOcrsettingsRepository.SettingsConfig;
|
||||
|
||||
_isEnabled = GeneralSettingsConfig.Enabled.PowerOCR;
|
||||
|
||||
// set the callback functions value to hangle outgoing IPC message.
|
||||
SendConfigMSG = ipcMSGCallBackFunc;
|
||||
|
||||
_delayedTimer = new Timer();
|
||||
_delayedTimer.Interval = SaveSettingsDelayInMs;
|
||||
_delayedTimer.Elapsed += DelayedTimer_Tick;
|
||||
_delayedTimer.AutoReset = false;
|
||||
}
|
||||
|
||||
public bool IsEnabled
|
||||
{
|
||||
get => _isEnabled;
|
||||
set
|
||||
{
|
||||
if (_isEnabled != value)
|
||||
{
|
||||
_isEnabled = value;
|
||||
OnPropertyChanged(nameof(IsEnabled));
|
||||
|
||||
// Set the status of PowerOCR in the general settings
|
||||
GeneralSettingsConfig.Enabled.PowerOCR = value;
|
||||
var outgoing = new OutGoingGeneralSettings(GeneralSettingsConfig);
|
||||
|
||||
SendConfigMSG(outgoing.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public HotkeySettings ActivationShortcut
|
||||
{
|
||||
get => _powerOcrSettings.Properties.ActivationShortcut;
|
||||
set
|
||||
{
|
||||
if (_powerOcrSettings.Properties.ActivationShortcut != value)
|
||||
{
|
||||
_powerOcrSettings.Properties.ActivationShortcut = value;
|
||||
OnPropertyChanged(nameof(ActivationShortcut));
|
||||
|
||||
_settingsUtils.SaveSettings(_powerOcrSettings.ToJsonString(), PowerOcrSettings.ModuleName);
|
||||
NotifySettingsChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ScheduleSavingOfSettings()
|
||||
{
|
||||
lock (_delayedActionLock)
|
||||
{
|
||||
if (_delayedTimer.Enabled)
|
||||
{
|
||||
_delayedTimer.Stop();
|
||||
}
|
||||
|
||||
_delayedTimer.Start();
|
||||
}
|
||||
}
|
||||
|
||||
private void DelayedTimer_Tick(object sender, EventArgs e)
|
||||
{
|
||||
lock (_delayedActionLock)
|
||||
{
|
||||
_delayedTimer.Stop();
|
||||
NotifySettingsChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private void NotifySettingsChanged()
|
||||
{
|
||||
// Using InvariantCulture as this is an IPC message
|
||||
SendConfigMSG(
|
||||
string.Format(
|
||||
CultureInfo.InvariantCulture,
|
||||
"{{ \"powertoys\": {{ \"{0}\": {1} }} }}",
|
||||
PowerOcrSettings.ModuleName,
|
||||
JsonSerializer.Serialize(_powerOcrSettings)));
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (!disposedValue)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
_delayedTimer.Dispose();
|
||||
}
|
||||
|
||||
disposedValue = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(disposing: true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,318 +0,0 @@
|
||||
// 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.Runtime.CompilerServices;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
|
||||
{
|
||||
public class PowerPreviewViewModel : Observable
|
||||
{
|
||||
private const string ModuleName = PowerPreviewSettings.ModuleName;
|
||||
|
||||
private PowerPreviewSettings Settings { get; set; }
|
||||
|
||||
private Func<string, int> SendConfigMSG { get; }
|
||||
|
||||
private string _settingsConfigFileFolder = string.Empty;
|
||||
|
||||
private GeneralSettings GeneralSettingsConfig { get; set; }
|
||||
|
||||
public PowerPreviewViewModel(ISettingsRepository<PowerPreviewSettings> moduleSettingsRepository, ISettingsRepository<GeneralSettings> generalSettingsRepository, Func<string, int> ipcMSGCallBackFunc, string configFileSubfolder = "")
|
||||
{
|
||||
// Update Settings file folder:
|
||||
_settingsConfigFileFolder = configFileSubfolder;
|
||||
|
||||
// To obtain the general Settings configurations of PowerToys
|
||||
if (generalSettingsRepository == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(generalSettingsRepository));
|
||||
}
|
||||
|
||||
GeneralSettingsConfig = generalSettingsRepository.SettingsConfig;
|
||||
|
||||
// To obtain the PowerPreview settings if it exists.
|
||||
// If the file does not exist, to create a new one and return the default settings configurations.
|
||||
if (moduleSettingsRepository == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(moduleSettingsRepository));
|
||||
}
|
||||
|
||||
Settings = moduleSettingsRepository.SettingsConfig;
|
||||
|
||||
// set the callback functions value to hangle outgoing IPC message.
|
||||
SendConfigMSG = ipcMSGCallBackFunc;
|
||||
|
||||
_svgRenderIsEnabled = Settings.Properties.EnableSvgPreview;
|
||||
_svgThumbnailIsEnabled = Settings.Properties.EnableSvgThumbnail;
|
||||
_mdRenderIsEnabled = Settings.Properties.EnableMdPreview;
|
||||
_monacoRenderIsEnabled = Settings.Properties.EnableMonacoPreview;
|
||||
_monacoWrapText = Settings.Properties.EnableMonacoPreviewWordWrap;
|
||||
_monacoPreviewTryFormat = Settings.Properties.MonacoPreviewTryFormat;
|
||||
_pdfRenderIsEnabled = Settings.Properties.EnablePdfPreview;
|
||||
_gcodeRenderIsEnabled = Settings.Properties.EnableGcodePreview;
|
||||
_pdfThumbnailIsEnabled = Settings.Properties.EnablePdfThumbnail;
|
||||
_gcodeThumbnailIsEnabled = Settings.Properties.EnableGcodeThumbnail;
|
||||
_stlThumbnailIsEnabled = Settings.Properties.EnableStlThumbnail;
|
||||
_stlThumbnailColor = Settings.Properties.StlThumbnailColor.Value;
|
||||
}
|
||||
|
||||
private bool _svgRenderIsEnabled;
|
||||
private bool _mdRenderIsEnabled;
|
||||
private bool _monacoRenderIsEnabled;
|
||||
private bool _monacoWrapText;
|
||||
private bool _monacoPreviewTryFormat;
|
||||
private bool _pdfRenderIsEnabled;
|
||||
private bool _gcodeRenderIsEnabled;
|
||||
private bool _svgThumbnailIsEnabled;
|
||||
private bool _pdfThumbnailIsEnabled;
|
||||
private bool _gcodeThumbnailIsEnabled;
|
||||
private bool _stlThumbnailIsEnabled;
|
||||
private string _stlThumbnailColor;
|
||||
|
||||
public bool SVGRenderIsEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
return _svgRenderIsEnabled;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _svgRenderIsEnabled)
|
||||
{
|
||||
_svgRenderIsEnabled = value;
|
||||
Settings.Properties.EnableSvgPreview = value;
|
||||
RaisePropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool SVGThumbnailIsEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
return _svgThumbnailIsEnabled;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _svgThumbnailIsEnabled)
|
||||
{
|
||||
_svgThumbnailIsEnabled = value;
|
||||
Settings.Properties.EnableSvgThumbnail = value;
|
||||
RaisePropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool MDRenderIsEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
return _mdRenderIsEnabled;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _mdRenderIsEnabled)
|
||||
{
|
||||
_mdRenderIsEnabled = value;
|
||||
Settings.Properties.EnableMdPreview = value;
|
||||
RaisePropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool MonacoRenderIsEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
return _monacoRenderIsEnabled;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _monacoRenderIsEnabled)
|
||||
{
|
||||
_monacoRenderIsEnabled = value;
|
||||
Settings.Properties.EnableMonacoPreview = value;
|
||||
RaisePropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool MonacoWrapText
|
||||
{
|
||||
get
|
||||
{
|
||||
return _monacoWrapText;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (_monacoWrapText != value)
|
||||
{
|
||||
_monacoWrapText = value;
|
||||
Settings.Properties.EnableMonacoPreviewWordWrap = value;
|
||||
RaisePropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool MonacoPreviewTryFormat
|
||||
{
|
||||
get
|
||||
{
|
||||
return _monacoPreviewTryFormat;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (_monacoPreviewTryFormat != value)
|
||||
{
|
||||
_monacoPreviewTryFormat = value;
|
||||
Settings.Properties.MonacoPreviewTryFormat = value;
|
||||
RaisePropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool PDFRenderIsEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
return _pdfRenderIsEnabled;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _pdfRenderIsEnabled)
|
||||
{
|
||||
_pdfRenderIsEnabled = value;
|
||||
Settings.Properties.EnablePdfPreview = value;
|
||||
RaisePropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool PDFThumbnailIsEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
return _pdfThumbnailIsEnabled;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _pdfThumbnailIsEnabled)
|
||||
{
|
||||
_pdfThumbnailIsEnabled = value;
|
||||
Settings.Properties.EnablePdfThumbnail = value;
|
||||
RaisePropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool GCODERenderIsEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
return _gcodeRenderIsEnabled;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _gcodeRenderIsEnabled)
|
||||
{
|
||||
_gcodeRenderIsEnabled = value;
|
||||
Settings.Properties.EnableGcodePreview = value;
|
||||
RaisePropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool GCODEThumbnailIsEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
return _gcodeThumbnailIsEnabled;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _gcodeThumbnailIsEnabled)
|
||||
{
|
||||
_gcodeThumbnailIsEnabled = value;
|
||||
Settings.Properties.EnableGcodeThumbnail = value;
|
||||
RaisePropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool STLThumbnailIsEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
return _stlThumbnailIsEnabled;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _stlThumbnailIsEnabled)
|
||||
{
|
||||
_stlThumbnailIsEnabled = value;
|
||||
Settings.Properties.EnableStlThumbnail = value;
|
||||
RaisePropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string STLThumbnailColor
|
||||
{
|
||||
get
|
||||
{
|
||||
return _stlThumbnailColor;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _stlThumbnailColor)
|
||||
{
|
||||
_stlThumbnailColor = value;
|
||||
Settings.Properties.StlThumbnailColor.Value = value;
|
||||
RaisePropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string GetSettingsSubPath()
|
||||
{
|
||||
return _settingsConfigFileFolder + "\\" + ModuleName;
|
||||
}
|
||||
|
||||
public bool IsElevated
|
||||
{
|
||||
get
|
||||
{
|
||||
return GeneralSettingsConfig.IsElevated;
|
||||
}
|
||||
}
|
||||
|
||||
private void RaisePropertyChanged([CallerMemberName] string propertyName = null)
|
||||
{
|
||||
// Notify UI of property change
|
||||
OnPropertyChanged(propertyName);
|
||||
|
||||
if (SendConfigMSG != null)
|
||||
{
|
||||
SndPowerPreviewSettings snd = new SndPowerPreviewSettings(Settings);
|
||||
SndModuleSettings<SndPowerPreviewSettings> ipcMessage = new SndModuleSettings<SndPowerPreviewSettings>(snd);
|
||||
SendConfigMSG(ipcMessage.ToJsonString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,238 +0,0 @@
|
||||
// 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.IO;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
|
||||
{
|
||||
public class PowerRenameViewModel : Observable
|
||||
{
|
||||
private GeneralSettings GeneralSettingsConfig { get; set; }
|
||||
|
||||
private readonly ISettingsUtils _settingsUtils;
|
||||
|
||||
private const string ModuleName = PowerRenameSettings.ModuleName;
|
||||
|
||||
private string _settingsConfigFileFolder = string.Empty;
|
||||
|
||||
private PowerRenameSettings Settings { get; set; }
|
||||
|
||||
private Func<string, int> SendConfigMSG { get; }
|
||||
|
||||
public PowerRenameViewModel(ISettingsUtils settingsUtils, ISettingsRepository<GeneralSettings> settingsRepository, Func<string, int> ipcMSGCallBackFunc, string configFileSubfolder = "")
|
||||
{
|
||||
// Update Settings file folder:
|
||||
_settingsConfigFileFolder = configFileSubfolder;
|
||||
_settingsUtils = settingsUtils ?? throw new ArgumentNullException(nameof(settingsUtils));
|
||||
|
||||
if (settingsRepository == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(settingsRepository));
|
||||
}
|
||||
|
||||
GeneralSettingsConfig = settingsRepository.SettingsConfig;
|
||||
|
||||
try
|
||||
{
|
||||
PowerRenameLocalProperties localSettings = _settingsUtils.GetSettingsOrDefault<PowerRenameLocalProperties>(GetSettingsSubPath(), "power-rename-settings.json");
|
||||
Settings = new PowerRenameSettings(localSettings);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.LogError($"Exception encountered while reading {ModuleName} settings.", e);
|
||||
#if DEBUG
|
||||
if (e is ArgumentException || e is ArgumentNullException || e is PathTooLongException)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
#endif
|
||||
PowerRenameLocalProperties localSettings = new PowerRenameLocalProperties();
|
||||
Settings = new PowerRenameSettings(localSettings);
|
||||
_settingsUtils.SaveSettings(localSettings.ToJsonString(), GetSettingsSubPath(), "power-rename-settings.json");
|
||||
}
|
||||
|
||||
// set the callback functions value to hangle outgoing IPC message.
|
||||
SendConfigMSG = ipcMSGCallBackFunc;
|
||||
|
||||
_powerRenameEnabledOnContextMenu = Settings.Properties.ShowIcon.Value;
|
||||
_powerRenameEnabledOnContextExtendedMenu = Settings.Properties.ExtendedContextMenuOnly.Value;
|
||||
_powerRenameRestoreFlagsOnLaunch = Settings.Properties.PersistState.Value;
|
||||
_powerRenameMaxDispListNumValue = Settings.Properties.MaxMRUSize.Value;
|
||||
_autoComplete = Settings.Properties.MRUEnabled.Value;
|
||||
_powerRenameUseBoostLib = Settings.Properties.UseBoostLib.Value;
|
||||
_powerRenameEnabled = GeneralSettingsConfig.Enabled.PowerRename;
|
||||
}
|
||||
|
||||
private bool _powerRenameEnabled;
|
||||
private bool _powerRenameEnabledOnContextMenu;
|
||||
private bool _powerRenameEnabledOnContextExtendedMenu;
|
||||
private bool _powerRenameRestoreFlagsOnLaunch;
|
||||
private int _powerRenameMaxDispListNumValue;
|
||||
private bool _autoComplete;
|
||||
private bool _powerRenameUseBoostLib;
|
||||
|
||||
public bool IsEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
return _powerRenameEnabled;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _powerRenameEnabled)
|
||||
{
|
||||
GeneralSettingsConfig.Enabled.PowerRename = value;
|
||||
OutGoingGeneralSettings snd = new OutGoingGeneralSettings(GeneralSettingsConfig);
|
||||
|
||||
SendConfigMSG(snd.ToString());
|
||||
|
||||
_powerRenameEnabled = value;
|
||||
OnPropertyChanged(nameof(IsEnabled));
|
||||
RaisePropertyChanged(nameof(GlobalAndMruEnabled));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool MRUEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
return _autoComplete;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _autoComplete)
|
||||
{
|
||||
_autoComplete = value;
|
||||
Settings.Properties.MRUEnabled.Value = value;
|
||||
RaisePropertyChanged();
|
||||
RaisePropertyChanged(nameof(GlobalAndMruEnabled));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool GlobalAndMruEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
return _autoComplete && _powerRenameEnabled;
|
||||
}
|
||||
}
|
||||
|
||||
public bool EnabledOnContextMenu
|
||||
{
|
||||
get
|
||||
{
|
||||
return _powerRenameEnabledOnContextMenu;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _powerRenameEnabledOnContextMenu)
|
||||
{
|
||||
_powerRenameEnabledOnContextMenu = value;
|
||||
Settings.Properties.ShowIcon.Value = value;
|
||||
RaisePropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool EnabledOnContextExtendedMenu
|
||||
{
|
||||
get
|
||||
{
|
||||
return _powerRenameEnabledOnContextExtendedMenu;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _powerRenameEnabledOnContextExtendedMenu)
|
||||
{
|
||||
_powerRenameEnabledOnContextExtendedMenu = value;
|
||||
Settings.Properties.ExtendedContextMenuOnly.Value = value;
|
||||
RaisePropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool RestoreFlagsOnLaunch
|
||||
{
|
||||
get
|
||||
{
|
||||
return _powerRenameRestoreFlagsOnLaunch;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _powerRenameRestoreFlagsOnLaunch)
|
||||
{
|
||||
_powerRenameRestoreFlagsOnLaunch = value;
|
||||
Settings.Properties.PersistState.Value = value;
|
||||
RaisePropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int MaxDispListNum
|
||||
{
|
||||
get
|
||||
{
|
||||
return _powerRenameMaxDispListNumValue;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _powerRenameMaxDispListNumValue)
|
||||
{
|
||||
_powerRenameMaxDispListNumValue = value;
|
||||
Settings.Properties.MaxMRUSize.Value = value;
|
||||
RaisePropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool UseBoostLib
|
||||
{
|
||||
get
|
||||
{
|
||||
return _powerRenameUseBoostLib;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _powerRenameUseBoostLib)
|
||||
{
|
||||
_powerRenameUseBoostLib = value;
|
||||
Settings.Properties.UseBoostLib.Value = value;
|
||||
RaisePropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string GetSettingsSubPath()
|
||||
{
|
||||
return _settingsConfigFileFolder + "\\" + ModuleName;
|
||||
}
|
||||
|
||||
private void RaisePropertyChanged([CallerMemberName] string propertyName = null)
|
||||
{
|
||||
// Notify UI of property change
|
||||
OnPropertyChanged(propertyName);
|
||||
|
||||
if (SendConfigMSG != null)
|
||||
{
|
||||
SndPowerRenameSettings snd = new SndPowerRenameSettings(Settings);
|
||||
SndModuleSettings<SndPowerRenameSettings> ipcMessage = new SndModuleSettings<SndPowerRenameSettings>(snd);
|
||||
SendConfigMSG(ipcMessage.ToJsonString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,225 +0,0 @@
|
||||
// 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.Runtime.CompilerServices;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
|
||||
{
|
||||
public class ShortcutGuideViewModel : Observable
|
||||
{
|
||||
private ISettingsUtils SettingsUtils { get; set; }
|
||||
|
||||
private GeneralSettings GeneralSettingsConfig { get; set; }
|
||||
|
||||
private ShortcutGuideSettings Settings { get; set; }
|
||||
|
||||
private const string ModuleName = ShortcutGuideSettings.ModuleName;
|
||||
|
||||
private Func<string, int> SendConfigMSG { get; }
|
||||
|
||||
private string _settingsConfigFileFolder = string.Empty;
|
||||
private string _disabledApps;
|
||||
|
||||
public ShortcutGuideViewModel(ISettingsUtils settingsUtils, ISettingsRepository<GeneralSettings> settingsRepository, ISettingsRepository<ShortcutGuideSettings> moduleSettingsRepository, Func<string, int> ipcMSGCallBackFunc, string configFileSubfolder = "")
|
||||
{
|
||||
SettingsUtils = settingsUtils;
|
||||
|
||||
// Update Settings file folder:
|
||||
_settingsConfigFileFolder = configFileSubfolder;
|
||||
|
||||
// To obtain the general PowerToys settings.
|
||||
if (settingsRepository == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(settingsRepository));
|
||||
}
|
||||
|
||||
GeneralSettingsConfig = settingsRepository.SettingsConfig;
|
||||
|
||||
// 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.
|
||||
if (moduleSettingsRepository == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(moduleSettingsRepository));
|
||||
}
|
||||
|
||||
Settings = moduleSettingsRepository.SettingsConfig;
|
||||
|
||||
// set the callback functions value to hangle outgoing IPC message.
|
||||
SendConfigMSG = ipcMSGCallBackFunc;
|
||||
|
||||
_isEnabled = GeneralSettingsConfig.Enabled.ShortcutGuide;
|
||||
_useLegacyPressWinKeyBehavior = Settings.Properties.UseLegacyPressWinKeyBehavior.Value;
|
||||
_pressTime = Settings.Properties.PressTime.Value;
|
||||
_opacity = Settings.Properties.OverlayOpacity.Value;
|
||||
_disabledApps = Settings.Properties.DisabledApps.Value;
|
||||
|
||||
switch (Settings.Properties.Theme.Value)
|
||||
{
|
||||
case "dark": _themeIndex = 0; break;
|
||||
case "light": _themeIndex = 1; break;
|
||||
case "system": _themeIndex = 2; break;
|
||||
}
|
||||
}
|
||||
|
||||
private bool _isEnabled;
|
||||
private int _themeIndex;
|
||||
private bool _useLegacyPressWinKeyBehavior;
|
||||
private int _pressTime;
|
||||
private int _opacity;
|
||||
|
||||
public bool IsEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
return _isEnabled;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _isEnabled)
|
||||
{
|
||||
_isEnabled = value;
|
||||
|
||||
// To update the status of shortcut guide in General PowerToy settings.
|
||||
GeneralSettingsConfig.Enabled.ShortcutGuide = value;
|
||||
OutGoingGeneralSettings snd = new OutGoingGeneralSettings(GeneralSettingsConfig);
|
||||
|
||||
SendConfigMSG(snd.ToString());
|
||||
OnPropertyChanged(nameof(IsEnabled));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public HotkeySettings OpenShortcutGuide
|
||||
{
|
||||
get
|
||||
{
|
||||
return Settings.Properties.OpenShortcutGuide;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (Settings.Properties.OpenShortcutGuide != value)
|
||||
{
|
||||
Settings.Properties.OpenShortcutGuide = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int ThemeIndex
|
||||
{
|
||||
get
|
||||
{
|
||||
return _themeIndex;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (_themeIndex != value)
|
||||
{
|
||||
switch (value)
|
||||
{
|
||||
case 0: Settings.Properties.Theme.Value = "dark"; break;
|
||||
case 1: Settings.Properties.Theme.Value = "light"; break;
|
||||
case 2: Settings.Properties.Theme.Value = "system"; break;
|
||||
}
|
||||
|
||||
_themeIndex = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int OverlayOpacity
|
||||
{
|
||||
get
|
||||
{
|
||||
return _opacity;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (_opacity != value)
|
||||
{
|
||||
_opacity = value;
|
||||
Settings.Properties.OverlayOpacity.Value = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string DisabledApps
|
||||
{
|
||||
get
|
||||
{
|
||||
return _disabledApps;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _disabledApps)
|
||||
{
|
||||
_disabledApps = value;
|
||||
Settings.Properties.DisabledApps.Value = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string GetSettingsSubPath()
|
||||
{
|
||||
return _settingsConfigFileFolder + "\\" + ModuleName;
|
||||
}
|
||||
|
||||
public void NotifyPropertyChanged([CallerMemberName] string propertyName = null)
|
||||
{
|
||||
OnPropertyChanged(propertyName);
|
||||
|
||||
SndShortcutGuideSettings outsettings = new SndShortcutGuideSettings(Settings);
|
||||
SndModuleSettings<SndShortcutGuideSettings> ipcMessage = new SndModuleSettings<SndShortcutGuideSettings>(outsettings);
|
||||
SendConfigMSG(ipcMessage.ToJsonString());
|
||||
SettingsUtils.SaveSettings(Settings.ToJsonString(), ModuleName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,452 +0,0 @@
|
||||
// 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;
|
||||
using System.Globalization;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.PowerToys.Settings.UI.Library;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.ViewModels.Commands;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
||||
{
|
||||
public class VideoConferenceViewModel : Observable
|
||||
{
|
||||
private readonly ISettingsUtils _settingsUtils;
|
||||
|
||||
private VideoConferenceSettings Settings { get; set; }
|
||||
|
||||
private GeneralSettings GeneralSettingsConfig { get; set; }
|
||||
|
||||
private const string ModuleName = "Video Conference";
|
||||
|
||||
private Func<string, int> SendConfigMSG { get; }
|
||||
|
||||
private Func<Task<string>> PickFileDialog { get; }
|
||||
|
||||
private string _settingsConfigFileFolder = string.Empty;
|
||||
|
||||
public VideoConferenceViewModel(
|
||||
ISettingsUtils settingsUtils,
|
||||
ISettingsRepository<GeneralSettings> settingsRepository,
|
||||
ISettingsRepository<VideoConferenceSettings> videoConferenceSettingsRepository,
|
||||
Func<string, int> ipcMSGCallBackFunc,
|
||||
Func<Task<string>> pickFileDialog,
|
||||
string configFileSubfolder = "")
|
||||
{
|
||||
PickFileDialog = pickFileDialog;
|
||||
|
||||
if (settingsRepository == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(settingsRepository));
|
||||
}
|
||||
|
||||
GeneralSettingsConfig = settingsRepository.SettingsConfig;
|
||||
|
||||
_settingsUtils = settingsUtils ?? throw new ArgumentNullException(nameof(settingsUtils));
|
||||
|
||||
SendConfigMSG = ipcMSGCallBackFunc;
|
||||
|
||||
_settingsConfigFileFolder = configFileSubfolder;
|
||||
|
||||
if (videoConferenceSettingsRepository == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(videoConferenceSettingsRepository));
|
||||
}
|
||||
|
||||
Settings = videoConferenceSettingsRepository.SettingsConfig;
|
||||
|
||||
CameraNames = interop.CommonManaged.GetAllVideoCaptureDeviceNames();
|
||||
MicrophoneNames = interop.CommonManaged.GetAllActiveMicrophoneDeviceNames();
|
||||
MicrophoneNames.Insert(0, "[All]");
|
||||
|
||||
var shouldSaveSettings = false;
|
||||
|
||||
if (string.IsNullOrEmpty(Settings.Properties.SelectedCamera.Value) && CameraNames.Count != 0)
|
||||
{
|
||||
_selectedCameraIndex = 0;
|
||||
Settings.Properties.SelectedCamera.Value = CameraNames[0];
|
||||
shouldSaveSettings = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
_selectedCameraIndex = CameraNames.FindIndex(name => name == Settings.Properties.SelectedCamera.Value);
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(Settings.Properties.SelectedMicrophone.Value))
|
||||
{
|
||||
_selectedMicrophoneIndex = 0;
|
||||
Settings.Properties.SelectedMicrophone.Value = MicrophoneNames[0];
|
||||
shouldSaveSettings = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
_selectedMicrophoneIndex = MicrophoneNames.FindIndex(name => name == Settings.Properties.SelectedMicrophone.Value);
|
||||
}
|
||||
|
||||
_isEnabled = GeneralSettingsConfig.Enabled.VideoConference;
|
||||
_cameraAndMicrophoneMuteHotkey = Settings.Properties.MuteCameraAndMicrophoneHotkey.Value;
|
||||
_microphoneMuteHotkey = Settings.Properties.MuteMicrophoneHotkey.Value;
|
||||
_cameraMuteHotkey = Settings.Properties.MuteCameraHotkey.Value;
|
||||
CameraImageOverlayPath = Settings.Properties.CameraOverlayImagePath.Value;
|
||||
SelectOverlayImage = new ButtonClickCommand(SelectOverlayImageAction);
|
||||
ClearOverlayImage = new ButtonClickCommand(ClearOverlayImageAction);
|
||||
|
||||
switch (Settings.Properties.ToolbarPosition.Value)
|
||||
{
|
||||
case "Top left corner":
|
||||
_toolbarPositionIndex = 0;
|
||||
break;
|
||||
case "Top center":
|
||||
_toolbarPositionIndex = 1;
|
||||
break;
|
||||
case "Top right corner":
|
||||
_toolbarPositionIndex = 2;
|
||||
break;
|
||||
case "Bottom left corner":
|
||||
_toolbarPositionIndex = 3;
|
||||
break;
|
||||
case "Bottom center":
|
||||
_toolbarPositionIndex = 4;
|
||||
break;
|
||||
case "Bottom right corner":
|
||||
_toolbarPositionIndex = 5;
|
||||
break;
|
||||
}
|
||||
|
||||
switch (Settings.Properties.ToolbarMonitor.Value)
|
||||
{
|
||||
case "Main monitor":
|
||||
_toolbarMonitorIndex = 0;
|
||||
break;
|
||||
|
||||
case "All monitors":
|
||||
_toolbarMonitorIndex = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
switch (Settings.Properties.ToolbarHide.Value)
|
||||
{
|
||||
case "Never":
|
||||
_toolbarHideIndex = 0;
|
||||
break;
|
||||
case "When both camera and microphone are unmuted":
|
||||
_toolbarHideIndex = 1;
|
||||
break;
|
||||
case "When both camera and microphone are muted":
|
||||
_toolbarHideIndex = 2;
|
||||
break;
|
||||
}
|
||||
|
||||
if (shouldSaveSettings)
|
||||
{
|
||||
_settingsUtils.SaveSettings(Settings.ToJsonString(), ModuleName);
|
||||
}
|
||||
}
|
||||
|
||||
private bool _isEnabled;
|
||||
private int _toolbarPositionIndex;
|
||||
private int _toolbarMonitorIndex;
|
||||
private int _toolbarHideIndex;
|
||||
private HotkeySettings _cameraAndMicrophoneMuteHotkey;
|
||||
private HotkeySettings _microphoneMuteHotkey;
|
||||
private HotkeySettings _cameraMuteHotkey;
|
||||
private int _selectedCameraIndex = -1;
|
||||
private int _selectedMicrophoneIndex;
|
||||
|
||||
public List<string> CameraNames { get; }
|
||||
|
||||
public List<string> MicrophoneNames { get; }
|
||||
|
||||
public string CameraImageOverlayPath { get; set; }
|
||||
|
||||
public ButtonClickCommand SelectOverlayImage { get; set; }
|
||||
|
||||
public ButtonClickCommand ClearOverlayImage { get; set; }
|
||||
|
||||
private void ClearOverlayImageAction()
|
||||
{
|
||||
CameraImageOverlayPath = string.Empty;
|
||||
Settings.Properties.CameraOverlayImagePath = string.Empty;
|
||||
RaisePropertyChanged(nameof(CameraImageOverlayPath));
|
||||
}
|
||||
|
||||
private async void SelectOverlayImageAction()
|
||||
{
|
||||
try
|
||||
{
|
||||
string pickedImage = await PickFileDialog().ConfigureAwait(true);
|
||||
if (pickedImage != null)
|
||||
{
|
||||
CameraImageOverlayPath = pickedImage;
|
||||
Settings.Properties.CameraOverlayImagePath = pickedImage;
|
||||
RaisePropertyChanged(nameof(CameraImageOverlayPath));
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public int SelectedCameraIndex
|
||||
{
|
||||
get
|
||||
{
|
||||
return _selectedCameraIndex;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (_selectedCameraIndex != value)
|
||||
{
|
||||
_selectedCameraIndex = value;
|
||||
if (_selectedCameraIndex >= 0 && _selectedCameraIndex < CameraNames.Count)
|
||||
{
|
||||
Settings.Properties.SelectedCamera.Value = CameraNames[_selectedCameraIndex];
|
||||
RaisePropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int SelectedMicrophoneIndex
|
||||
{
|
||||
get
|
||||
{
|
||||
return _selectedMicrophoneIndex;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (_selectedMicrophoneIndex != value)
|
||||
{
|
||||
_selectedMicrophoneIndex = value;
|
||||
if (_selectedMicrophoneIndex >= 0 && _selectedMicrophoneIndex < MicrophoneNames.Count)
|
||||
{
|
||||
Settings.Properties.SelectedMicrophone.Value = MicrophoneNames[_selectedMicrophoneIndex];
|
||||
RaisePropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
return _isEnabled;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _isEnabled)
|
||||
{
|
||||
_isEnabled = value;
|
||||
GeneralSettingsConfig.Enabled.VideoConference = value;
|
||||
OutGoingGeneralSettings snd = new OutGoingGeneralSettings(GeneralSettingsConfig);
|
||||
|
||||
SendConfigMSG(snd.ToString());
|
||||
OnPropertyChanged(nameof(IsEnabled));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsElevated
|
||||
{
|
||||
get
|
||||
{
|
||||
return GeneralSettingsConfig.IsElevated;
|
||||
}
|
||||
}
|
||||
|
||||
public HotkeySettings CameraAndMicrophoneMuteHotkey
|
||||
{
|
||||
get
|
||||
{
|
||||
return _cameraAndMicrophoneMuteHotkey;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _cameraAndMicrophoneMuteHotkey)
|
||||
{
|
||||
_cameraAndMicrophoneMuteHotkey = value;
|
||||
Settings.Properties.MuteCameraAndMicrophoneHotkey.Value = value;
|
||||
RaisePropertyChanged(nameof(CameraAndMicrophoneMuteHotkey));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public HotkeySettings MicrophoneMuteHotkey
|
||||
{
|
||||
get
|
||||
{
|
||||
return _microphoneMuteHotkey;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _microphoneMuteHotkey)
|
||||
{
|
||||
_microphoneMuteHotkey = value;
|
||||
Settings.Properties.MuteMicrophoneHotkey.Value = value;
|
||||
RaisePropertyChanged(nameof(MicrophoneMuteHotkey));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public HotkeySettings CameraMuteHotkey
|
||||
{
|
||||
get
|
||||
{
|
||||
return _cameraMuteHotkey;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _cameraMuteHotkey)
|
||||
{
|
||||
_cameraMuteHotkey = value;
|
||||
Settings.Properties.MuteCameraHotkey.Value = value;
|
||||
RaisePropertyChanged(nameof(CameraMuteHotkey));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int ToolbarPositionIndex
|
||||
{
|
||||
get
|
||||
{
|
||||
return _toolbarPositionIndex;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (_toolbarPositionIndex != value)
|
||||
{
|
||||
_toolbarPositionIndex = value;
|
||||
switch (_toolbarPositionIndex)
|
||||
{
|
||||
case 0:
|
||||
Settings.Properties.ToolbarPosition.Value = "Top left corner";
|
||||
break;
|
||||
|
||||
case 1:
|
||||
Settings.Properties.ToolbarPosition.Value = "Top center";
|
||||
break;
|
||||
|
||||
case 2:
|
||||
Settings.Properties.ToolbarPosition.Value = "Top right corner";
|
||||
break;
|
||||
|
||||
case 3:
|
||||
Settings.Properties.ToolbarPosition.Value = "Bottom left corner";
|
||||
break;
|
||||
|
||||
case 4:
|
||||
Settings.Properties.ToolbarPosition.Value = "Bottom center";
|
||||
break;
|
||||
|
||||
case 5:
|
||||
Settings.Properties.ToolbarPosition.Value = "Bottom right corner";
|
||||
break;
|
||||
}
|
||||
|
||||
RaisePropertyChanged(nameof(ToolbarPositionIndex));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int ToolbarMonitorIndex
|
||||
{
|
||||
get
|
||||
{
|
||||
return _toolbarMonitorIndex;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (_toolbarMonitorIndex != value)
|
||||
{
|
||||
_toolbarMonitorIndex = value;
|
||||
switch (_toolbarMonitorIndex)
|
||||
{
|
||||
case 0:
|
||||
Settings.Properties.ToolbarMonitor.Value = "Main monitor";
|
||||
break;
|
||||
|
||||
case 1:
|
||||
Settings.Properties.ToolbarMonitor.Value = "All monitors";
|
||||
break;
|
||||
}
|
||||
|
||||
RaisePropertyChanged(nameof(ToolbarMonitorIndex));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int ToolbarHideIndex
|
||||
{
|
||||
get
|
||||
{
|
||||
return _toolbarHideIndex;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _toolbarHideIndex)
|
||||
{
|
||||
_toolbarHideIndex = value;
|
||||
switch (_toolbarHideIndex)
|
||||
{
|
||||
case 0:
|
||||
Settings.Properties.ToolbarHide.Value = "Never";
|
||||
break;
|
||||
case 1:
|
||||
Settings.Properties.ToolbarHide.Value = "When both camera and microphone are unmuted";
|
||||
break;
|
||||
case 2:
|
||||
Settings.Properties.ToolbarHide.Value = "When both camera and microphone are muted";
|
||||
break;
|
||||
}
|
||||
|
||||
RaisePropertyChanged(nameof(ToolbarHideIndex));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string GetSettingsSubPath()
|
||||
{
|
||||
return _settingsConfigFileFolder + (string.IsNullOrEmpty(_settingsConfigFileFolder) ? string.Empty : "\\") + ModuleName;
|
||||
}
|
||||
|
||||
public void RaisePropertyChanged([CallerMemberName] string propertyName = null)
|
||||
{
|
||||
OnPropertyChanged(propertyName);
|
||||
|
||||
_settingsUtils.SaveSettings(Settings.ToJsonString(), GetSettingsSubPath());
|
||||
|
||||
SendConfigMSG(
|
||||
string.Format(
|
||||
CultureInfo.InvariantCulture,
|
||||
"{{ \"powertoys\": {{ \"{0}\": {1} }} }}",
|
||||
ModuleName,
|
||||
JsonSerializer.Serialize(Settings)));
|
||||
}
|
||||
}
|
||||
|
||||
[ComImport]
|
||||
[Guid("3E68D4BD-7135-4D10-8018-9FB6D9F33FA1")]
|
||||
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
||||
public interface IInitializeWithWindow
|
||||
{
|
||||
void Initialize(IntPtr hwnd);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user