mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-04 10:16:24 +02:00
[Settings, Common.UI, runner exe] Unify exe/dll naming (#15005)
* Unify exe/dll naming - PowerToys.Runner Align naming with other exes - PowerToys Runner -> PowerToys.Runner * Unify exe/dll naming - Microsoft.PowerToys.Common.UI Project name - Microsoft.PowerToys.Common.UI -> Common.UI dll name - Microsoft.PowerToys.Common.UI.dll -> PowerToys.Common.UI.dll * Unify exe/dll naming - Settings Project names - Microsoft.PowerToys.Settings* -> Settings* Dll names - Microsoft.PowerToys.Settings*.dll -> PowerToys.Settings*.dll * Revert file autoformat * [Docs] Update paths to settings projects/files * Fix tests - Update path
This commit is contained in:
157
src/settings-ui/Settings.UI.Library/ViewModels/AwakeViewModel.cs
Normal file
157
src/settings-ui/Settings.UI.Library/ViewModels/AwakeViewModel.cs
Normal file
@@ -0,0 +1,157 @@
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,331 @@
|
||||
// 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, 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 (_settingsUtils.SettingsExists(ColorPickerSettings.ModuleName))
|
||||
{
|
||||
_colorPickerSettings = _settingsUtils.GetSettingsOrDefault<ColorPickerSettings>(ColorPickerSettings.ModuleName);
|
||||
}
|
||||
else
|
||||
{
|
||||
_colorPickerSettings = new ColorPickerSettings();
|
||||
}
|
||||
|
||||
_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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
// 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.Windows.Input;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels.Commands
|
||||
{
|
||||
public class ButtonClickCommand : ICommand
|
||||
{
|
||||
private readonly Action _execute;
|
||||
|
||||
public ButtonClickCommand(Action execute)
|
||||
{
|
||||
_execute = execute;
|
||||
}
|
||||
|
||||
// Occurs when changes occur that affect whether or not the command should execute.
|
||||
public event EventHandler CanExecuteChanged;
|
||||
|
||||
// Defines the method that determines whether the command can execute in its current state.
|
||||
public bool CanExecute(object parameter)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// Defines the method to be called when the command is invoked.
|
||||
public void Execute(object parameter)
|
||||
{
|
||||
_execute();
|
||||
}
|
||||
|
||||
public void OnCanExecuteChanged() => CanExecuteChanged?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
// 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.Windows.Input;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels.Commands
|
||||
{
|
||||
public class RelayCommand : ICommand
|
||||
{
|
||||
private readonly Action _execute;
|
||||
private readonly Func<bool> _canExecute;
|
||||
|
||||
public event EventHandler CanExecuteChanged;
|
||||
|
||||
public RelayCommand(Action execute)
|
||||
: this(execute, null)
|
||||
{
|
||||
}
|
||||
|
||||
public RelayCommand(Action execute, Func<bool> canExecute)
|
||||
{
|
||||
_execute = execute ?? throw new ArgumentNullException(nameof(execute));
|
||||
_canExecute = canExecute;
|
||||
}
|
||||
|
||||
public bool CanExecute(object parameter) => _canExecute == null || _canExecute();
|
||||
|
||||
public void Execute(object parameter) => _execute();
|
||||
|
||||
public void OnCanExecuteChanged() => CanExecuteChanged?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
// 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.Windows.Input;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels.Commands
|
||||
{
|
||||
public class RelayCommand<T> : ICommand
|
||||
{
|
||||
private readonly Action<T> execute;
|
||||
|
||||
private readonly Func<T, bool> canExecute;
|
||||
|
||||
public event EventHandler CanExecuteChanged;
|
||||
|
||||
public RelayCommand(Action<T> execute)
|
||||
: this(execute, null)
|
||||
{
|
||||
}
|
||||
|
||||
public RelayCommand(Action<T> execute, Func<T, bool> canExecute)
|
||||
{
|
||||
this.execute = execute ?? throw new ArgumentNullException(nameof(execute));
|
||||
this.canExecute = canExecute;
|
||||
}
|
||||
|
||||
public bool CanExecute(object parameter) => canExecute == null || canExecute((T)parameter);
|
||||
|
||||
public void Execute(object parameter) => execute((T)parameter);
|
||||
|
||||
public void OnCanExecuteChanged() => CanExecuteChanged?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,757 @@
|
||||
// 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.Drawing;
|
||||
using System.Globalization;
|
||||
using System.Runtime.CompilerServices;
|
||||
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 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 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;
|
||||
_highlightOpacity = Settings.Properties.FancyzonesHighlightOpacity.Value;
|
||||
_excludedApps = Settings.Properties.FancyzonesExcludedApps.Value;
|
||||
_systemTheme = Settings.Properties.FancyzonesSystemTheme.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 : "#F5FCFF";
|
||||
|
||||
string borderColor = Settings.Properties.FancyzonesBorderColor.Value;
|
||||
_zoneBorderColor = !string.IsNullOrEmpty(borderColor) ? borderColor : "#FFFFFF";
|
||||
|
||||
string highlightColor = Settings.Properties.FancyzonesZoneHighlightColor.Value;
|
||||
_zoneHighlightColor = !string.IsNullOrEmpty(highlightColor) ? highlightColor : "#0078D7";
|
||||
|
||||
_isEnabled = GeneralSettingsConfig.Enabled.FancyZones;
|
||||
}
|
||||
|
||||
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 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;
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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
|
||||
{
|
||||
// The fallback value is based on ToRGBHex's behavior, which returns
|
||||
// #FFFFFF if any exceptions are encountered, e.g. from passing in a null value.
|
||||
// This extra handling is added here to deal with FxCop warnings.
|
||||
value = (value != null) ? SettingsUtilities.ToRGBHex(value) : "#FFFFFF";
|
||||
if (!value.Equals(_zoneHighlightColor, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
_zoneHighlightColor = value;
|
||||
Settings.Properties.FancyzonesZoneHighlightColor.Value = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string ZoneBorderColor
|
||||
{
|
||||
get
|
||||
{
|
||||
return _zoneBorderColor;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
// The fallback value is based on ToRGBHex's behavior, which returns
|
||||
// #FFFFFF if any exceptions are encountered, e.g. from passing in a null value.
|
||||
// This extra handling is added here to deal with FxCop warnings.
|
||||
value = (value != null) ? SettingsUtilities.ToRGBHex(value) : "#FFFFFF";
|
||||
if (!value.Equals(_zoneBorderColor, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
_zoneBorderColor = value;
|
||||
Settings.Properties.FancyzonesBorderColor.Value = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string ZoneInActiveColor
|
||||
{
|
||||
get
|
||||
{
|
||||
return _zoneInActiveColor;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
// The fallback value is based on ToRGBHex's behavior, which returns
|
||||
// #FFFFFF if any exceptions are encountered, e.g. from passing in a null value.
|
||||
// This extra handling is added here to deal with FxCop warnings.
|
||||
value = (value != null) ? SettingsUtilities.ToRGBHex(value) : "#FFFFFF";
|
||||
if (!value.Equals(_zoneInActiveColor, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
_zoneInActiveColor = value;
|
||||
Settings.Properties.FancyzonesInActiveColor.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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,506 @@
|
||||
// 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.Diagnostics.CodeAnalysis;
|
||||
using System.IO.Abstractions;
|
||||
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 GeneralViewModel : Observable
|
||||
{
|
||||
private GeneralSettings GeneralSettingsConfig { get; set; }
|
||||
|
||||
private UpdatingSettings UpdatingSettingsConfig { get; set; }
|
||||
|
||||
public ButtonClickCommand CheckForUpdatesEventHandler { 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;
|
||||
|
||||
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)
|
||||
{
|
||||
CheckForUpdatesEventHandler = new ButtonClickCommand(CheckForUpdatesClick);
|
||||
RestartElevatedButtonEventHandler = new ButtonClickCommand(RestartElevated);
|
||||
UpdateNowButtonEventHandler = new ButtonClickCommand(UpdateNowClick);
|
||||
|
||||
// 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 fxcop
|
||||
// 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;
|
||||
|
||||
// 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 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);
|
||||
}
|
||||
#pragma warning disable CA1031 // Do not catch general exception types
|
||||
catch (Exception e)
|
||||
#pragma warning restore CA1031 // Do not catch general exception types
|
||||
{
|
||||
Logger.LogError("Exception encountered when changing Settings theme", e);
|
||||
}
|
||||
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// FxCop suggests marking this member static, but it is accessed through
|
||||
// an instance in autogenerated files (GeneralPage.g.cs) and will break
|
||||
// the file if modified
|
||||
#pragma warning disable CA1822 // Mark members as static
|
||||
public string PowerToysVersion
|
||||
#pragma warning restore CA1822 // Mark members as static
|
||||
{
|
||||
get
|
||||
{
|
||||
return Helper.GetProductVersion();
|
||||
}
|
||||
}
|
||||
|
||||
public string UpdateCheckedDate
|
||||
{
|
||||
get
|
||||
{
|
||||
RequestUpdateCheckedDate();
|
||||
return _updateCheckedDate;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (_updateCheckedDate != value)
|
||||
{
|
||||
_updateCheckedDate = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 IsDownloadAllowed
|
||||
{
|
||||
get
|
||||
{
|
||||
return AutoUpdatesEnabled && !IsNewVersionDownloading;
|
||||
}
|
||||
}
|
||||
|
||||
public void NotifyPropertyChanged([CallerMemberName] string propertyName = null)
|
||||
{
|
||||
// Notify UI of property change
|
||||
OnPropertyChanged(propertyName);
|
||||
OutGoingGeneralSettings outsettings = new OutGoingGeneralSettings(GeneralSettingsConfig);
|
||||
|
||||
SendConfigMSG(outsettings.ToString());
|
||||
}
|
||||
|
||||
// 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/" });
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
public void RefreshUpdatingState()
|
||||
{
|
||||
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 || config.ToJsonString() == UpdatingSettingsConfig.ToJsonString())
|
||||
{
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,405 @@
|
||||
// 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.Diagnostics.CodeAnalysis;
|
||||
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; }
|
||||
|
||||
[SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "Exceptions should not crash the program but will be logged until we can understand common exception scenarios")]
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#pragma warning disable CA2227 // Collection properties should be read only
|
||||
public ObservableCollection<ImageSize> Sizes
|
||||
#pragma warning restore CA2227 // Collection properties should be read only
|
||||
{
|
||||
get
|
||||
{
|
||||
return _advancedSizes;
|
||||
}
|
||||
|
||||
// FxCop demands collection properties to be read-only, but this
|
||||
// setter is used in autogenerated files (ImageResizerPage.g.cs)
|
||||
// and replacing the setter with its own method will break the file
|
||||
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.Where<ImageSize>(x => x.Id == id).First();
|
||||
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.Where<ImageSize>(x => x.Id == modifiedSize.Id).First().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.Substring(namePrefix.Length), out int number))
|
||||
{
|
||||
if (newSizeCounter < number)
|
||||
{
|
||||
newSizeCounter = number;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $"{namePrefix} {++newSizeCounter}";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,297 @@
|
||||
// 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.Diagnostics.CodeAnalysis;
|
||||
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; }
|
||||
|
||||
[SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "Exceptions should not crash the program but will be logged until we can understand common exception scenarios")]
|
||||
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);
|
||||
}
|
||||
|
||||
[SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "Exceptions here (especially mutex errors) should not halt app execution, but they will be logged.")]
|
||||
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)} {Process.GetCurrentProcess().Id}");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.LogError($"Exception encountered when opening an {PowerToyName} editor", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void NotifyFileChanged()
|
||||
{
|
||||
OnPropertyChanged(nameof(RemapKeys));
|
||||
OnPropertyChanged(nameof(RemapShortcuts));
|
||||
}
|
||||
|
||||
[SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "Exceptions here (especially mutex errors) should not halt app execution, but they will be logged.")]
|
||||
public bool LoadProfile()
|
||||
{
|
||||
// The KBM process out of runner creates the default.json file if it does not exist.
|
||||
var success = true;
|
||||
var readSuccessfully = false;
|
||||
|
||||
string fileName = Settings.Properties.ActiveConfiguration.Value + JsonFileType;
|
||||
|
||||
try
|
||||
{
|
||||
// retry loop for reading
|
||||
CancellationTokenSource ts = new CancellationTokenSource();
|
||||
Task t = Task.Run(() =>
|
||||
{
|
||||
while (!readSuccessfully && !ts.IsCancellationRequested)
|
||||
{
|
||||
if (_settingsUtils.SettingsExists(PowerToyName, fileName))
|
||||
{
|
||||
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).Wait();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
t.Wait(1000, ts.Token);
|
||||
ts.Cancel();
|
||||
ts.Dispose();
|
||||
|
||||
if (!readSuccessfully)
|
||||
{
|
||||
success = false;
|
||||
}
|
||||
|
||||
FilterRemapKeysList(_profile?.RemapKeys?.InProcessRemapKeys);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// Failed to load the configuration.
|
||||
Logger.LogError($"Exception encountered when loading {PowerToyName} profile", e);
|
||||
success = false;
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,420 @@
|
||||
// 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; }
|
||||
|
||||
public MouseUtilsViewModel(ISettingsUtils settingsUtils, ISettingsRepository<GeneralSettings> settingsRepository, ISettingsRepository<FindMyMouseSettings> findMyMouseSettingsRepository, ISettingsRepository<MouseHighlighterSettings> mouseHighlighterSettingsRepository, 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;
|
||||
|
||||
// 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;
|
||||
_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;
|
||||
|
||||
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;
|
||||
|
||||
// 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 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 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
|
||||
{
|
||||
// The fallback value is based on ToRGBHex's behavior, which returns
|
||||
// #FFFFFF if any exceptions are encountered, e.g. from passing in a null value.
|
||||
// This extra handling is added here to deal with FxCop warnings.
|
||||
value = (value != null) ? SettingsUtilities.ToRGBHex(value) : "#FFFFFF";
|
||||
if (!value.Equals(_highlighterLeftButtonClickColor, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
_highlighterLeftButtonClickColor = value;
|
||||
MouseHighlighterSettingsConfig.Properties.LeftButtonClickColor.Value = value;
|
||||
NotifyMouseHighlighterPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string MouseHighlighterRightButtonClickColor
|
||||
{
|
||||
get
|
||||
{
|
||||
return _highlighterRightButtonClickColor;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
// The fallback value is based on ToRGBHex's behavior, which returns
|
||||
// #FFFFFF if any exceptions are encountered, e.g. from passing in a null value.
|
||||
// This extra handling is added here to deal with FxCop warnings.
|
||||
value = (value != null) ? SettingsUtilities.ToRGBHex(value) : "#FFFFFF";
|
||||
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);
|
||||
}
|
||||
|
||||
private Func<string, int> SendConfigMSG { get; }
|
||||
|
||||
private bool _isFindMyMouseEnabled;
|
||||
private bool _findMyMouseDoNotActivateOnGameMode;
|
||||
private string _findMyMouseBackgroundColor;
|
||||
private string _findMyMouseSpotlightColor;
|
||||
private int _findMyMouseOverlayOpacity;
|
||||
private int _findMyMouseSpotlightRadius;
|
||||
private int _findMyMouseAnimationDurationMs;
|
||||
private int _findMyMouseSpotlightInitialZoom;
|
||||
|
||||
private bool _isMouseHighlighterEnabled;
|
||||
private string _highlighterLeftButtonClickColor;
|
||||
private string _highlighterRightButtonClickColor;
|
||||
private int _highlighterOpacity;
|
||||
private int _highlighterRadius;
|
||||
private int _highlightFadeDelayMs;
|
||||
private int _highlightFadeDurationMs;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
// 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 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
// 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(ShowNotAllowedKeywordWarning));
|
||||
NotifyPropertyChanged(nameof(Enabled));
|
||||
NotifyPropertyChanged(nameof(DisabledOpacity));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool Enabled => !Disabled;
|
||||
|
||||
public double DisabledOpacity => Disabled ? 0.5 : 1;
|
||||
|
||||
public bool IsGlobal
|
||||
{
|
||||
get
|
||||
{
|
||||
return settings.IsGlobal;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (settings.IsGlobal != value)
|
||||
{
|
||||
settings.IsGlobal = value;
|
||||
NotifyPropertyChanged();
|
||||
NotifyPropertyChanged(nameof(ShowNotAccessibleWarning));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string ActionKeyword
|
||||
{
|
||||
get
|
||||
{
|
||||
return settings.ActionKeyword;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (settings.ActionKeyword != value)
|
||||
{
|
||||
settings.ActionKeyword = value;
|
||||
NotifyPropertyChanged();
|
||||
NotifyPropertyChanged(nameof(ShowNotAccessibleWarning));
|
||||
NotifyPropertyChanged(nameof(ShowNotAllowedKeywordWarning));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
private static readonly List<string> NotAllowedKeywords = new List<string>()
|
||||
{
|
||||
"~", @"\", @"\\",
|
||||
};
|
||||
|
||||
public bool ShowNotAllowedKeywordWarning
|
||||
{
|
||||
get => !Disabled && NotAllowedKeywords.Contains(ActionKeyword);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,442 @@
|
||||
// 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;
|
||||
}
|
||||
|
||||
foreach (var plugin in Plugins)
|
||||
{
|
||||
plugin.PropertyChanged += OnPluginInfoChange;
|
||||
}
|
||||
|
||||
SearchPluginsCommand = new RelayCommand(SearchPlugins);
|
||||
}
|
||||
|
||||
private void OnPluginInfoChange(object sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
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 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)));
|
||||
}
|
||||
|
||||
return _plugins;
|
||||
}
|
||||
}
|
||||
|
||||
public bool ShowAllPluginsDisabledWarning
|
||||
{
|
||||
get => EnablePowerLauncher && Plugins.Any() && 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)));
|
||||
}
|
||||
else
|
||||
{
|
||||
_plugins = null;
|
||||
}
|
||||
|
||||
OnPropertyChanged(nameof(Plugins));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,218 @@
|
||||
// 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;
|
||||
_pdfRenderIsEnabled = Settings.Properties.EnablePdfPreview;
|
||||
_gcodeRenderIsEnabled = Settings.Properties.EnableGcodePreview;
|
||||
_pdfThumbnailIsEnabled = Settings.Properties.EnablePdfThumbnail;
|
||||
_gcodeThumbnailIsEnabled = Settings.Properties.EnableGcodeThumbnail;
|
||||
}
|
||||
|
||||
private bool _svgRenderIsEnabled;
|
||||
private bool _mdRenderIsEnabled;
|
||||
private bool _pdfRenderIsEnabled;
|
||||
private bool _gcodeRenderIsEnabled;
|
||||
private bool _svgThumbnailIsEnabled;
|
||||
private bool _pdfThumbnailIsEnabled;
|
||||
private bool _gcodeThumbnailIsEnabled;
|
||||
|
||||
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 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 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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,240 @@
|
||||
// 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.CodeAnalysis;
|
||||
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; }
|
||||
|
||||
[SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "Exceptions should not crash the program but will be logged until we can understand common exception scenarios")]
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,225 @@
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,426 @@
|
||||
// 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.Linq;
|
||||
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
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.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, 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;
|
||||
|
||||
try
|
||||
{
|
||||
Settings = _settingsUtils.GetSettings<VideoConferenceSettings>(GetSettingsSubPath());
|
||||
}
|
||||
#pragma warning disable CA1031 // Do not catch general exception types
|
||||
catch
|
||||
#pragma warning restore CA1031 // Do not catch general exception types
|
||||
{
|
||||
Settings = new VideoConferenceSettings();
|
||||
_settingsUtils.SaveSettings(Settings.ToJsonString(), GetSettingsSubPath());
|
||||
}
|
||||
|
||||
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;
|
||||
_mirophoneMuteHotkey = Settings.Properties.MuteMicrophoneHotkey.Value;
|
||||
_cameraMuteHotkey = Settings.Properties.MuteCameraHotkey.Value;
|
||||
CameraImageOverlayPath = Settings.Properties.CameraOverlayImagePath.Value;
|
||||
SelectOverlayImage = new ButtonClickCommand(SelectOverlayImageAction);
|
||||
ClearOverlayImage = new ButtonClickCommand(ClearOverlayImageAction);
|
||||
|
||||
_hideToolbarWhenUnmuted = Settings.Properties.HideToolbarWhenUnmuted.Value;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
if (shouldSaveSettings)
|
||||
{
|
||||
_settingsUtils.SaveSettings(Settings.ToJsonString(), ModuleName);
|
||||
}
|
||||
}
|
||||
|
||||
private bool _isEnabled;
|
||||
private int _toolbarPositionIndex;
|
||||
private int _toolbarMonitorIndex;
|
||||
private HotkeySettings _cameraAndMicrophoneMuteHotkey;
|
||||
private HotkeySettings _mirophoneMuteHotkey;
|
||||
private HotkeySettings _cameraMuteHotkey;
|
||||
private int _selectedCameraIndex = -1;
|
||||
private int _selectedMicrophoneIndex;
|
||||
private bool _hideToolbarWhenUnmuted;
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
#pragma warning disable CA1031 // Do not catch general exception types
|
||||
catch
|
||||
#pragma warning restore CA1031 // Do not catch general exception types
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
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 _mirophoneMuteHotkey;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _mirophoneMuteHotkey)
|
||||
{
|
||||
_mirophoneMuteHotkey = 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 ToolbarPostionIndex
|
||||
{
|
||||
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(ToolbarPostionIndex));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 bool HideToolbarWhenUnmuted
|
||||
{
|
||||
get
|
||||
{
|
||||
return _hideToolbarWhenUnmuted;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _hideToolbarWhenUnmuted)
|
||||
{
|
||||
_hideToolbarWhenUnmuted = value;
|
||||
Settings.Properties.HideToolbarWhenUnmuted.Value = value;
|
||||
RaisePropertyChanged(nameof(HideToolbarWhenUnmuted));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string GetSettingsSubPath()
|
||||
{
|
||||
return _settingsConfigFileFolder + "\\" + ModuleName;
|
||||
}
|
||||
|
||||
#pragma warning disable CA1030 // Use events where appropriate
|
||||
public void RaisePropertyChanged([CallerMemberName] string propertyName = null)
|
||||
#pragma warning restore CA1030 // Use events where appropriate
|
||||
{
|
||||
OnPropertyChanged(propertyName);
|
||||
SndVideoConferenceSettings outsettings = new SndVideoConferenceSettings(Settings);
|
||||
SndModuleSettings<SndVideoConferenceSettings> ipcMessage = new SndModuleSettings<SndVideoConferenceSettings>(outsettings);
|
||||
SendConfigMSG(ipcMessage.ToJsonString());
|
||||
_settingsUtils.SaveSettings(Settings.ToJsonString(), GetSettingsSubPath());
|
||||
}
|
||||
}
|
||||
|
||||
[ComImport]
|
||||
[Guid("3E68D4BD-7135-4D10-8018-9FB6D9F33FA1")]
|
||||
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
||||
public interface IInitializeWithWindow
|
||||
{
|
||||
void Initialize(IntPtr hwnd);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user