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:
@@ -0,0 +1,39 @@
|
||||
// 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.Text.Json.Serialization;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public class AppSpecificKeysDataModel : KeysDataModel
|
||||
{
|
||||
[JsonPropertyName("targetApp")]
|
||||
public string TargetApp { get; set; }
|
||||
|
||||
public new List<string> GetMappedOriginalKeys()
|
||||
{
|
||||
return base.GetMappedOriginalKeys();
|
||||
}
|
||||
|
||||
public new List<string> GetMappedNewRemapKeys()
|
||||
{
|
||||
return base.GetMappedNewRemapKeys();
|
||||
}
|
||||
|
||||
public bool Compare(AppSpecificKeysDataModel arg)
|
||||
{
|
||||
if (arg == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(arg));
|
||||
}
|
||||
|
||||
// Using Ordinal comparison for internal text
|
||||
return OriginalKeys.Equals(arg.OriginalKeys, StringComparison.Ordinal) &&
|
||||
NewRemapKeys.Equals(arg.NewRemapKeys, StringComparison.Ordinal) &&
|
||||
TargetApp.Equals(arg.TargetApp, StringComparison.Ordinal);
|
||||
}
|
||||
}
|
||||
}
|
||||
38
src/settings-ui/Settings.UI.Library/AwakeProperties.cs
Normal file
38
src/settings-ui/Settings.UI.Library/AwakeProperties.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
// 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.Text.Json.Serialization;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public class AwakeProperties
|
||||
{
|
||||
public AwakeProperties()
|
||||
{
|
||||
KeepDisplayOn = false;
|
||||
Mode = AwakeMode.PASSIVE;
|
||||
Hours = 0;
|
||||
Minutes = 0;
|
||||
}
|
||||
|
||||
[JsonPropertyName("awake_keep_display_on")]
|
||||
public bool KeepDisplayOn { get; set; }
|
||||
|
||||
[JsonPropertyName("awake_mode")]
|
||||
public AwakeMode Mode { get; set; }
|
||||
|
||||
[JsonPropertyName("awake_hours")]
|
||||
public uint Hours { get; set; }
|
||||
|
||||
[JsonPropertyName("awake_minutes")]
|
||||
public uint Minutes { get; set; }
|
||||
}
|
||||
|
||||
public enum AwakeMode
|
||||
{
|
||||
PASSIVE = 0,
|
||||
INDEFINITE = 1,
|
||||
TIMED = 2,
|
||||
}
|
||||
}
|
||||
35
src/settings-ui/Settings.UI.Library/AwakeSettings.cs
Normal file
35
src/settings-ui/Settings.UI.Library/AwakeSettings.cs
Normal file
@@ -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.Text.Json.Serialization;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public class AwakeSettings : BasePTModuleSettings, ISettingsConfig
|
||||
{
|
||||
public const string ModuleName = "Awake";
|
||||
public const string ModuleVersion = "0.0.1";
|
||||
|
||||
public AwakeSettings()
|
||||
{
|
||||
Name = ModuleName;
|
||||
Version = ModuleVersion;
|
||||
Properties = new AwakeProperties();
|
||||
}
|
||||
|
||||
[JsonPropertyName("properties")]
|
||||
public AwakeProperties Properties { get; set; }
|
||||
|
||||
public string GetModuleName()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
|
||||
public bool UpgradeSettingsConfiguration()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
38
src/settings-ui/Settings.UI.Library/BasePTModuleSettings.cs
Normal file
38
src/settings-ui/Settings.UI.Library/BasePTModuleSettings.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
// 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.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public abstract class BasePTModuleSettings
|
||||
{
|
||||
// Gets or sets name of the powertoy module.
|
||||
[JsonPropertyName("name")]
|
||||
public string Name { get; set; }
|
||||
|
||||
// Gets or sets the powertoys version.
|
||||
[JsonPropertyName("version")]
|
||||
public string Version { get; set; }
|
||||
|
||||
// converts the current to a json string.
|
||||
public virtual string ToJsonString()
|
||||
{
|
||||
// By default JsonSerializer will only serialize the properties in the base class. This can be avoided by passing the object type (more details at https://stackoverflow.com/a/62498888)
|
||||
return JsonSerializer.Serialize(this, GetType());
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return ToJsonString().GetHashCode();
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
var settings = obj as BasePTModuleSettings;
|
||||
return settings?.ToJsonString() == ToJsonString();
|
||||
}
|
||||
}
|
||||
}
|
||||
30
src/settings-ui/Settings.UI.Library/BoolProperty.cs
Normal file
30
src/settings-ui/Settings.UI.Library/BoolProperty.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
// 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.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public class BoolProperty
|
||||
{
|
||||
public BoolProperty()
|
||||
{
|
||||
Value = false;
|
||||
}
|
||||
|
||||
public BoolProperty(bool value)
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
|
||||
[JsonPropertyName("value")]
|
||||
public bool Value { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return JsonSerializer.Serialize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
// 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.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public class BoolPropertyJsonConverter : JsonConverter<bool>
|
||||
{
|
||||
public override bool Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
var boolProperty = JsonSerializer.Deserialize<BoolProperty>(ref reader, options);
|
||||
return boolProperty.Value;
|
||||
}
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, bool value, JsonSerializerOptions options)
|
||||
{
|
||||
var boolProperty = new BoolProperty(value);
|
||||
JsonSerializer.Serialize(writer, boolProperty, options);
|
||||
}
|
||||
}
|
||||
}
|
||||
102
src/settings-ui/Settings.UI.Library/ColorFormatModel.cs
Normal file
102
src/settings-ui/Settings.UI.Library/ColorFormatModel.cs
Normal file
@@ -0,0 +1,102 @@
|
||||
// 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
|
||||
{
|
||||
public class ColorFormatModel : INotifyPropertyChanged
|
||||
{
|
||||
private string _name;
|
||||
private string _example;
|
||||
private bool _isShown;
|
||||
private bool _canMoveUp = true;
|
||||
private bool _canMoveDown = true;
|
||||
|
||||
public ColorFormatModel(string name, string example, bool isShown)
|
||||
{
|
||||
Name = name;
|
||||
Example = example;
|
||||
IsShown = isShown;
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return _name;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_name = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public string Example
|
||||
{
|
||||
get
|
||||
{
|
||||
return _example;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_example = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsShown
|
||||
{
|
||||
get
|
||||
{
|
||||
return _isShown;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_isShown = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public bool CanMoveUp
|
||||
{
|
||||
get
|
||||
{
|
||||
return _canMoveUp;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_canMoveUp = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public bool CanMoveDown
|
||||
{
|
||||
get
|
||||
{
|
||||
return _canMoveDown;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_canMoveDown = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
private void OnPropertyChanged([CallerMemberName] string propertyName = null)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
}
|
||||
}
|
||||
58
src/settings-ui/Settings.UI.Library/ColorPickerProperties.cs
Normal file
58
src/settings-ui/Settings.UI.Library/ColorPickerProperties.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
// 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.Collections.Generic;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Enumerations;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public class ColorPickerProperties
|
||||
{
|
||||
public ColorPickerProperties()
|
||||
{
|
||||
ActivationShortcut = new HotkeySettings(true, false, false, true, 0x43);
|
||||
ChangeCursor = false;
|
||||
ColorHistory = new List<string>();
|
||||
ColorHistoryLimit = 20;
|
||||
VisibleColorFormats = new Dictionary<string, bool>();
|
||||
VisibleColorFormats.Add("HEX", true);
|
||||
VisibleColorFormats.Add("RGB", true);
|
||||
VisibleColorFormats.Add("HSL", true);
|
||||
ShowColorName = false;
|
||||
ActivationAction = ColorPickerActivationAction.OpenColorPickerAndThenEditor;
|
||||
}
|
||||
|
||||
public HotkeySettings ActivationShortcut { get; set; }
|
||||
|
||||
[JsonPropertyName("changecursor")]
|
||||
[JsonConverter(typeof(BoolPropertyJsonConverter))]
|
||||
public bool ChangeCursor { get; set; }
|
||||
|
||||
[JsonPropertyName("copiedcolorrepresentation")]
|
||||
public ColorRepresentationType CopiedColorRepresentation { get; set; }
|
||||
|
||||
[JsonPropertyName("activationaction")]
|
||||
public ColorPickerActivationAction ActivationAction { get; set; }
|
||||
|
||||
[JsonPropertyName("colorhistory")]
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2227:Collection properties should be read only", Justification = "Need to change this collection")]
|
||||
public List<string> ColorHistory { get; set; }
|
||||
|
||||
[JsonPropertyName("colorhistorylimit")]
|
||||
public int ColorHistoryLimit { get; set; }
|
||||
|
||||
[JsonPropertyName("visiblecolorformats")]
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2227:Collection properties should be read only", Justification = "Need to change this collection")]
|
||||
public Dictionary<string, bool> VisibleColorFormats { get; set; }
|
||||
|
||||
[JsonPropertyName("showcolorname")]
|
||||
[JsonConverter(typeof(BoolPropertyJsonConverter))]
|
||||
public bool ShowColorName { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
=> JsonSerializer.Serialize(this);
|
||||
}
|
||||
}
|
||||
49
src/settings-ui/Settings.UI.Library/ColorPickerSettings.cs
Normal file
49
src/settings-ui/Settings.UI.Library/ColorPickerSettings.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
// 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.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public class ColorPickerSettings : BasePTModuleSettings, ISettingsConfig
|
||||
{
|
||||
public const string ModuleName = "ColorPicker";
|
||||
|
||||
[JsonPropertyName("properties")]
|
||||
public ColorPickerProperties Properties { get; set; }
|
||||
|
||||
public ColorPickerSettings()
|
||||
{
|
||||
Properties = new ColorPickerProperties();
|
||||
Version = "1";
|
||||
Name = ModuleName;
|
||||
}
|
||||
|
||||
public virtual void Save(ISettingsUtils settingsUtils)
|
||||
{
|
||||
// Save settings to file
|
||||
var options = new JsonSerializerOptions
|
||||
{
|
||||
WriteIndented = true,
|
||||
};
|
||||
|
||||
if (settingsUtils == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(settingsUtils));
|
||||
}
|
||||
|
||||
settingsUtils.SaveSettings(JsonSerializer.Serialize(this, options), ModuleName);
|
||||
}
|
||||
|
||||
public string GetModuleName()
|
||||
=> Name;
|
||||
|
||||
// This can be utilized in the future if the settings.json file is to be modified/deleted.
|
||||
public bool UpgradeSettingsConfiguration()
|
||||
=> false;
|
||||
}
|
||||
}
|
||||
20
src/settings-ui/Settings.UI.Library/ConfigDefaults.cs
Normal file
20
src/settings-ui/Settings.UI.Library/ConfigDefaults.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
// 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.
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public static class ConfigDefaults
|
||||
{
|
||||
// Fancy Zones Default Colors
|
||||
public static readonly string DefaultFancyZonesZoneHighlightColor = "#0078D7";
|
||||
public static readonly string DefaultFancyZonesInActiveColor = "#F5FCFF";
|
||||
public static readonly string DefaultFancyzonesBorderColor = "#FFFFFF";
|
||||
|
||||
// Fancy Zones Default Flags.
|
||||
public static readonly bool DefaultFancyzonesShiftDrag = true;
|
||||
public static readonly bool DefaultUseCursorposEditorStartupscreen = true;
|
||||
public static readonly bool DefaultFancyzonesQuickLayoutSwitch = true;
|
||||
public static readonly bool DefaultFancyzonesFlashZonesOnQuickSwitch = true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
// 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.Text.Json.Serialization;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library.CustomAction
|
||||
{
|
||||
public class CustomActionDataModel
|
||||
{
|
||||
[JsonPropertyName("action_name")]
|
||||
public string Name { get; set; }
|
||||
|
||||
[JsonPropertyName("value")]
|
||||
public string Value { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
// 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.Text.Json;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library.CustomAction
|
||||
{
|
||||
public class CustomNamePolicy : JsonNamingPolicy
|
||||
{
|
||||
private Func<string, string> convertDelegate;
|
||||
|
||||
public CustomNamePolicy(Func<string, string> convertDelegate)
|
||||
{
|
||||
this.convertDelegate = convertDelegate;
|
||||
}
|
||||
|
||||
public override string ConvertName(string name)
|
||||
{
|
||||
return convertDelegate(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// 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.
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library.CustomAction
|
||||
{
|
||||
public class ModuleCustomAction
|
||||
{
|
||||
public CustomActionDataModel ModuleAction { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -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.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library.CustomAction
|
||||
{
|
||||
public class SendCustomAction
|
||||
{
|
||||
private readonly string moduleName;
|
||||
|
||||
public SendCustomAction(string moduleName)
|
||||
{
|
||||
this.moduleName = moduleName;
|
||||
}
|
||||
|
||||
[JsonPropertyName("action")]
|
||||
public ModuleCustomAction Action { get; set; }
|
||||
|
||||
public string ToJsonString()
|
||||
{
|
||||
var jsonSerializerOptions = new JsonSerializerOptions
|
||||
{
|
||||
PropertyNamingPolicy = new CustomNamePolicy((propertyName) =>
|
||||
{
|
||||
// Using Ordinal as this is an internal property name
|
||||
return propertyName.Equals("ModuleAction", System.StringComparison.Ordinal) ? moduleName : propertyName;
|
||||
}),
|
||||
};
|
||||
|
||||
return JsonSerializer.Serialize(this, jsonSerializerOptions);
|
||||
}
|
||||
}
|
||||
}
|
||||
33
src/settings-ui/Settings.UI.Library/DoubleProperty.cs
Normal file
33
src/settings-ui/Settings.UI.Library/DoubleProperty.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
// 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.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
// Represents the configuration property of the settings that store Double type.
|
||||
public class DoubleProperty
|
||||
{
|
||||
public DoubleProperty()
|
||||
{
|
||||
Value = 0.0;
|
||||
}
|
||||
|
||||
public DoubleProperty(double value)
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
|
||||
// Gets or sets the double value of the settings configuration.
|
||||
[JsonPropertyName("value")]
|
||||
public double Value { get; set; }
|
||||
|
||||
// Returns a JSON version of the class settings configuration class.
|
||||
public override string ToString()
|
||||
{
|
||||
return JsonSerializer.Serialize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
225
src/settings-ui/Settings.UI.Library/EnabledModules.cs
Normal file
225
src/settings-ui/Settings.UI.Library/EnabledModules.cs
Normal file
@@ -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.Runtime.CompilerServices;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using Microsoft.PowerToys.Settings.Telemetry;
|
||||
using Microsoft.PowerToys.Telemetry;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public class EnabledModules
|
||||
{
|
||||
public EnabledModules()
|
||||
{
|
||||
}
|
||||
|
||||
private bool fancyZones = true;
|
||||
|
||||
[JsonPropertyName("FancyZones")]
|
||||
public bool FancyZones
|
||||
{
|
||||
get => fancyZones;
|
||||
set
|
||||
{
|
||||
if (fancyZones != value)
|
||||
{
|
||||
LogTelemetryEvent(value);
|
||||
fancyZones = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool imageResizer = true;
|
||||
|
||||
[JsonPropertyName("Image Resizer")]
|
||||
public bool ImageResizer
|
||||
{
|
||||
get => imageResizer;
|
||||
set
|
||||
{
|
||||
if (imageResizer != value)
|
||||
{
|
||||
LogTelemetryEvent(value);
|
||||
imageResizer = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool fileExplorerPreview = true;
|
||||
|
||||
[JsonPropertyName("File Explorer Preview")]
|
||||
public bool FileExplorerPreview
|
||||
{
|
||||
get => fileExplorerPreview;
|
||||
set
|
||||
{
|
||||
if (fileExplorerPreview != value)
|
||||
{
|
||||
LogTelemetryEvent(value);
|
||||
fileExplorerPreview = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool shortcutGuide = true;
|
||||
|
||||
[JsonPropertyName("Shortcut Guide")]
|
||||
public bool ShortcutGuide
|
||||
{
|
||||
get => shortcutGuide;
|
||||
set
|
||||
{
|
||||
if (shortcutGuide != value)
|
||||
{
|
||||
LogTelemetryEvent(value);
|
||||
shortcutGuide = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool videoConference; // defaulting to off https://github.com/microsoft/PowerToys/issues/14507
|
||||
|
||||
[JsonPropertyName("Video Conference")]
|
||||
public bool VideoConference
|
||||
{
|
||||
get => this.videoConference;
|
||||
set
|
||||
{
|
||||
if (this.videoConference != value)
|
||||
{
|
||||
LogTelemetryEvent(value);
|
||||
this.videoConference = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool powerRename = true;
|
||||
|
||||
public bool PowerRename
|
||||
{
|
||||
get => powerRename;
|
||||
set
|
||||
{
|
||||
if (powerRename != value)
|
||||
{
|
||||
LogTelemetryEvent(value);
|
||||
powerRename = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool keyboardManager = true;
|
||||
|
||||
[JsonPropertyName("Keyboard Manager")]
|
||||
public bool KeyboardManager
|
||||
{
|
||||
get => keyboardManager;
|
||||
set
|
||||
{
|
||||
if (keyboardManager != value)
|
||||
{
|
||||
LogTelemetryEvent(value);
|
||||
keyboardManager = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool powerLauncher = true;
|
||||
|
||||
[JsonPropertyName("PowerToys Run")]
|
||||
public bool PowerLauncher
|
||||
{
|
||||
get => powerLauncher;
|
||||
set
|
||||
{
|
||||
if (powerLauncher != value)
|
||||
{
|
||||
LogTelemetryEvent(value);
|
||||
powerLauncher = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool colorPicker = true;
|
||||
|
||||
[JsonPropertyName("ColorPicker")]
|
||||
public bool ColorPicker
|
||||
{
|
||||
get => colorPicker;
|
||||
set
|
||||
{
|
||||
if (colorPicker != value)
|
||||
{
|
||||
LogTelemetryEvent(value);
|
||||
colorPicker = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool awake;
|
||||
|
||||
[JsonPropertyName("Awake")]
|
||||
public bool Awake
|
||||
{
|
||||
get => awake;
|
||||
set
|
||||
{
|
||||
if (awake != value)
|
||||
{
|
||||
LogTelemetryEvent(value);
|
||||
awake = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool findMyMouse = true;
|
||||
|
||||
[JsonPropertyName("FindMyMouse")]
|
||||
public bool FindMyMouse
|
||||
{
|
||||
get => findMyMouse;
|
||||
set
|
||||
{
|
||||
if (findMyMouse != value)
|
||||
{
|
||||
LogTelemetryEvent(value);
|
||||
findMyMouse = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool mouseHighlighter = true;
|
||||
|
||||
[JsonPropertyName("MouseHighlighter")]
|
||||
public bool MouseHighlighter
|
||||
{
|
||||
get => mouseHighlighter;
|
||||
set
|
||||
{
|
||||
if (mouseHighlighter != value)
|
||||
{
|
||||
LogTelemetryEvent(value);
|
||||
mouseHighlighter = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string ToJsonString()
|
||||
{
|
||||
return JsonSerializer.Serialize(this);
|
||||
}
|
||||
|
||||
private static void LogTelemetryEvent(bool value, [CallerMemberName] string moduleName = null)
|
||||
{
|
||||
var dataEvent = new SettingsEnabledEvent()
|
||||
{
|
||||
Value = value,
|
||||
Name = moduleName,
|
||||
};
|
||||
PowerToysTelemetry.Log.WriteEvent(dataEvent);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// 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.
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library.Enumerations
|
||||
{
|
||||
public enum ColorPickerActivationAction
|
||||
{
|
||||
// Activation shortcut opens editor
|
||||
OpenEditor,
|
||||
|
||||
// Activation shortcut opens color picker and after picking a color color is copied into clipboard and opens editor
|
||||
OpenColorPickerAndThenEditor,
|
||||
|
||||
// Activation shortcut opens color picker only and picking color copies color into clipboard
|
||||
OpenOnlyColorPicker,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
// 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.
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library.Enumerations
|
||||
{
|
||||
// NOTE: don't change the order (numbers) of the enumeration entires
|
||||
|
||||
/// <summary>
|
||||
/// The type of the color representation
|
||||
/// </summary>
|
||||
public enum ColorRepresentationType
|
||||
{
|
||||
/// <summary>
|
||||
/// Color presentation as hexadecimal color value without the alpha-value (e.g. #0055FF)
|
||||
/// </summary>
|
||||
HEX = 0,
|
||||
|
||||
/// <summary>
|
||||
/// Color presentation as RGB color value (red[0..255], green[0..255], blue[0..255])
|
||||
/// </summary>
|
||||
RGB = 1,
|
||||
|
||||
/// <summary>
|
||||
/// Color presentation as CMYK color value (cyan[0%..100%], magenta[0%..100%], yellow[0%..100%], black key[0%..100%])
|
||||
/// </summary>
|
||||
CMYK = 2,
|
||||
|
||||
/// <summary>
|
||||
/// Color presentation as HSL color value (hue[0°..360°], saturation[0..100%], lightness[0%..100%])
|
||||
/// </summary>
|
||||
HSL = 3,
|
||||
|
||||
/// <summary>
|
||||
/// Color presentation as HSV color value (hue[0°..360°], saturation[0%..100%], value[0%..100%])
|
||||
/// </summary>
|
||||
HSV = 4,
|
||||
|
||||
/// <summary>
|
||||
/// Color presentation as HSB color value (hue[0°..360°], saturation[0%..100%], brightness[0%..100%])
|
||||
/// </summary>
|
||||
HSB = 5,
|
||||
|
||||
/// <summary>
|
||||
/// Color presentation as HSI color value (hue[0°..360°], saturation[0%..100%], intensity[0%..100%])
|
||||
/// </summary>
|
||||
HSI = 6,
|
||||
|
||||
/// <summary>
|
||||
/// Color presentation as HWB color value (hue[0°..360°], whiteness[0%..100%], blackness[0%..100%])
|
||||
/// </summary>
|
||||
HWB = 7,
|
||||
|
||||
/// <summary>
|
||||
/// Color presentation as natural color (hue, whiteness[0%..100%], blackness[0%..100%])
|
||||
/// </summary>
|
||||
NCol = 8,
|
||||
|
||||
/// <summary>
|
||||
/// Color presentation as CIELAB color space, also referred to as CIELAB(L[0..100], A[-128..127], B[-128..127])
|
||||
/// </summary>
|
||||
CIELAB = 9,
|
||||
|
||||
/// <summary>
|
||||
/// Color presentation as CIEXYZ color space (X[0..95], Y[0..100], Z[0..109]
|
||||
/// </summary>
|
||||
CIEXYZ = 10,
|
||||
|
||||
/// <summary>
|
||||
/// Color presentation as RGB float (red[0..1], green[0..1], blue[0..1])
|
||||
/// </summary>
|
||||
VEC4 = 11,
|
||||
|
||||
/// <summary>
|
||||
/// Color presentation as integer decimal value 0-16777215
|
||||
/// </summary>
|
||||
DecimalValue = 12,
|
||||
}
|
||||
}
|
||||
139
src/settings-ui/Settings.UI.Library/FZConfigProperties.cs
Normal file
139
src/settings-ui/Settings.UI.Library/FZConfigProperties.cs
Normal file
@@ -0,0 +1,139 @@
|
||||
// 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.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public class FZConfigProperties
|
||||
{
|
||||
// in reality, this file needs to be kept in sync currently with src\modules\fancyzones\lib\Settings.h
|
||||
public const int VkOem3 = 0xc0;
|
||||
public const int VkNext = 0x22;
|
||||
public const int VkPrior = 0x21;
|
||||
|
||||
public static readonly HotkeySettings DefaultEditorHotkeyValue = new HotkeySettings(true, false, false, true, VkOem3);
|
||||
public static readonly HotkeySettings DefaultNextTabHotkeyValue = new HotkeySettings(true, false, false, false, VkNext);
|
||||
public static readonly HotkeySettings DefaultPrevTabHotkeyValue = new HotkeySettings(true, false, false, false, VkPrior);
|
||||
|
||||
public FZConfigProperties()
|
||||
{
|
||||
FancyzonesShiftDrag = new BoolProperty(ConfigDefaults.DefaultFancyzonesShiftDrag);
|
||||
FancyzonesOverrideSnapHotkeys = new BoolProperty();
|
||||
FancyzonesMouseSwitch = new BoolProperty();
|
||||
FancyzonesMoveWindowsAcrossMonitors = new BoolProperty();
|
||||
FancyzonesMoveWindowsBasedOnPosition = new BoolProperty();
|
||||
FancyzonesOverlappingZonesAlgorithm = new IntProperty();
|
||||
FancyzonesDisplayChangeMoveWindows = new BoolProperty();
|
||||
FancyzonesZoneSetChangeMoveWindows = new BoolProperty();
|
||||
FancyzonesAppLastZoneMoveWindows = new BoolProperty();
|
||||
FancyzonesOpenWindowOnActiveMonitor = new BoolProperty();
|
||||
FancyzonesRestoreSize = new BoolProperty();
|
||||
FancyzonesQuickLayoutSwitch = new BoolProperty(ConfigDefaults.DefaultFancyzonesQuickLayoutSwitch);
|
||||
FancyzonesFlashZonesOnQuickSwitch = new BoolProperty(ConfigDefaults.DefaultFancyzonesFlashZonesOnQuickSwitch);
|
||||
UseCursorposEditorStartupscreen = new BoolProperty(ConfigDefaults.DefaultUseCursorposEditorStartupscreen);
|
||||
FancyzonesShowOnAllMonitors = new BoolProperty();
|
||||
FancyzonesSpanZonesAcrossMonitors = new BoolProperty();
|
||||
FancyzonesZoneHighlightColor = new StringProperty(ConfigDefaults.DefaultFancyZonesZoneHighlightColor);
|
||||
FancyzonesHighlightOpacity = new IntProperty(50);
|
||||
FancyzonesEditorHotkey = new KeyboardKeysProperty(DefaultEditorHotkeyValue);
|
||||
FancyzonesWindowSwitching = new BoolProperty(true);
|
||||
FancyzonesNextTabHotkey = new KeyboardKeysProperty(DefaultNextTabHotkeyValue);
|
||||
FancyzonesPrevTabHotkey = new KeyboardKeysProperty(DefaultPrevTabHotkeyValue);
|
||||
FancyzonesMakeDraggedWindowTransparent = new BoolProperty();
|
||||
FancyzonesExcludedApps = new StringProperty();
|
||||
FancyzonesInActiveColor = new StringProperty(ConfigDefaults.DefaultFancyZonesInActiveColor);
|
||||
FancyzonesBorderColor = new StringProperty(ConfigDefaults.DefaultFancyzonesBorderColor);
|
||||
FancyzonesSystemTheme = new BoolProperty(true);
|
||||
}
|
||||
|
||||
[JsonPropertyName("fancyzones_shiftDrag")]
|
||||
public BoolProperty FancyzonesShiftDrag { get; set; }
|
||||
|
||||
[JsonPropertyName("fancyzones_mouseSwitch")]
|
||||
public BoolProperty FancyzonesMouseSwitch { get; set; }
|
||||
|
||||
[JsonPropertyName("fancyzones_overrideSnapHotkeys")]
|
||||
public BoolProperty FancyzonesOverrideSnapHotkeys { get; set; }
|
||||
|
||||
[JsonPropertyName("fancyzones_moveWindowAcrossMonitors")]
|
||||
public BoolProperty FancyzonesMoveWindowsAcrossMonitors { get; set; }
|
||||
|
||||
[JsonPropertyName("fancyzones_moveWindowsBasedOnPosition")]
|
||||
public BoolProperty FancyzonesMoveWindowsBasedOnPosition { get; set; }
|
||||
|
||||
[JsonPropertyName("fancyzones_overlappingZonesAlgorithm")]
|
||||
public IntProperty FancyzonesOverlappingZonesAlgorithm { get; set; }
|
||||
|
||||
[JsonPropertyName("fancyzones_displayChange_moveWindows")]
|
||||
public BoolProperty FancyzonesDisplayChangeMoveWindows { get; set; }
|
||||
|
||||
[JsonPropertyName("fancyzones_zoneSetChange_moveWindows")]
|
||||
public BoolProperty FancyzonesZoneSetChangeMoveWindows { get; set; }
|
||||
|
||||
[JsonPropertyName("fancyzones_appLastZone_moveWindows")]
|
||||
public BoolProperty FancyzonesAppLastZoneMoveWindows { get; set; }
|
||||
|
||||
[JsonPropertyName("fancyzones_openWindowOnActiveMonitor")]
|
||||
public BoolProperty FancyzonesOpenWindowOnActiveMonitor { get; set; }
|
||||
|
||||
[JsonPropertyName("fancyzones_restoreSize")]
|
||||
public BoolProperty FancyzonesRestoreSize { get; set; }
|
||||
|
||||
[JsonPropertyName("fancyzones_quickLayoutSwitch")]
|
||||
public BoolProperty FancyzonesQuickLayoutSwitch { get; set; }
|
||||
|
||||
[JsonPropertyName("fancyzones_flashZonesOnQuickSwitch")]
|
||||
public BoolProperty FancyzonesFlashZonesOnQuickSwitch { get; set; }
|
||||
|
||||
[JsonPropertyName("use_cursorpos_editor_startupscreen")]
|
||||
public BoolProperty UseCursorposEditorStartupscreen { get; set; }
|
||||
|
||||
[JsonPropertyName("fancyzones_show_on_all_monitors")]
|
||||
public BoolProperty FancyzonesShowOnAllMonitors { get; set; }
|
||||
|
||||
[JsonPropertyName("fancyzones_span_zones_across_monitors")]
|
||||
public BoolProperty FancyzonesSpanZonesAcrossMonitors { get; set; }
|
||||
|
||||
[JsonPropertyName("fancyzones_makeDraggedWindowTransparent")]
|
||||
public BoolProperty FancyzonesMakeDraggedWindowTransparent { get; set; }
|
||||
|
||||
[JsonPropertyName("fancyzones_zoneHighlightColor")]
|
||||
public StringProperty FancyzonesZoneHighlightColor { get; set; }
|
||||
|
||||
[JsonPropertyName("fancyzones_highlight_opacity")]
|
||||
public IntProperty FancyzonesHighlightOpacity { get; set; }
|
||||
|
||||
[JsonPropertyName("fancyzones_editor_hotkey")]
|
||||
public KeyboardKeysProperty FancyzonesEditorHotkey { get; set; }
|
||||
|
||||
[JsonPropertyName("fancyzones_windowSwitching")]
|
||||
public BoolProperty FancyzonesWindowSwitching { get; set; }
|
||||
|
||||
[JsonPropertyName("fancyzones_nextTab_hotkey")]
|
||||
public KeyboardKeysProperty FancyzonesNextTabHotkey { get; set; }
|
||||
|
||||
[JsonPropertyName("fancyzones_prevTab_hotkey")]
|
||||
public KeyboardKeysProperty FancyzonesPrevTabHotkey { get; set; }
|
||||
|
||||
[JsonPropertyName("fancyzones_excluded_apps")]
|
||||
public StringProperty FancyzonesExcludedApps { get; set; }
|
||||
|
||||
[JsonPropertyName("fancyzones_zoneBorderColor")]
|
||||
public StringProperty FancyzonesBorderColor { get; set; }
|
||||
|
||||
[JsonPropertyName("fancyzones_zoneColor")]
|
||||
public StringProperty FancyzonesInActiveColor { get; set; }
|
||||
|
||||
[JsonPropertyName("fancyzones_systemTheme")]
|
||||
public BoolProperty FancyzonesSystemTheme { get; set; }
|
||||
|
||||
// converts the current to a json string.
|
||||
public string ToJsonString()
|
||||
{
|
||||
return JsonSerializer.Serialize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
35
src/settings-ui/Settings.UI.Library/FancyZonesSettings.cs
Normal file
35
src/settings-ui/Settings.UI.Library/FancyZonesSettings.cs
Normal file
@@ -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.Text.Json.Serialization;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public class FancyZonesSettings : BasePTModuleSettings, ISettingsConfig
|
||||
{
|
||||
public const string ModuleName = "FancyZones";
|
||||
|
||||
public FancyZonesSettings()
|
||||
{
|
||||
Version = "1.0";
|
||||
Name = ModuleName;
|
||||
Properties = new FZConfigProperties();
|
||||
}
|
||||
|
||||
[JsonPropertyName("properties")]
|
||||
public FZConfigProperties Properties { get; set; }
|
||||
|
||||
public string GetModuleName()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
|
||||
// This can be utilized in the future if the settings.json file is to be modified/deleted.
|
||||
public bool UpgradeSettingsConfiguration()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
43
src/settings-ui/Settings.UI.Library/FindMyMouseProperties.cs
Normal file
43
src/settings-ui/Settings.UI.Library/FindMyMouseProperties.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
// 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.Text.Json.Serialization;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public class FindMyMouseProperties
|
||||
{
|
||||
[JsonPropertyName("do_not_activate_on_game_mode")]
|
||||
public BoolProperty DoNotActivateOnGameMode { get; set; }
|
||||
|
||||
[JsonPropertyName("background_color")]
|
||||
public StringProperty BackgroundColor { get; set; }
|
||||
|
||||
[JsonPropertyName("spotlight_color")]
|
||||
public StringProperty SpotlightColor { get; set; }
|
||||
|
||||
[JsonPropertyName("overlay_opacity")]
|
||||
public IntProperty OverlayOpacity { get; set; }
|
||||
|
||||
[JsonPropertyName("spotlight_radius")]
|
||||
public IntProperty SpotlightRadius { get; set; }
|
||||
|
||||
[JsonPropertyName("animation_duration_ms")]
|
||||
public IntProperty AnimationDurationMs { get; set; }
|
||||
|
||||
[JsonPropertyName("spotlight_initial_zoom")]
|
||||
public IntProperty SpotlightInitialZoom { get; set; }
|
||||
|
||||
public FindMyMouseProperties()
|
||||
{
|
||||
DoNotActivateOnGameMode = new BoolProperty(true);
|
||||
BackgroundColor = new StringProperty("#000000");
|
||||
SpotlightColor = new StringProperty("#FFFFFF");
|
||||
OverlayOpacity = new IntProperty(50);
|
||||
SpotlightRadius = new IntProperty(100);
|
||||
AnimationDurationMs = new IntProperty(500);
|
||||
SpotlightInitialZoom = new IntProperty(9);
|
||||
}
|
||||
}
|
||||
}
|
||||
35
src/settings-ui/Settings.UI.Library/FindMyMouseSettings.cs
Normal file
35
src/settings-ui/Settings.UI.Library/FindMyMouseSettings.cs
Normal file
@@ -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.Text.Json.Serialization;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public class FindMyMouseSettings : BasePTModuleSettings, ISettingsConfig
|
||||
{
|
||||
public const string ModuleName = "FindMyMouse";
|
||||
|
||||
[JsonPropertyName("properties")]
|
||||
public FindMyMouseProperties Properties { get; set; }
|
||||
|
||||
public FindMyMouseSettings()
|
||||
{
|
||||
Name = ModuleName;
|
||||
Properties = new FindMyMouseProperties();
|
||||
Version = "1.0";
|
||||
}
|
||||
|
||||
public string GetModuleName()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
|
||||
// This can be utilized in the future if the settings.json file is to be modified/deleted.
|
||||
public bool UpgradeSettingsConfiguration()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
// 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.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public class FindMyMouseSettingsIPCMessage
|
||||
{
|
||||
[JsonPropertyName("powertoys")]
|
||||
public SndFindMyMouseSettings Powertoys { get; set; }
|
||||
|
||||
public FindMyMouseSettingsIPCMessage()
|
||||
{
|
||||
}
|
||||
|
||||
public FindMyMouseSettingsIPCMessage(SndFindMyMouseSettings settings)
|
||||
{
|
||||
this.Powertoys = settings;
|
||||
}
|
||||
|
||||
public string ToJsonString()
|
||||
{
|
||||
return JsonSerializer.Serialize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
114
src/settings-ui/Settings.UI.Library/GeneralSettings.cs
Normal file
114
src/settings-ui/Settings.UI.Library/GeneralSettings.cs
Normal file
@@ -0,0 +1,114 @@
|
||||
// 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.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public class GeneralSettings : ISettingsConfig
|
||||
{
|
||||
// Gets or sets a value indicating whether run powertoys on start-up.
|
||||
[JsonPropertyName("startup")]
|
||||
public bool Startup { get; set; }
|
||||
|
||||
// Gets or sets a value indicating whether the powertoy elevated.
|
||||
[JsonPropertyName("is_elevated")]
|
||||
public bool IsElevated { get; set; }
|
||||
|
||||
// Gets or sets a value indicating whether powertoys should run elevated.
|
||||
[JsonPropertyName("run_elevated")]
|
||||
public bool RunElevated { get; set; }
|
||||
|
||||
// Gets or sets a value indicating whether is admin.
|
||||
[JsonPropertyName("is_admin")]
|
||||
public bool IsAdmin { get; set; }
|
||||
|
||||
// Gets or sets theme Name.
|
||||
[JsonPropertyName("theme")]
|
||||
public string Theme { get; set; }
|
||||
|
||||
// Gets or sets system theme name.
|
||||
[JsonPropertyName("system_theme")]
|
||||
public string SystemTheme { get; set; }
|
||||
|
||||
// Gets or sets powertoys version number.
|
||||
[JsonPropertyName("powertoys_version")]
|
||||
public string PowertoysVersion { get; set; }
|
||||
|
||||
[JsonPropertyName("action_name")]
|
||||
public string CustomActionName { get; set; }
|
||||
|
||||
[JsonPropertyName("enabled")]
|
||||
public EnabledModules Enabled { get; set; }
|
||||
|
||||
[JsonPropertyName("download_updates_automatically")]
|
||||
public bool AutoDownloadUpdates { get; set; }
|
||||
|
||||
[SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "Any error from calling interop code should not prevent the program from loading.")]
|
||||
public GeneralSettings()
|
||||
{
|
||||
Startup = false;
|
||||
IsAdmin = false;
|
||||
IsElevated = false;
|
||||
AutoDownloadUpdates = false;
|
||||
Theme = "system";
|
||||
SystemTheme = "light";
|
||||
try
|
||||
{
|
||||
PowertoysVersion = DefaultPowertoysVersion();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.LogError("Exception encountered when getting PowerToys version", e);
|
||||
PowertoysVersion = "v0.0.0";
|
||||
}
|
||||
|
||||
Enabled = new EnabledModules();
|
||||
CustomActionName = string.Empty;
|
||||
}
|
||||
|
||||
// converts the current to a json string.
|
||||
public string ToJsonString()
|
||||
{
|
||||
return JsonSerializer.Serialize(this);
|
||||
}
|
||||
|
||||
private static string DefaultPowertoysVersion()
|
||||
{
|
||||
return interop.CommonManaged.GetProductVersion();
|
||||
}
|
||||
|
||||
// This function is to implement the ISettingsConfig interface.
|
||||
// This interface helps in getting the settings configurations.
|
||||
public string GetModuleName()
|
||||
{
|
||||
// The SettingsUtils functions access general settings when the module name is an empty string.
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
public bool UpgradeSettingsConfiguration()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (Helper.CompareVersions(PowertoysVersion, Helper.GetProductVersion()) != 0)
|
||||
{
|
||||
// Update settings
|
||||
PowertoysVersion = Helper.GetProductVersion();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (FormatException)
|
||||
{
|
||||
// If there is an issue with the version number format, don't migrate settings.
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
// 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.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public class GeneralSettingsCustomAction
|
||||
{
|
||||
[JsonPropertyName("action")]
|
||||
public OutGoingGeneralSettings GeneralSettingsAction { get; set; }
|
||||
|
||||
public GeneralSettingsCustomAction()
|
||||
{
|
||||
}
|
||||
|
||||
public GeneralSettingsCustomAction(OutGoingGeneralSettings action)
|
||||
{
|
||||
GeneralSettingsAction = action;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return JsonSerializer.Serialize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
24
src/settings-ui/Settings.UI.Library/GenericProperty`1.cs
Normal file
24
src/settings-ui/Settings.UI.Library/GenericProperty`1.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
// 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.Text.Json.Serialization;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public class GenericProperty<T>
|
||||
{
|
||||
[JsonPropertyName("value")]
|
||||
public T Value { get; set; }
|
||||
|
||||
public GenericProperty(T value)
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
|
||||
// Added a parameterless constructor because of an exception during deserialization. More details here: https://docs.microsoft.com/en-us/dotnet/standard/serialization/system-text-json-how-to#deserialization-behavior
|
||||
public GenericProperty()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
27
src/settings-ui/Settings.UI.Library/Helpers/Observable.cs
Normal file
27
src/settings-ui/Settings.UI.Library/Helpers/Observable.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
// 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.Helpers
|
||||
{
|
||||
public class Observable : INotifyPropertyChanged
|
||||
{
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
protected void Set<T>(ref T storage, T value, [CallerMemberName] string propertyName = null)
|
||||
{
|
||||
if (Equals(storage, value))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
storage = value;
|
||||
OnPropertyChanged(propertyName);
|
||||
}
|
||||
|
||||
protected void OnPropertyChanged(string propertyName) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
// 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.Drawing;
|
||||
using System.Globalization;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library.Helpers
|
||||
{
|
||||
public static class SettingsUtilities
|
||||
{
|
||||
public static string ToRGBHex(string color)
|
||||
{
|
||||
if (color == null)
|
||||
{
|
||||
return "#FFFFFF";
|
||||
}
|
||||
|
||||
// Using InvariantCulture as these are expected to be hex codes.
|
||||
bool success = int.TryParse(
|
||||
color.Replace("#", string.Empty),
|
||||
System.Globalization.NumberStyles.HexNumber,
|
||||
CultureInfo.InvariantCulture,
|
||||
out int argb);
|
||||
|
||||
if (success)
|
||||
{
|
||||
Color clr = Color.FromArgb(argb);
|
||||
return "#" + clr.R.ToString("X2", CultureInfo.InvariantCulture) +
|
||||
clr.G.ToString("X2", CultureInfo.InvariantCulture) +
|
||||
clr.B.ToString("X2", CultureInfo.InvariantCulture);
|
||||
}
|
||||
else
|
||||
{
|
||||
return "#FFFFFF";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
180
src/settings-ui/Settings.UI.Library/HotkeySettings.cs
Normal file
180
src/settings-ui/Settings.UI.Library/HotkeySettings.cs
Normal file
@@ -0,0 +1,180 @@
|
||||
// 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.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Text.Json.Serialization;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public class HotkeySettings
|
||||
{
|
||||
private const int VKTAB = 0x09;
|
||||
|
||||
public HotkeySettings()
|
||||
{
|
||||
Win = false;
|
||||
Ctrl = false;
|
||||
Alt = false;
|
||||
Shift = false;
|
||||
Code = 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="HotkeySettings"/> class.
|
||||
/// </summary>
|
||||
/// <param name="win">Should Windows key be used</param>
|
||||
/// <param name="ctrl">Should Ctrl key be used</param>
|
||||
/// <param name="alt">Should Alt key be used</param>
|
||||
/// <param name="shift">Should Shift key be used</param>
|
||||
/// <param name="code">Go to https://docs.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes to see list of v-keys</param>
|
||||
public HotkeySettings(bool win, bool ctrl, bool alt, bool shift, int code)
|
||||
{
|
||||
Win = win;
|
||||
Ctrl = ctrl;
|
||||
Alt = alt;
|
||||
Shift = shift;
|
||||
Code = code;
|
||||
}
|
||||
|
||||
public HotkeySettings Clone()
|
||||
{
|
||||
return new HotkeySettings(Win, Ctrl, Alt, Shift, Code);
|
||||
}
|
||||
|
||||
[JsonPropertyName("win")]
|
||||
public bool Win { get; set; }
|
||||
|
||||
[JsonPropertyName("ctrl")]
|
||||
public bool Ctrl { get; set; }
|
||||
|
||||
[JsonPropertyName("alt")]
|
||||
public bool Alt { get; set; }
|
||||
|
||||
[JsonPropertyName("shift")]
|
||||
public bool Shift { get; set; }
|
||||
|
||||
[JsonPropertyName("code")]
|
||||
public int Code { get; set; }
|
||||
|
||||
// This is currently needed for FancyZones, we need to unify these two objects
|
||||
// see src\common\settings_objects.h
|
||||
[JsonPropertyName("key")]
|
||||
public string Key { get; set; } = string.Empty;
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
StringBuilder output = new StringBuilder();
|
||||
|
||||
if (Win)
|
||||
{
|
||||
output.Append("Win + ");
|
||||
}
|
||||
|
||||
if (Ctrl)
|
||||
{
|
||||
output.Append("Ctrl + ");
|
||||
}
|
||||
|
||||
if (Alt)
|
||||
{
|
||||
output.Append("Alt + ");
|
||||
}
|
||||
|
||||
if (Shift)
|
||||
{
|
||||
output.Append("Shift + ");
|
||||
}
|
||||
|
||||
if (Code > 0)
|
||||
{
|
||||
var localKey = Helper.GetKeyName((uint)Code);
|
||||
output.Append(localKey);
|
||||
}
|
||||
else if (output.Length >= 2)
|
||||
{
|
||||
output.Remove(output.Length - 2, 2);
|
||||
}
|
||||
|
||||
return output.ToString();
|
||||
}
|
||||
|
||||
public List<object> GetKeysList()
|
||||
{
|
||||
List<object> shortcutList = new List<object>();
|
||||
|
||||
if (Win)
|
||||
{
|
||||
shortcutList.Add(92); // The Windows key or button.
|
||||
}
|
||||
|
||||
if (Ctrl)
|
||||
{
|
||||
shortcutList.Add("Ctrl");
|
||||
}
|
||||
|
||||
if (Alt)
|
||||
{
|
||||
shortcutList.Add("Alt");
|
||||
}
|
||||
|
||||
if (Shift)
|
||||
{
|
||||
shortcutList.Add("Shift");
|
||||
|
||||
// shortcutList.Add(16); // The Shift key or button.
|
||||
}
|
||||
|
||||
if (Code > 0)
|
||||
{
|
||||
switch (Code)
|
||||
{
|
||||
// https://docs.microsoft.com/en-us/uwp/api/windows.system.virtualkey?view=winrt-20348
|
||||
case 38: // The Up Arrow key or button.
|
||||
case 40: // The Down Arrow key or button.
|
||||
case 37: // The Left Arrow key or button.
|
||||
case 39: // The Right Arrow key or button.
|
||||
// case 8: // The Back key or button.
|
||||
// case 13: // The Enter key or button.
|
||||
shortcutList.Add(Code);
|
||||
break;
|
||||
default:
|
||||
var localKey = Helper.GetKeyName((uint)Code);
|
||||
shortcutList.Add(localKey);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return shortcutList;
|
||||
}
|
||||
|
||||
public bool IsValid()
|
||||
{
|
||||
if (IsAccessibleShortcut())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return (Alt || Ctrl || Win || Shift) && Code != 0;
|
||||
}
|
||||
|
||||
public bool IsEmpty()
|
||||
{
|
||||
return !Alt && !Ctrl && !Win && !Shift && Code == 0;
|
||||
}
|
||||
|
||||
public bool IsAccessibleShortcut()
|
||||
{
|
||||
// Shift+Tab and Tab are accessible shortcuts
|
||||
if ((!Alt && !Ctrl && !Win && Shift && Code == VKTAB)
|
||||
|| (!Alt && !Ctrl && !Win && !Shift && Code == VKTAB))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
// 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 interop;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public delegate void KeyEvent(int key);
|
||||
|
||||
public delegate bool IsActive();
|
||||
|
||||
public delegate bool FilterAccessibleKeyboardEvents(int key, UIntPtr extraInfo);
|
||||
|
||||
public class HotkeySettingsControlHook : IDisposable
|
||||
{
|
||||
private const int WmKeyDown = 0x100;
|
||||
private const int WmKeyUp = 0x101;
|
||||
private const int WmSysKeyDown = 0x0104;
|
||||
private const int WmSysKeyUp = 0x0105;
|
||||
|
||||
[SuppressMessage("Usage", "CA2213:Disposable fields should be disposed", Justification = "This class conforms to the IDisposable pattern, and the Dispose and C++ destructor does get called when debugging. Looks like a false positive from FxCop.")]
|
||||
private KeyboardHook _hook;
|
||||
private KeyEvent _keyDown;
|
||||
private KeyEvent _keyUp;
|
||||
private IsActive _isActive;
|
||||
private bool disposedValue;
|
||||
|
||||
private FilterAccessibleKeyboardEvents _filterKeyboardEvent;
|
||||
|
||||
public HotkeySettingsControlHook(KeyEvent keyDown, KeyEvent keyUp, IsActive isActive, FilterAccessibleKeyboardEvents filterAccessibleKeyboardEvents)
|
||||
{
|
||||
_keyDown = keyDown;
|
||||
_keyUp = keyUp;
|
||||
_isActive = isActive;
|
||||
_filterKeyboardEvent = filterAccessibleKeyboardEvents;
|
||||
_hook = new KeyboardHook(HotkeySettingsHookCallback, IsActive, FilterKeyboardEvents);
|
||||
_hook.Start();
|
||||
}
|
||||
|
||||
private bool IsActive()
|
||||
{
|
||||
return _isActive();
|
||||
}
|
||||
|
||||
private void HotkeySettingsHookCallback(KeyboardEvent ev)
|
||||
{
|
||||
switch (ev.message)
|
||||
{
|
||||
case WmKeyDown:
|
||||
case WmSysKeyDown:
|
||||
_keyDown(ev.key);
|
||||
break;
|
||||
case WmKeyUp:
|
||||
case WmSysKeyUp:
|
||||
_keyUp(ev.key);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private bool FilterKeyboardEvents(KeyboardEvent ev)
|
||||
{
|
||||
return _filterKeyboardEvent(ev.key, (UIntPtr)ev.dwExtraInfo);
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (!disposedValue)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
// Dispose the KeyboardHook object to terminate the hook threads
|
||||
_hook.Dispose();
|
||||
}
|
||||
|
||||
disposedValue = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(disposing: true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
17
src/settings-ui/Settings.UI.Library/ISettingsPath.cs
Normal file
17
src/settings-ui/Settings.UI.Library/ISettingsPath.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
// 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.
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public interface ISettingsPath
|
||||
{
|
||||
bool SettingsFolderExists(string powertoy);
|
||||
|
||||
void CreateSettingsFolder(string powertoy);
|
||||
|
||||
void DeleteSettings(string powertoy = "");
|
||||
|
||||
string GetSettingsPath(string powertoy, string fileName);
|
||||
}
|
||||
}
|
||||
25
src/settings-ui/Settings.UI.Library/ISettingsUtils.cs
Normal file
25
src/settings-ui/Settings.UI.Library/ISettingsUtils.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
// 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 Microsoft.PowerToys.Settings.UI.Library.Interfaces;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public interface ISettingsUtils
|
||||
{
|
||||
T GetSettings<T>(string powertoy = "", string fileName = "settings.json")
|
||||
where T : ISettingsConfig, new();
|
||||
|
||||
T GetSettingsOrDefault<T>(string powertoy = "", string fileName = "settings.json")
|
||||
where T : ISettingsConfig, new();
|
||||
|
||||
void SaveSettings(string jsonSettings, string powertoy = "", string fileName = "settings.json");
|
||||
|
||||
bool SettingsExists(string powertoy = "", string fileName = "settings.json");
|
||||
|
||||
void DeleteSettings(string powertoy = "");
|
||||
|
||||
string GetSettingsFilePath(string powertoy = "", string fileName = "settings.json");
|
||||
}
|
||||
}
|
||||
121
src/settings-ui/Settings.UI.Library/ImageResizerProperties.cs
Normal file
121
src/settings-ui/Settings.UI.Library/ImageResizerProperties.cs
Normal file
@@ -0,0 +1,121 @@
|
||||
// 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.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public class ImageResizerProperties
|
||||
{
|
||||
public ImageResizerProperties()
|
||||
{
|
||||
ImageresizerSelectedSizeIndex = new IntProperty(0);
|
||||
ImageresizerShrinkOnly = new BoolProperty(false);
|
||||
ImageresizerReplace = new BoolProperty(false);
|
||||
ImageresizerIgnoreOrientation = new BoolProperty(true);
|
||||
ImageresizerJpegQualityLevel = new IntProperty(90);
|
||||
ImageresizerPngInterlaceOption = new IntProperty();
|
||||
ImageresizerTiffCompressOption = new IntProperty();
|
||||
ImageresizerFileName = new StringProperty("%1 (%2)");
|
||||
ImageresizerSizes = new ImageResizerSizes();
|
||||
ImageresizerKeepDateModified = new BoolProperty();
|
||||
ImageresizerFallbackEncoder = new StringProperty(new System.Guid("19e4a5aa-5662-4fc5-a0c0-1758028e1057").ToString());
|
||||
ImageresizerCustomSize = new ImageResizerCustomSizeProperty(new ImageSize(4, "custom", ResizeFit.Fit, 1024, 640, ResizeUnit.Pixel));
|
||||
}
|
||||
|
||||
public ImageResizerProperties(Func<string, string> resourceLoader)
|
||||
: this()
|
||||
{
|
||||
if (resourceLoader == null)
|
||||
{
|
||||
throw new NullReferenceException("Resource loader is null");
|
||||
}
|
||||
|
||||
ImageresizerSizes = new ImageResizerSizes(new ObservableCollection<ImageSize>()
|
||||
{
|
||||
new ImageSize(0, resourceLoader("ImageResizer_DefaultSize_Small"), ResizeFit.Fit, 854, 480, ResizeUnit.Pixel),
|
||||
new ImageSize(1, resourceLoader("ImageResizer_DefaultSize_Medium"), ResizeFit.Fit, 1366, 768, ResizeUnit.Pixel),
|
||||
new ImageSize(2, resourceLoader("ImageResizer_DefaultSize_Large"), ResizeFit.Fit, 1920, 1080, ResizeUnit.Pixel),
|
||||
new ImageSize(3, resourceLoader("ImageResizer_DefaultSize_Phone"), ResizeFit.Fit, 320, 568, ResizeUnit.Pixel),
|
||||
});
|
||||
}
|
||||
|
||||
[JsonPropertyName("imageresizer_selectedSizeIndex")]
|
||||
public IntProperty ImageresizerSelectedSizeIndex { get; set; }
|
||||
|
||||
[JsonPropertyName("imageresizer_shrinkOnly")]
|
||||
public BoolProperty ImageresizerShrinkOnly { get; set; }
|
||||
|
||||
[JsonPropertyName("imageresizer_replace")]
|
||||
public BoolProperty ImageresizerReplace { get; set; }
|
||||
|
||||
[JsonPropertyName("imageresizer_ignoreOrientation")]
|
||||
public BoolProperty ImageresizerIgnoreOrientation { get; set; }
|
||||
|
||||
[JsonPropertyName("imageresizer_jpegQualityLevel")]
|
||||
public IntProperty ImageresizerJpegQualityLevel { get; set; }
|
||||
|
||||
[JsonPropertyName("imageresizer_pngInterlaceOption")]
|
||||
public IntProperty ImageresizerPngInterlaceOption { get; set; }
|
||||
|
||||
[JsonPropertyName("imageresizer_tiffCompressOption")]
|
||||
public IntProperty ImageresizerTiffCompressOption { get; set; }
|
||||
|
||||
[JsonPropertyName("imageresizer_fileName")]
|
||||
public StringProperty ImageresizerFileName { get; set; }
|
||||
|
||||
[JsonPropertyName("imageresizer_sizes")]
|
||||
public ImageResizerSizes ImageresizerSizes { get; set; }
|
||||
|
||||
[JsonPropertyName("imageresizer_keepDateModified")]
|
||||
public BoolProperty ImageresizerKeepDateModified { get; set; }
|
||||
|
||||
[JsonPropertyName("imageresizer_fallbackEncoder")]
|
||||
public StringProperty ImageresizerFallbackEncoder { get; set; }
|
||||
|
||||
[JsonPropertyName("imageresizer_customSize")]
|
||||
public ImageResizerCustomSizeProperty ImageresizerCustomSize { get; set; }
|
||||
|
||||
public string ToJsonString()
|
||||
{
|
||||
return JsonSerializer.Serialize(this);
|
||||
}
|
||||
}
|
||||
|
||||
public enum ResizeFit
|
||||
{
|
||||
Fill = 0,
|
||||
Fit = 1,
|
||||
Stretch = 2,
|
||||
}
|
||||
|
||||
public enum ResizeUnit
|
||||
{
|
||||
Centimeter = 0,
|
||||
Inch = 1,
|
||||
Percent = 2,
|
||||
Pixel = 3,
|
||||
}
|
||||
|
||||
public enum PngInterlaceOption
|
||||
{
|
||||
Default = 0,
|
||||
On = 1,
|
||||
Off = 2,
|
||||
}
|
||||
|
||||
public enum TiffCompressOption
|
||||
{
|
||||
Default = 0,
|
||||
None = 1,
|
||||
Ccitt3 = 2,
|
||||
Ccitt4 = 3,
|
||||
Lzw = 4,
|
||||
Rle = 5,
|
||||
Zip = 6,
|
||||
}
|
||||
}
|
||||
52
src/settings-ui/Settings.UI.Library/ImageResizerSettings.cs
Normal file
52
src/settings-ui/Settings.UI.Library/ImageResizerSettings.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
// 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.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public class ImageResizerSettings : BasePTModuleSettings, ISettingsConfig
|
||||
{
|
||||
public const string ModuleName = "Image Resizer";
|
||||
|
||||
[JsonPropertyName("properties")]
|
||||
public ImageResizerProperties Properties { get; set; }
|
||||
|
||||
public ImageResizerSettings()
|
||||
{
|
||||
Version = "1";
|
||||
Name = ModuleName;
|
||||
Properties = new ImageResizerProperties();
|
||||
}
|
||||
|
||||
public ImageResizerSettings(Func<string, string> resourceLoader)
|
||||
: this()
|
||||
{
|
||||
Properties = new ImageResizerProperties(resourceLoader);
|
||||
}
|
||||
|
||||
public override string ToJsonString()
|
||||
{
|
||||
var options = new JsonSerializerOptions
|
||||
{
|
||||
WriteIndented = true,
|
||||
};
|
||||
return JsonSerializer.Serialize(this, options);
|
||||
}
|
||||
|
||||
public string GetModuleName()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
|
||||
// This can be utilized in the future if the settings.json file is to be modified/deleted.
|
||||
public bool UpgradeSettingsConfiguration()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
246
src/settings-ui/Settings.UI.Library/ImageSize.cs
Normal file
246
src/settings-ui/Settings.UI.Library/ImageSize.cs
Normal file
@@ -0,0 +1,246 @@
|
||||
// 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.ComponentModel;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public class ImageSize : INotifyPropertyChanged
|
||||
{
|
||||
public ImageSize(int id)
|
||||
{
|
||||
Id = id;
|
||||
Name = string.Empty;
|
||||
Fit = (int)ResizeFit.Fit;
|
||||
Width = 0;
|
||||
Height = 0;
|
||||
Unit = (int)ResizeUnit.Pixel;
|
||||
}
|
||||
|
||||
public ImageSize()
|
||||
{
|
||||
Id = 0;
|
||||
Name = string.Empty;
|
||||
Fit = (int)ResizeFit.Fit;
|
||||
Width = 0;
|
||||
Height = 0;
|
||||
Unit = (int)ResizeUnit.Pixel;
|
||||
}
|
||||
|
||||
public ImageSize(int id, string name, ResizeFit fit, double width, double height, ResizeUnit unit)
|
||||
{
|
||||
Id = id;
|
||||
Name = name;
|
||||
Fit = (int)fit;
|
||||
Width = width;
|
||||
Height = height;
|
||||
Unit = (int)unit;
|
||||
}
|
||||
|
||||
private int _id;
|
||||
private string _name;
|
||||
private int _fit;
|
||||
private double _height;
|
||||
private double _width;
|
||||
private int _unit;
|
||||
|
||||
public int Id
|
||||
{
|
||||
get
|
||||
{
|
||||
return _id;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (_id != value)
|
||||
{
|
||||
_id = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int ExtraBoxOpacity
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Unit == 2 && Fit != 2)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 100;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool EnableEtraBoxes
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Unit == 2 && Fit != 2)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[JsonPropertyName("name")]
|
||||
public string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return _name;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (_name != value)
|
||||
{
|
||||
_name = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[JsonPropertyName("fit")]
|
||||
public int Fit
|
||||
{
|
||||
get
|
||||
{
|
||||
return _fit;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (_fit != value)
|
||||
{
|
||||
_fit = value;
|
||||
OnPropertyChanged();
|
||||
OnPropertyChanged(nameof(ExtraBoxOpacity));
|
||||
OnPropertyChanged(nameof(EnableEtraBoxes));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[JsonPropertyName("width")]
|
||||
public double Width
|
||||
{
|
||||
get
|
||||
{
|
||||
return _width;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
double newWidth = -1;
|
||||
|
||||
if (value < 0 || double.IsNaN(value))
|
||||
{
|
||||
newWidth = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
newWidth = value;
|
||||
}
|
||||
|
||||
if (_width != newWidth)
|
||||
{
|
||||
_width = newWidth;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[JsonPropertyName("height")]
|
||||
public double Height
|
||||
{
|
||||
get
|
||||
{
|
||||
return _height;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
double newHeight = -1;
|
||||
|
||||
if (value < 0 || double.IsNaN(value))
|
||||
{
|
||||
newHeight = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
newHeight = value;
|
||||
}
|
||||
|
||||
if (_height != newHeight)
|
||||
{
|
||||
_height = newHeight;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[JsonPropertyName("unit")]
|
||||
public int Unit
|
||||
{
|
||||
get
|
||||
{
|
||||
return _unit;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (_unit != value)
|
||||
{
|
||||
_unit = value;
|
||||
OnPropertyChanged();
|
||||
OnPropertyChanged(nameof(ExtraBoxOpacity));
|
||||
OnPropertyChanged(nameof(EnableEtraBoxes));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
public void OnPropertyChanged([CallerMemberName] string propertyName = null)
|
||||
{
|
||||
var handler = PropertyChanged;
|
||||
if (handler != null)
|
||||
{
|
||||
handler(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
}
|
||||
|
||||
public void Update(ImageSize modifiedSize)
|
||||
{
|
||||
if (modifiedSize == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(modifiedSize));
|
||||
}
|
||||
|
||||
Id = modifiedSize.Id;
|
||||
Name = modifiedSize.Name;
|
||||
Fit = modifiedSize.Fit;
|
||||
Width = modifiedSize.Width;
|
||||
Height = modifiedSize.Height;
|
||||
Unit = modifiedSize.Unit;
|
||||
}
|
||||
|
||||
public string ToJsonString()
|
||||
{
|
||||
return JsonSerializer.Serialize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// 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.Text.Json.Serialization;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public class ImagerResizerKeepDateModified
|
||||
{
|
||||
[JsonPropertyName("value")]
|
||||
public bool Value { get; set; }
|
||||
|
||||
public ImagerResizerKeepDateModified()
|
||||
{
|
||||
Value = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
// 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.Text.Json.Serialization;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public class ImageResizerCustomSizeProperty
|
||||
{
|
||||
[JsonPropertyName("value")]
|
||||
public ImageSize Value { get; set; }
|
||||
|
||||
public ImageResizerCustomSizeProperty()
|
||||
{
|
||||
Value = new ImageSize();
|
||||
}
|
||||
|
||||
public ImageResizerCustomSizeProperty(ImageSize value)
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// 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.Text.Json.Serialization;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public class ImageResizerFallbackEncoder
|
||||
{
|
||||
[JsonPropertyName("value")]
|
||||
public string Value { get; set; }
|
||||
|
||||
public ImageResizerFallbackEncoder()
|
||||
{
|
||||
Value = string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
40
src/settings-ui/Settings.UI.Library/ImageresizerSizes.cs
Normal file
40
src/settings-ui/Settings.UI.Library/ImageresizerSizes.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
// 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.Collections.ObjectModel;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public class ImageResizerSizes
|
||||
{
|
||||
// Suppressing this warning because removing the setter breaks
|
||||
// deserialization with System.Text.Json. This affects the UI display.
|
||||
// See: https://github.com/dotnet/runtime/issues/30258
|
||||
[JsonPropertyName("value")]
|
||||
#pragma warning disable CA2227 // Collection properties should be read only
|
||||
public ObservableCollection<ImageSize> Value { get; set; }
|
||||
#pragma warning restore CA2227 // Collection properties should be read only
|
||||
|
||||
public ImageResizerSizes()
|
||||
{
|
||||
Value = new ObservableCollection<ImageSize>();
|
||||
}
|
||||
|
||||
public ImageResizerSizes(ObservableCollection<ImageSize> value)
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
|
||||
public string ToJsonString()
|
||||
{
|
||||
var options = new JsonSerializerOptions
|
||||
{
|
||||
WriteIndented = true,
|
||||
};
|
||||
return JsonSerializer.Serialize(this, options);
|
||||
}
|
||||
}
|
||||
}
|
||||
33
src/settings-ui/Settings.UI.Library/IntProperty.cs
Normal file
33
src/settings-ui/Settings.UI.Library/IntProperty.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
// 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.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
// Represents the configuration property of the settings that store Integer type.
|
||||
public class IntProperty
|
||||
{
|
||||
public IntProperty()
|
||||
{
|
||||
Value = 0;
|
||||
}
|
||||
|
||||
public IntProperty(int value)
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
|
||||
// Gets or sets the integer value of the settings configuration.
|
||||
[JsonPropertyName("value")]
|
||||
public int Value { get; set; }
|
||||
|
||||
// Returns a JSON version of the class settings configuration class.
|
||||
public override string ToString()
|
||||
{
|
||||
return JsonSerializer.Serialize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
// 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.
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library.Interfaces
|
||||
{
|
||||
// Common interface to be implemented by all the objects which get and store settings properties.
|
||||
public interface ISettingsConfig
|
||||
{
|
||||
string ToJsonString();
|
||||
|
||||
string GetModuleName();
|
||||
|
||||
bool UpgradeSettingsConfiguration();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// 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.
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library.Interfaces
|
||||
{
|
||||
public interface ISettingsRepository<T>
|
||||
{
|
||||
T SettingsConfig { get; set; }
|
||||
}
|
||||
}
|
||||
24
src/settings-ui/Settings.UI.Library/KeyBoardKeysProperty.cs
Normal file
24
src/settings-ui/Settings.UI.Library/KeyBoardKeysProperty.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
// 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.Text.Json.Serialization;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public class KeyboardKeysProperty
|
||||
{
|
||||
public KeyboardKeysProperty()
|
||||
{
|
||||
Value = new HotkeySettings();
|
||||
}
|
||||
|
||||
public KeyboardKeysProperty(HotkeySettings hkSettings)
|
||||
{
|
||||
Value = hkSettings;
|
||||
}
|
||||
|
||||
[JsonPropertyName("value")]
|
||||
public HotkeySettings Value { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -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.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public class KeyboardManagerProfile : ISettingsConfig
|
||||
{
|
||||
[JsonPropertyName("remapKeys")]
|
||||
public RemapKeysDataModel RemapKeys { get; set; }
|
||||
|
||||
[JsonPropertyName("remapShortcuts")]
|
||||
public ShortcutsKeyDataModel RemapShortcuts { get; set; }
|
||||
|
||||
public KeyboardManagerProfile()
|
||||
{
|
||||
RemapKeys = new RemapKeysDataModel();
|
||||
RemapShortcuts = new ShortcutsKeyDataModel();
|
||||
}
|
||||
|
||||
public string ToJsonString()
|
||||
{
|
||||
return JsonSerializer.Serialize(this);
|
||||
}
|
||||
|
||||
public string GetModuleName()
|
||||
{
|
||||
return KeyboardManagerSettings.ModuleName;
|
||||
}
|
||||
|
||||
// This can be utilized in the future if the default.json file is to be modified/deleted.
|
||||
public bool UpgradeSettingsConfiguration()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
// 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.Collections.Generic;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public class KeyboardManagerProperties
|
||||
{
|
||||
[JsonPropertyName("activeConfiguration")]
|
||||
public GenericProperty<string> ActiveConfiguration { get; set; }
|
||||
|
||||
// List of all Keyboard Configurations.
|
||||
[JsonPropertyName("keyboardConfigurations")]
|
||||
public GenericProperty<List<string>> KeyboardConfigurations { get; set; }
|
||||
|
||||
public KeyboardManagerProperties()
|
||||
{
|
||||
KeyboardConfigurations = new GenericProperty<List<string>>(new List<string> { "default", });
|
||||
ActiveConfiguration = new GenericProperty<string>("default");
|
||||
}
|
||||
|
||||
public string ToJsonString()
|
||||
{
|
||||
return JsonSerializer.Serialize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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.Text.Json.Serialization;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public class KeyboardManagerSettings : BasePTModuleSettings, ISettingsConfig
|
||||
{
|
||||
public const string ModuleName = "Keyboard Manager";
|
||||
|
||||
[JsonPropertyName("properties")]
|
||||
public KeyboardManagerProperties Properties { get; set; }
|
||||
|
||||
public KeyboardManagerSettings()
|
||||
{
|
||||
Properties = new KeyboardManagerProperties();
|
||||
Version = "1";
|
||||
Name = ModuleName;
|
||||
}
|
||||
|
||||
public string GetModuleName()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
|
||||
// This can be utilized in the future if the settings.json file is to be modified/deleted.
|
||||
public bool UpgradeSettingsConfiguration()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
45
src/settings-ui/Settings.UI.Library/KeysDataModel.cs
Normal file
45
src/settings-ui/Settings.UI.Library/KeysDataModel.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
// 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.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public class KeysDataModel
|
||||
{
|
||||
[JsonPropertyName("originalKeys")]
|
||||
public string OriginalKeys { get; set; }
|
||||
|
||||
[JsonPropertyName("newRemapKeys")]
|
||||
public string NewRemapKeys { get; set; }
|
||||
|
||||
private static List<string> MapKeys(string stringOfKeys)
|
||||
{
|
||||
return stringOfKeys
|
||||
.Split(';')
|
||||
.Select(uint.Parse)
|
||||
.Select(Helper.GetKeyName)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<string> GetMappedOriginalKeys()
|
||||
{
|
||||
return MapKeys(OriginalKeys);
|
||||
}
|
||||
|
||||
public List<string> GetMappedNewRemapKeys()
|
||||
{
|
||||
return MapKeys(NewRemapKeys);
|
||||
}
|
||||
|
||||
public string ToJsonString()
|
||||
{
|
||||
return JsonSerializer.Serialize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
// 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.Text.Json.Serialization;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public class MouseHighlighterProperties
|
||||
{
|
||||
[JsonPropertyName("activation_shortcut")]
|
||||
public HotkeySettings ActivationShortcut { get; set; }
|
||||
|
||||
[JsonPropertyName("left_button_click_color")]
|
||||
public StringProperty LeftButtonClickColor { get; set; }
|
||||
|
||||
[JsonPropertyName("right_button_click_color")]
|
||||
public StringProperty RightButtonClickColor { get; set; }
|
||||
|
||||
[JsonPropertyName("highlight_opacity")]
|
||||
public IntProperty HighlightOpacity { get; set; }
|
||||
|
||||
[JsonPropertyName("highlight_radius")]
|
||||
public IntProperty HighlightRadius { get; set; }
|
||||
|
||||
[JsonPropertyName("highlight_fade_delay_ms")]
|
||||
public IntProperty HighlightFadeDelayMs { get; set; }
|
||||
|
||||
[JsonPropertyName("highlight_fade_duration_ms")]
|
||||
public IntProperty HighlightFadeDurationMs { get; set; }
|
||||
|
||||
public MouseHighlighterProperties()
|
||||
{
|
||||
ActivationShortcut = new HotkeySettings(true, false, false, true, 0x48);
|
||||
LeftButtonClickColor = new StringProperty("#FFFF00");
|
||||
RightButtonClickColor = new StringProperty("#0000FF");
|
||||
HighlightOpacity = new IntProperty(160);
|
||||
HighlightRadius = new IntProperty(20);
|
||||
HighlightFadeDelayMs = new IntProperty(500);
|
||||
HighlightFadeDurationMs = new IntProperty(250);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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.Text.Json.Serialization;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public class MouseHighlighterSettings : BasePTModuleSettings, ISettingsConfig
|
||||
{
|
||||
public const string ModuleName = "MouseHighlighter";
|
||||
|
||||
[JsonPropertyName("properties")]
|
||||
public MouseHighlighterProperties Properties { get; set; }
|
||||
|
||||
public MouseHighlighterSettings()
|
||||
{
|
||||
Name = ModuleName;
|
||||
Properties = new MouseHighlighterProperties();
|
||||
Version = "1.0";
|
||||
}
|
||||
|
||||
public string GetModuleName()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
|
||||
// This can be utilized in the future if the settings.json file is to be modified/deleted.
|
||||
public bool UpgradeSettingsConfiguration()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
// 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.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public class MouseHighlighterSettingsIPCMessage
|
||||
{
|
||||
[JsonPropertyName("powertoys")]
|
||||
public SndMouseHighlighterSettings Powertoys { get; set; }
|
||||
|
||||
public MouseHighlighterSettingsIPCMessage()
|
||||
{
|
||||
}
|
||||
|
||||
public MouseHighlighterSettingsIPCMessage(SndMouseHighlighterSettings settings)
|
||||
{
|
||||
this.Powertoys = settings;
|
||||
}
|
||||
|
||||
public string ToJsonString()
|
||||
{
|
||||
return JsonSerializer.Serialize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
// 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.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public class OutGoingGeneralSettings
|
||||
{
|
||||
[JsonPropertyName("general")]
|
||||
public GeneralSettings GeneralSettings { get; set; }
|
||||
|
||||
public OutGoingGeneralSettings()
|
||||
{
|
||||
}
|
||||
|
||||
public OutGoingGeneralSettings(GeneralSettings generalSettings)
|
||||
{
|
||||
GeneralSettings = generalSettings;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return JsonSerializer.Serialize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
// 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.
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public class PluginAdditionalOption
|
||||
{
|
||||
public string Key { get; set; }
|
||||
|
||||
public string DisplayLabel { get; set; }
|
||||
|
||||
public bool Value { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
// 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.Collections.Generic;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public class PowerLauncherPluginSettings
|
||||
{
|
||||
public string Id { get; set; }
|
||||
|
||||
public string Name { get; set; }
|
||||
|
||||
public string Description { get; set; }
|
||||
|
||||
public string Author { get; set; }
|
||||
|
||||
public bool Disabled { get; set; }
|
||||
|
||||
public bool IsGlobal { get; set; }
|
||||
|
||||
public string ActionKeyword { get; set; }
|
||||
|
||||
public string IconPathDark { get; set; }
|
||||
|
||||
public string IconPathLight { get; set; }
|
||||
|
||||
public IEnumerable<PluginAdditionalOption> AdditionalOptions { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
// 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.Text.Json.Serialization;
|
||||
using ManagedCommon;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public class PowerLauncherProperties
|
||||
{
|
||||
[JsonPropertyName("search_result_preference")]
|
||||
public string SearchResultPreference { get; set; }
|
||||
|
||||
[JsonPropertyName("search_type_preference")]
|
||||
public string SearchTypePreference { get; set; }
|
||||
|
||||
[JsonPropertyName("maximum_number_of_results")]
|
||||
public int MaximumNumberOfResults { get; set; }
|
||||
|
||||
[JsonPropertyName("open_powerlauncher")]
|
||||
public HotkeySettings OpenPowerLauncher { get; set; }
|
||||
|
||||
[JsonPropertyName("open_file_location")]
|
||||
public HotkeySettings OpenFileLocation { get; set; }
|
||||
|
||||
[JsonPropertyName("copy_path_location")]
|
||||
public HotkeySettings CopyPathLocation { get; set; }
|
||||
|
||||
[JsonPropertyName("open_console")]
|
||||
public HotkeySettings OpenConsole { get; set; }
|
||||
|
||||
[JsonPropertyName("override_win_r_key")]
|
||||
public bool OverrideWinkeyR { get; set; }
|
||||
|
||||
[JsonPropertyName("override_win_s_key")]
|
||||
public bool OverrideWinkeyS { get; set; }
|
||||
|
||||
[JsonPropertyName("ignore_hotkeys_in_fullscreen")]
|
||||
public bool IgnoreHotkeysInFullscreen { get; set; }
|
||||
|
||||
[JsonPropertyName("clear_input_on_launch")]
|
||||
public bool ClearInputOnLaunch { get; set; }
|
||||
|
||||
[JsonPropertyName("theme")]
|
||||
public Theme Theme { get; set; }
|
||||
|
||||
[JsonPropertyName("startupPosition")]
|
||||
public StartupPosition Position { get; set; }
|
||||
|
||||
[JsonPropertyName("use_centralized_keyboard_hook")]
|
||||
public bool UseCentralizedKeyboardHook { get; set; }
|
||||
|
||||
public PowerLauncherProperties()
|
||||
{
|
||||
OpenPowerLauncher = new HotkeySettings(false, false, true, false, 32);
|
||||
OpenFileLocation = new HotkeySettings();
|
||||
CopyPathLocation = new HotkeySettings();
|
||||
OpenConsole = new HotkeySettings();
|
||||
SearchResultPreference = "most_recently_used";
|
||||
SearchTypePreference = "application_name";
|
||||
IgnoreHotkeysInFullscreen = false;
|
||||
ClearInputOnLaunch = false;
|
||||
MaximumNumberOfResults = 4;
|
||||
Theme = Theme.System;
|
||||
Position = StartupPosition.Cursor;
|
||||
UseCentralizedKeyboardHook = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
57
src/settings-ui/Settings.UI.Library/PowerLauncherSettings.cs
Normal file
57
src/settings-ui/Settings.UI.Library/PowerLauncherSettings.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
// 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.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public class PowerLauncherSettings : BasePTModuleSettings, ISettingsConfig
|
||||
{
|
||||
public const string ModuleName = "PowerToys Run";
|
||||
|
||||
[JsonPropertyName("properties")]
|
||||
public PowerLauncherProperties Properties { get; set; }
|
||||
|
||||
[JsonPropertyName("plugins")]
|
||||
public IEnumerable<PowerLauncherPluginSettings> Plugins { get; set; } = new List<PowerLauncherPluginSettings>();
|
||||
|
||||
public PowerLauncherSettings()
|
||||
{
|
||||
Properties = new PowerLauncherProperties();
|
||||
Version = "1.0";
|
||||
Name = ModuleName;
|
||||
}
|
||||
|
||||
public virtual void Save(ISettingsUtils settingsUtils)
|
||||
{
|
||||
// Save settings to file
|
||||
var options = new JsonSerializerOptions
|
||||
{
|
||||
WriteIndented = true,
|
||||
};
|
||||
|
||||
if (settingsUtils == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(settingsUtils));
|
||||
}
|
||||
|
||||
settingsUtils.SaveSettings(JsonSerializer.Serialize(this, options), ModuleName);
|
||||
}
|
||||
|
||||
public string GetModuleName()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
|
||||
// This can be utilized in the future if the settings.json file is to be modified/deleted.
|
||||
public bool UpgradeSettingsConfiguration()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
153
src/settings-ui/Settings.UI.Library/PowerPreviewProperties.cs
Normal file
153
src/settings-ui/Settings.UI.Library/PowerPreviewProperties.cs
Normal file
@@ -0,0 +1,153 @@
|
||||
// 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.Runtime.CompilerServices;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using Microsoft.PowerToys.Settings.Telemetry;
|
||||
using Microsoft.PowerToys.Telemetry;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public class PowerPreviewProperties
|
||||
{
|
||||
private bool enableSvgPreview = true;
|
||||
|
||||
[JsonPropertyName("svg-previewer-toggle-setting")]
|
||||
[JsonConverter(typeof(BoolPropertyJsonConverter))]
|
||||
public bool EnableSvgPreview
|
||||
{
|
||||
get => enableSvgPreview;
|
||||
set
|
||||
{
|
||||
if (value != enableSvgPreview)
|
||||
{
|
||||
LogTelemetryEvent(value);
|
||||
enableSvgPreview = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool enableSvgThumbnail = true;
|
||||
|
||||
[JsonPropertyName("svg-thumbnail-toggle-setting")]
|
||||
[JsonConverter(typeof(BoolPropertyJsonConverter))]
|
||||
public bool EnableSvgThumbnail
|
||||
{
|
||||
get => enableSvgThumbnail;
|
||||
set
|
||||
{
|
||||
if (value != enableSvgThumbnail)
|
||||
{
|
||||
LogTelemetryEvent(value);
|
||||
enableSvgThumbnail = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool enableMdPreview = true;
|
||||
|
||||
[JsonPropertyName("md-previewer-toggle-setting")]
|
||||
[JsonConverter(typeof(BoolPropertyJsonConverter))]
|
||||
public bool EnableMdPreview
|
||||
{
|
||||
get => enableMdPreview;
|
||||
set
|
||||
{
|
||||
if (value != enableMdPreview)
|
||||
{
|
||||
LogTelemetryEvent(value);
|
||||
enableMdPreview = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool enablePdfPreview = true;
|
||||
|
||||
[JsonPropertyName("pdf-previewer-toggle-setting")]
|
||||
[JsonConverter(typeof(BoolPropertyJsonConverter))]
|
||||
public bool EnablePdfPreview
|
||||
{
|
||||
get => enablePdfPreview;
|
||||
set
|
||||
{
|
||||
if (value != enablePdfPreview)
|
||||
{
|
||||
LogTelemetryEvent(value);
|
||||
enablePdfPreview = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool enablePdfThumbnail = true;
|
||||
|
||||
[JsonPropertyName("pdf-thumbnail-toggle-setting")]
|
||||
[JsonConverter(typeof(BoolPropertyJsonConverter))]
|
||||
public bool EnablePdfThumbnail
|
||||
{
|
||||
get => enablePdfThumbnail;
|
||||
set
|
||||
{
|
||||
if (value != enablePdfThumbnail)
|
||||
{
|
||||
LogTelemetryEvent(value);
|
||||
enablePdfThumbnail = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool enableGcodePreview = true;
|
||||
|
||||
[JsonPropertyName("gcode-previewer-toggle-setting")]
|
||||
[JsonConverter(typeof(BoolPropertyJsonConverter))]
|
||||
public bool EnableGcodePreview
|
||||
{
|
||||
get => enableGcodePreview;
|
||||
set
|
||||
{
|
||||
if (value != enableGcodePreview)
|
||||
{
|
||||
LogTelemetryEvent(value);
|
||||
enableGcodePreview = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool enableGcodeThumbnail = true;
|
||||
|
||||
[JsonPropertyName("gcode-thumbnail-toggle-setting")]
|
||||
[JsonConverter(typeof(BoolPropertyJsonConverter))]
|
||||
public bool EnableGcodeThumbnail
|
||||
{
|
||||
get => enableGcodeThumbnail;
|
||||
set
|
||||
{
|
||||
if (value != enableGcodeThumbnail)
|
||||
{
|
||||
LogTelemetryEvent(value);
|
||||
enableGcodeThumbnail = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public PowerPreviewProperties()
|
||||
{
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return JsonSerializer.Serialize(this);
|
||||
}
|
||||
|
||||
private static void LogTelemetryEvent(bool value, [CallerMemberName] string propertyName = null)
|
||||
{
|
||||
var dataEvent = new SettingsEnabledEvent()
|
||||
{
|
||||
Value = value,
|
||||
Name = propertyName,
|
||||
};
|
||||
PowerToysTelemetry.Log.WriteEvent(dataEvent);
|
||||
}
|
||||
}
|
||||
}
|
||||
35
src/settings-ui/Settings.UI.Library/PowerPreviewSettings.cs
Normal file
35
src/settings-ui/Settings.UI.Library/PowerPreviewSettings.cs
Normal file
@@ -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.Text.Json.Serialization;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public class PowerPreviewSettings : BasePTModuleSettings, ISettingsConfig
|
||||
{
|
||||
public const string ModuleName = "File Explorer";
|
||||
|
||||
[JsonPropertyName("properties")]
|
||||
public PowerPreviewProperties Properties { get; set; }
|
||||
|
||||
public PowerPreviewSettings()
|
||||
{
|
||||
Properties = new PowerPreviewProperties();
|
||||
Version = "1";
|
||||
Name = ModuleName;
|
||||
}
|
||||
|
||||
public string GetModuleName()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
|
||||
// This can be utilized in the future if the settings.json file is to be modified/deleted.
|
||||
public bool UpgradeSettingsConfiguration()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
// 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.Text.Json;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public class PowerRenameLocalProperties : ISettingsConfig
|
||||
{
|
||||
public PowerRenameLocalProperties()
|
||||
{
|
||||
PersistState = false;
|
||||
MRUEnabled = false;
|
||||
MaxMRUSize = 0;
|
||||
ShowIcon = false;
|
||||
ExtendedContextMenuOnly = false;
|
||||
UseBoostLib = false;
|
||||
}
|
||||
|
||||
private int _maxSize;
|
||||
|
||||
public bool PersistState { get; set; }
|
||||
|
||||
public bool MRUEnabled { get; set; }
|
||||
|
||||
public int MaxMRUSize
|
||||
{
|
||||
get
|
||||
{
|
||||
return _maxSize;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value < 0)
|
||||
{
|
||||
_maxSize = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
_maxSize = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool ShowIcon { get; set; }
|
||||
|
||||
public bool ExtendedContextMenuOnly { get; set; }
|
||||
|
||||
public bool UseBoostLib { get; set; }
|
||||
|
||||
public string ToJsonString()
|
||||
{
|
||||
return JsonSerializer.Serialize(this);
|
||||
}
|
||||
|
||||
// This function is required to implement the ISettingsConfig interface and obtain the settings configurations.
|
||||
public string GetModuleName()
|
||||
{
|
||||
string moduleName = PowerRenameSettings.ModuleName;
|
||||
return moduleName;
|
||||
}
|
||||
|
||||
// This can be utilized in the future if the settings.json file is to be modified/deleted.
|
||||
public bool UpgradeSettingsConfiguration()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
42
src/settings-ui/Settings.UI.Library/PowerRenameProperties.cs
Normal file
42
src/settings-ui/Settings.UI.Library/PowerRenameProperties.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
// 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.Text.Json.Serialization;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public class PowerRenameProperties
|
||||
{
|
||||
public PowerRenameProperties()
|
||||
{
|
||||
PersistState = new BoolProperty();
|
||||
MRUEnabled = new BoolProperty();
|
||||
MaxMRUSize = new IntProperty();
|
||||
ShowIcon = new BoolProperty();
|
||||
ExtendedContextMenuOnly = new BoolProperty();
|
||||
UseBoostLib = new BoolProperty();
|
||||
Enabled = new BoolProperty();
|
||||
}
|
||||
|
||||
public BoolProperty Enabled { get; set; }
|
||||
|
||||
[JsonPropertyName("bool_persist_input")]
|
||||
public BoolProperty PersistState { get; set; }
|
||||
|
||||
[JsonPropertyName("bool_mru_enabled")]
|
||||
public BoolProperty MRUEnabled { get; set; }
|
||||
|
||||
[JsonPropertyName("int_max_mru_size")]
|
||||
public IntProperty MaxMRUSize { get; set; }
|
||||
|
||||
[JsonPropertyName("bool_show_icon_on_menu")]
|
||||
public BoolProperty ShowIcon { get; set; }
|
||||
|
||||
[JsonPropertyName("bool_show_extended_menu")]
|
||||
public BoolProperty ExtendedContextMenuOnly { get; set; }
|
||||
|
||||
[JsonPropertyName("bool_use_boost_lib")]
|
||||
public BoolProperty UseBoostLib { get; set; }
|
||||
}
|
||||
}
|
||||
62
src/settings-ui/Settings.UI.Library/PowerRenameSettings.cs
Normal file
62
src/settings-ui/Settings.UI.Library/PowerRenameSettings.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
// 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.Text.Json.Serialization;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public class PowerRenameSettings : BasePTModuleSettings, ISettingsConfig
|
||||
{
|
||||
public const string ModuleName = "PowerRename";
|
||||
|
||||
[JsonPropertyName("properties")]
|
||||
public PowerRenameProperties Properties { get; set; }
|
||||
|
||||
public PowerRenameSettings()
|
||||
{
|
||||
Properties = new PowerRenameProperties();
|
||||
Version = "1";
|
||||
Name = ModuleName;
|
||||
}
|
||||
|
||||
public PowerRenameSettings(PowerRenameLocalProperties localProperties)
|
||||
{
|
||||
if (localProperties == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(localProperties));
|
||||
}
|
||||
|
||||
Properties = new PowerRenameProperties();
|
||||
Properties.PersistState.Value = localProperties.PersistState;
|
||||
Properties.MRUEnabled.Value = localProperties.MRUEnabled;
|
||||
Properties.MaxMRUSize.Value = localProperties.MaxMRUSize;
|
||||
Properties.ShowIcon.Value = localProperties.ShowIcon;
|
||||
Properties.ExtendedContextMenuOnly.Value = localProperties.ExtendedContextMenuOnly;
|
||||
Properties.UseBoostLib.Value = localProperties.UseBoostLib;
|
||||
|
||||
Version = "1";
|
||||
Name = ModuleName;
|
||||
}
|
||||
|
||||
public PowerRenameSettings(string ptName)
|
||||
{
|
||||
Properties = new PowerRenameProperties();
|
||||
Version = "1";
|
||||
Name = ptName;
|
||||
}
|
||||
|
||||
public string GetModuleName()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
|
||||
// This can be utilized in the future if the power-rename-settings.json file is to be modified/deleted.
|
||||
public bool UpgradeSettingsConfiguration()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
// 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.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public class PowerRenameSettingsIPCMessage
|
||||
{
|
||||
[JsonPropertyName("powertoys")]
|
||||
public SndPowerRenameSettings Powertoys { get; set; }
|
||||
|
||||
public PowerRenameSettingsIPCMessage()
|
||||
{
|
||||
}
|
||||
|
||||
public PowerRenameSettingsIPCMessage(SndPowerRenameSettings settings)
|
||||
{
|
||||
Powertoys = settings;
|
||||
}
|
||||
|
||||
public string ToJsonString()
|
||||
{
|
||||
return JsonSerializer.Serialize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
31
src/settings-ui/Settings.UI.Library/RemapKeysDataModel.cs
Normal file
31
src/settings-ui/Settings.UI.Library/RemapKeysDataModel.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
// 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.Collections.Generic;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public class RemapKeysDataModel
|
||||
{
|
||||
// Suppressing this warning because removing the setter breaks
|
||||
// deserialization with System.Text.Json. This affects the UI display.
|
||||
// See: https://github.com/dotnet/runtime/issues/30258
|
||||
[JsonPropertyName("inProcess")]
|
||||
#pragma warning disable CA2227 // Collection properties should be read only
|
||||
public List<KeysDataModel> InProcessRemapKeys { get; set; }
|
||||
#pragma warning restore CA2227 // Collection properties should be read only
|
||||
|
||||
public RemapKeysDataModel()
|
||||
{
|
||||
InProcessRemapKeys = new List<KeysDataModel>();
|
||||
}
|
||||
|
||||
public string ToJsonString()
|
||||
{
|
||||
return JsonSerializer.Serialize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
62
src/settings-ui/Settings.UI.Library/SettingPath.cs
Normal file
62
src/settings-ui/Settings.UI.Library/SettingPath.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.IO.Abstractions;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public class SettingPath : ISettingsPath
|
||||
{
|
||||
private const string DefaultFileName = "settings.json";
|
||||
|
||||
private readonly IDirectory _directory;
|
||||
|
||||
private readonly IPath _path;
|
||||
|
||||
public SettingPath(IDirectory directory, IPath path)
|
||||
{
|
||||
_directory = directory ?? throw new ArgumentNullException(nameof(directory));
|
||||
_path = path ?? throw new ArgumentNullException(nameof(path));
|
||||
}
|
||||
|
||||
public bool SettingsFolderExists(string powertoy)
|
||||
{
|
||||
return _directory.Exists(System.IO.Path.Combine(LocalApplicationDataFolder(), $"Microsoft\\PowerToys\\{powertoy}"));
|
||||
}
|
||||
|
||||
public void CreateSettingsFolder(string powertoy)
|
||||
{
|
||||
_directory.CreateDirectory(System.IO.Path.Combine(LocalApplicationDataFolder(), $"Microsoft\\PowerToys\\{powertoy}"));
|
||||
}
|
||||
|
||||
public void DeleteSettings(string powertoy = "")
|
||||
{
|
||||
_directory.Delete(System.IO.Path.Combine(LocalApplicationDataFolder(), $"Microsoft\\PowerToys\\{powertoy}"));
|
||||
}
|
||||
|
||||
private static string LocalApplicationDataFolder()
|
||||
{
|
||||
return Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get path to the json settings file.
|
||||
/// </summary>
|
||||
/// <returns>string path.</returns>
|
||||
public string GetSettingsPath(string powertoy, string fileName = DefaultFileName)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(powertoy))
|
||||
{
|
||||
return _path.Combine(
|
||||
LocalApplicationDataFolder(),
|
||||
$"Microsoft\\PowerToys\\{fileName}");
|
||||
}
|
||||
|
||||
return _path.Combine(
|
||||
LocalApplicationDataFolder(),
|
||||
$"Microsoft\\PowerToys\\{powertoy}\\{fileName}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<Import Project="..\..\Version.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<Platforms>x64</Platforms>
|
||||
<Version>$(Version).0</Version>
|
||||
<Authors>Microsoft Corporation</Authors>
|
||||
<Product>PowerToys</Product>
|
||||
<Description>PowerToys Settings UI Library</Description>
|
||||
<Copyright>Copyright (C) 2020 Microsoft Corporation</Copyright>
|
||||
<RepositoryUrl>https://github.com/microsoft/PowerToys</RepositoryUrl>
|
||||
<RepositoryType>Github</RepositoryType>
|
||||
<PackageTags>PowerToys</PackageTags>
|
||||
<NeutralLanguage>en-US</NeutralLanguage>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<AssemblyName>PowerToys.Settings.UI.Lib</AssemblyName>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<DebugType>full</DebugType>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<AdditionalFiles Include="..\..\codeAnalysis\StyleCop.json" Link="StyleCop.json">
|
||||
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
|
||||
</AdditionalFiles>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="..\..\codeAnalysis\GlobalSuppressions.cs" Link="GlobalSuppressions.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="System.IO.Abstractions" Version="12.2.5" />
|
||||
<PackageReference Include="System.Text.Json" Version="5.0.2" />
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers">
|
||||
<Version>3.3.0</Version>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\common\interop\PowerToys.Interop.vcxproj" />
|
||||
<ProjectReference Include="..\..\common\ManagedCommon\ManagedCommon.csproj" />
|
||||
<ProjectReference Include="..\..\common\ManagedTelemetry\Telemetry\ManagedTelemetry.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
70
src/settings-ui/Settings.UI.Library/SettingsRepository`1.cs
Normal file
70
src/settings-ui/Settings.UI.Library/SettingsRepository`1.cs
Normal file
@@ -0,0 +1,70 @@
|
||||
// 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 Microsoft.PowerToys.Settings.UI.Library.Interfaces;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
// This Singleton class is a wrapper around the settings configurations that are accessed by viewmodels.
|
||||
// This class can have only one instance and therefore the settings configurations are common to all.
|
||||
public class SettingsRepository<T> : ISettingsRepository<T>
|
||||
where T : class, ISettingsConfig, new()
|
||||
{
|
||||
private static readonly object _SettingsRepoLock = new object();
|
||||
|
||||
private static ISettingsUtils _settingsUtils;
|
||||
|
||||
private static SettingsRepository<T> settingsRepository;
|
||||
|
||||
private T settingsConfig;
|
||||
|
||||
// Suppressing the warning as this is a singleton class and this method is
|
||||
// necessarily static
|
||||
#pragma warning disable CA1000 // Do not declare static members on generic types
|
||||
public static SettingsRepository<T> GetInstance(ISettingsUtils settingsUtils)
|
||||
#pragma warning restore CA1000 // Do not declare static members on generic types
|
||||
{
|
||||
// To ensure that only one instance of Settings Repository is created in a multi-threaded environment.
|
||||
lock (_SettingsRepoLock)
|
||||
{
|
||||
if (settingsRepository == null)
|
||||
{
|
||||
settingsRepository = new SettingsRepository<T>();
|
||||
_settingsUtils = settingsUtils ?? throw new ArgumentNullException(nameof(settingsUtils));
|
||||
}
|
||||
|
||||
return settingsRepository;
|
||||
}
|
||||
}
|
||||
|
||||
// The Singleton class must have a private constructor so that it cannot be instantiated by any other object other than itself.
|
||||
private SettingsRepository()
|
||||
{
|
||||
}
|
||||
|
||||
// Settings configurations shared across all viewmodels
|
||||
public T SettingsConfig
|
||||
{
|
||||
get
|
||||
{
|
||||
if (settingsConfig == null)
|
||||
{
|
||||
T settingsItem = new T();
|
||||
settingsConfig = _settingsUtils.GetSettingsOrDefault<T>(settingsItem.GetModuleName());
|
||||
}
|
||||
|
||||
return settingsConfig;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != null)
|
||||
{
|
||||
settingsConfig = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
145
src/settings-ui/Settings.UI.Library/SettingsUtils.cs
Normal file
145
src/settings-ui/Settings.UI.Library/SettingsUtils.cs
Normal file
@@ -0,0 +1,145 @@
|
||||
// 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.IO.Abstractions;
|
||||
using System.Text.Json;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public class SettingsUtils : ISettingsUtils
|
||||
{
|
||||
private const string DefaultFileName = "settings.json";
|
||||
private const string DefaultModuleName = "";
|
||||
private readonly IFile _file;
|
||||
private readonly ISettingsPath _settingsPath;
|
||||
|
||||
public SettingsUtils()
|
||||
: this(new FileSystem())
|
||||
{
|
||||
}
|
||||
|
||||
public SettingsUtils(IFileSystem fileSystem)
|
||||
: this(fileSystem?.File, new SettingPath(fileSystem?.Directory, fileSystem?.Path))
|
||||
{
|
||||
}
|
||||
|
||||
public SettingsUtils(IFile file, ISettingsPath settingPath)
|
||||
{
|
||||
_file = file ?? throw new ArgumentNullException(nameof(file));
|
||||
_settingsPath = settingPath;
|
||||
}
|
||||
|
||||
public bool SettingsExists(string powertoy = DefaultModuleName, string fileName = DefaultFileName)
|
||||
{
|
||||
var settingsPath = _settingsPath.GetSettingsPath(powertoy, fileName);
|
||||
return _file.Exists(settingsPath);
|
||||
}
|
||||
|
||||
public void DeleteSettings(string powertoy = "")
|
||||
{
|
||||
_settingsPath.DeleteSettings(powertoy);
|
||||
}
|
||||
|
||||
public T GetSettings<T>(string powertoy = DefaultModuleName, string fileName = DefaultFileName)
|
||||
where T : ISettingsConfig, new()
|
||||
{
|
||||
if (!SettingsExists(powertoy, fileName))
|
||||
{
|
||||
throw new FileNotFoundException();
|
||||
}
|
||||
|
||||
// Given the file already exists, to deserialize the file and read its content.
|
||||
T deserializedSettings = GetFile<T>(powertoy, fileName);
|
||||
|
||||
// If the file needs to be modified, to save the new configurations accordingly.
|
||||
if (deserializedSettings.UpgradeSettingsConfiguration())
|
||||
{
|
||||
SaveSettings(deserializedSettings.ToJsonString(), powertoy, fileName);
|
||||
}
|
||||
|
||||
return deserializedSettings;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a Deserialized object of the json settings string.
|
||||
/// This function creates a file in the powertoy folder if it does not exist and returns an object with default properties.
|
||||
/// </summary>
|
||||
/// <returns>Deserialized json settings object.</returns>
|
||||
public T GetSettingsOrDefault<T>(string powertoy = DefaultModuleName, string fileName = DefaultFileName)
|
||||
where T : ISettingsConfig, new()
|
||||
{
|
||||
try
|
||||
{
|
||||
return GetSettings<T>(powertoy, fileName);
|
||||
}
|
||||
|
||||
// Catch json deserialization exceptions when the file is corrupt and has an invalid json.
|
||||
// If there are any deserialization issues like in https://github.com/microsoft/PowerToys/issues/7500, log the error and create a new settings.json file.
|
||||
// This is different from the case where we have trailing zeros following a valid json file, which we have handled by trimming the trailing zeros.
|
||||
catch (JsonException ex)
|
||||
{
|
||||
Logger.LogError($"Exception encountered while loading {powertoy} settings.", ex);
|
||||
}
|
||||
catch (FileNotFoundException)
|
||||
{
|
||||
Logger.LogInfo($"Settings file {fileName} for {powertoy} was not found.");
|
||||
}
|
||||
|
||||
// If the settings file does not exist or if the file is corrupt, to create a new object with default parameters and save it to a newly created settings file.
|
||||
T newSettingsItem = new T();
|
||||
SaveSettings(newSettingsItem.ToJsonString(), powertoy, fileName);
|
||||
return newSettingsItem;
|
||||
}
|
||||
|
||||
// Given the powerToy folder name and filename to be accessed, this function deserializes and returns the file.
|
||||
private T GetFile<T>(string powertoyFolderName = DefaultModuleName, string fileName = DefaultFileName)
|
||||
{
|
||||
// Adding Trim('\0') to overcome possible NTFS file corruption.
|
||||
// Look at issue https://github.com/microsoft/PowerToys/issues/6413 you'll see the file has a large sum of \0 to fill up a 4096 byte buffer for writing to disk
|
||||
// This, while not totally ideal, does work around the problem by trimming the end.
|
||||
// The file itself did write the content correctly but something is off with the actual end of the file, hence the 0x00 bug
|
||||
var jsonSettingsString = _file.ReadAllText(_settingsPath.GetSettingsPath(powertoyFolderName, fileName)).Trim('\0');
|
||||
return JsonSerializer.Deserialize<T>(jsonSettingsString);
|
||||
}
|
||||
|
||||
// Save settings to a json file.
|
||||
[SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "General exceptions will be logged until we can better understand runtime exception scenarios")]
|
||||
public void SaveSettings(string jsonSettings, string powertoy = DefaultModuleName, string fileName = DefaultFileName)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (jsonSettings != null)
|
||||
{
|
||||
if (!_settingsPath.SettingsFolderExists(powertoy))
|
||||
{
|
||||
_settingsPath.CreateSettingsFolder(powertoy);
|
||||
}
|
||||
|
||||
_file.WriteAllText(_settingsPath.GetSettingsPath(powertoy, fileName), jsonSettings);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.LogError($"Exception encountered while saving {powertoy} settings.", e);
|
||||
#if DEBUG
|
||||
if (e is ArgumentException || e is ArgumentNullException || e is PathTooLongException)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
// Returns the file path to the settings file, that is exposed from the local ISettingsPath instance.
|
||||
public string GetSettingsFilePath(string powertoy = "", string fileName = "settings.json")
|
||||
{
|
||||
return _settingsPath.GetSettingsPath(powertoy, fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
// 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.Text.Json.Serialization;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public class ShortcutGuideProperties
|
||||
{
|
||||
public ShortcutGuideProperties()
|
||||
{
|
||||
OverlayOpacity = new IntProperty(90);
|
||||
UseLegacyPressWinKeyBehavior = new BoolProperty(false);
|
||||
PressTime = new IntProperty(900);
|
||||
Theme = new StringProperty("system");
|
||||
DisabledApps = new StringProperty();
|
||||
OpenShortcutGuide = new HotkeySettings(true, false, false, true, 0xBF);
|
||||
}
|
||||
|
||||
[JsonPropertyName("open_shortcutguide")]
|
||||
public HotkeySettings OpenShortcutGuide { get; set; }
|
||||
|
||||
[JsonPropertyName("overlay_opacity")]
|
||||
public IntProperty OverlayOpacity { get; set; }
|
||||
|
||||
[JsonPropertyName("use_legacy_press_win_key_behavior")]
|
||||
public BoolProperty UseLegacyPressWinKeyBehavior { get; set; }
|
||||
|
||||
[JsonPropertyName("press_time")]
|
||||
public IntProperty PressTime { get; set; }
|
||||
|
||||
[JsonPropertyName("theme")]
|
||||
public StringProperty Theme { get; set; }
|
||||
|
||||
[JsonPropertyName("disabled_apps")]
|
||||
public StringProperty DisabledApps { get; set; }
|
||||
}
|
||||
}
|
||||
35
src/settings-ui/Settings.UI.Library/ShortcutGuideSettings.cs
Normal file
35
src/settings-ui/Settings.UI.Library/ShortcutGuideSettings.cs
Normal file
@@ -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.Text.Json.Serialization;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public class ShortcutGuideSettings : BasePTModuleSettings, ISettingsConfig
|
||||
{
|
||||
public const string ModuleName = "Shortcut Guide";
|
||||
|
||||
[JsonPropertyName("properties")]
|
||||
public ShortcutGuideProperties Properties { get; set; }
|
||||
|
||||
public ShortcutGuideSettings()
|
||||
{
|
||||
Name = ModuleName;
|
||||
Properties = new ShortcutGuideProperties();
|
||||
Version = "1.0";
|
||||
}
|
||||
|
||||
public string GetModuleName()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
|
||||
// This can be utilized in the future if the settings.json file is to be modified/deleted.
|
||||
public bool UpgradeSettingsConfiguration()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
// 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.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public class ShortcutGuideSettingsIPCMessage
|
||||
{
|
||||
[JsonPropertyName("powertoys")]
|
||||
public SndShortcutGuideSettings Powertoys { get; set; }
|
||||
|
||||
public ShortcutGuideSettingsIPCMessage()
|
||||
{
|
||||
}
|
||||
|
||||
public ShortcutGuideSettingsIPCMessage(SndShortcutGuideSettings settings)
|
||||
{
|
||||
Powertoys = settings;
|
||||
}
|
||||
|
||||
public string ToJsonString()
|
||||
{
|
||||
return JsonSerializer.Serialize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
37
src/settings-ui/Settings.UI.Library/ShortcutsKeyDataModel.cs
Normal file
37
src/settings-ui/Settings.UI.Library/ShortcutsKeyDataModel.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
// 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.Collections.Generic;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public class ShortcutsKeyDataModel
|
||||
{
|
||||
// Suppressing these warnings because removing the setter breaks
|
||||
// deserialization with System.Text.Json. This affects the UI display.
|
||||
// See: https://github.com/dotnet/runtime/issues/30258
|
||||
[JsonPropertyName("global")]
|
||||
#pragma warning disable CA2227 // Collection properties should be read only
|
||||
public List<KeysDataModel> GlobalRemapShortcuts { get; set; }
|
||||
#pragma warning restore CA2227 // Collection properties should be read only
|
||||
|
||||
[JsonPropertyName("appSpecific")]
|
||||
#pragma warning disable CA2227 // Collection properties should be read only
|
||||
public List<AppSpecificKeysDataModel> AppSpecificRemapShortcuts { get; set; }
|
||||
#pragma warning restore CA2227 // Collection properties should be read only
|
||||
|
||||
public ShortcutsKeyDataModel()
|
||||
{
|
||||
GlobalRemapShortcuts = new List<KeysDataModel>();
|
||||
AppSpecificRemapShortcuts = new List<AppSpecificKeysDataModel>();
|
||||
}
|
||||
|
||||
public string ToJsonString()
|
||||
{
|
||||
return JsonSerializer.Serialize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
29
src/settings-ui/Settings.UI.Library/SndAwakeSettings.cs
Normal file
29
src/settings-ui/Settings.UI.Library/SndAwakeSettings.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
// 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.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public class SndAwakeSettings
|
||||
{
|
||||
[JsonPropertyName("Awake")]
|
||||
public AwakeSettings Settings { get; set; }
|
||||
|
||||
public SndAwakeSettings()
|
||||
{
|
||||
}
|
||||
|
||||
public SndAwakeSettings(AwakeSettings settings)
|
||||
{
|
||||
Settings = settings;
|
||||
}
|
||||
|
||||
public string ToJsonString()
|
||||
{
|
||||
return JsonSerializer.Serialize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
// 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.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public class SndFindMyMouseSettings
|
||||
{
|
||||
[JsonPropertyName("FindMyMouse")]
|
||||
public FindMyMouseSettings FindMyMouse { get; set; }
|
||||
|
||||
public SndFindMyMouseSettings()
|
||||
{
|
||||
}
|
||||
|
||||
public SndFindMyMouseSettings(FindMyMouseSettings settings)
|
||||
{
|
||||
FindMyMouse = settings;
|
||||
}
|
||||
|
||||
public string ToJsonString()
|
||||
{
|
||||
return JsonSerializer.Serialize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
// 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.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public class SndImageResizerSettings
|
||||
{
|
||||
[JsonPropertyName("Image Resizer")]
|
||||
public ImageResizerSettings ImageResizer { get; set; }
|
||||
|
||||
public SndImageResizerSettings(ImageResizerSettings settings)
|
||||
{
|
||||
ImageResizer = settings;
|
||||
}
|
||||
|
||||
public string ToJsonString()
|
||||
{
|
||||
return JsonSerializer.Serialize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
// 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.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public class SndKeyboardManagerSettings
|
||||
{
|
||||
[JsonPropertyName("Keyboard Manager")]
|
||||
public KeyboardManagerSettings KeyboardManagerSettings { get; }
|
||||
|
||||
public SndKeyboardManagerSettings(KeyboardManagerSettings keyboardManagerSettings)
|
||||
{
|
||||
KeyboardManagerSettings = keyboardManagerSettings;
|
||||
}
|
||||
|
||||
public string ToJsonString()
|
||||
{
|
||||
return JsonSerializer.Serialize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
30
src/settings-ui/Settings.UI.Library/SndModuleSettings`1.cs
Normal file
30
src/settings-ui/Settings.UI.Library/SndModuleSettings`1.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
// 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.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
// Represents a powertoys module settings sent to the runner.
|
||||
public class SndModuleSettings<T>
|
||||
{
|
||||
[JsonPropertyName("powertoys")]
|
||||
public T PowertoysSetting { get; set; }
|
||||
|
||||
public SndModuleSettings()
|
||||
{
|
||||
}
|
||||
|
||||
public SndModuleSettings(T settings)
|
||||
{
|
||||
PowertoysSetting = settings;
|
||||
}
|
||||
|
||||
public string ToJsonString()
|
||||
{
|
||||
return JsonSerializer.Serialize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
// 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.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public class SndMouseHighlighterSettings
|
||||
{
|
||||
[JsonPropertyName("MouseHighlighter")]
|
||||
public MouseHighlighterSettings MouseHighlighter { get; set; }
|
||||
|
||||
public SndMouseHighlighterSettings()
|
||||
{
|
||||
}
|
||||
|
||||
public SndMouseHighlighterSettings(MouseHighlighterSettings settings)
|
||||
{
|
||||
MouseHighlighter = settings;
|
||||
}
|
||||
|
||||
public string ToJsonString()
|
||||
{
|
||||
return JsonSerializer.Serialize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
// 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.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public class SndPowerPreviewSettings
|
||||
{
|
||||
[JsonPropertyName("File Explorer")]
|
||||
public PowerPreviewSettings FileExplorerPreviewSettings { get; set; }
|
||||
|
||||
public SndPowerPreviewSettings()
|
||||
{
|
||||
}
|
||||
|
||||
public SndPowerPreviewSettings(PowerPreviewSettings settings)
|
||||
{
|
||||
FileExplorerPreviewSettings = settings;
|
||||
}
|
||||
|
||||
public string ToJsonString()
|
||||
{
|
||||
return JsonSerializer.Serialize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
// 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.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public class SndPowerRenameSettings
|
||||
{
|
||||
[JsonPropertyName("PowerRename")]
|
||||
public PowerRenameSettings PowerRename { get; set; }
|
||||
|
||||
public SndPowerRenameSettings()
|
||||
{
|
||||
}
|
||||
|
||||
public SndPowerRenameSettings(PowerRenameSettings settings)
|
||||
{
|
||||
PowerRename = settings;
|
||||
}
|
||||
|
||||
public string ToJsonString()
|
||||
{
|
||||
return JsonSerializer.Serialize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
// 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.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public class SndShortcutGuideSettings
|
||||
{
|
||||
[JsonPropertyName("Shortcut Guide")]
|
||||
public ShortcutGuideSettings ShortcutGuide { get; set; }
|
||||
|
||||
public SndShortcutGuideSettings()
|
||||
{
|
||||
}
|
||||
|
||||
public SndShortcutGuideSettings(ShortcutGuideSettings settings)
|
||||
{
|
||||
ShortcutGuide = settings;
|
||||
}
|
||||
|
||||
public string ToJsonString()
|
||||
{
|
||||
return JsonSerializer.Serialize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
// 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.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public class SndVideoConferenceSettings
|
||||
{
|
||||
[JsonPropertyName("Video Conference")]
|
||||
public VideoConferenceSettings VideoConference { get; set; }
|
||||
|
||||
public SndVideoConferenceSettings(VideoConferenceSettings settings)
|
||||
{
|
||||
VideoConference = settings;
|
||||
}
|
||||
|
||||
public string ToJsonString()
|
||||
{
|
||||
return JsonSerializer.Serialize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
44
src/settings-ui/Settings.UI.Library/StringProperty.cs
Normal file
44
src/settings-ui/Settings.UI.Library/StringProperty.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
// 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.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
// Represents the configuration property of the settings that store string type.
|
||||
public class StringProperty
|
||||
{
|
||||
public StringProperty()
|
||||
{
|
||||
Value = string.Empty;
|
||||
}
|
||||
|
||||
public StringProperty(string value)
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
|
||||
// Gets or sets the integer value of the settings configuration.
|
||||
[JsonPropertyName("value")]
|
||||
public string Value { get; set; }
|
||||
|
||||
// Returns a JSON version of the class settings configuration class.
|
||||
public override string ToString()
|
||||
{
|
||||
return JsonSerializer.Serialize(this);
|
||||
}
|
||||
|
||||
public static StringProperty ToStringProperty(string v)
|
||||
{
|
||||
return new StringProperty(v);
|
||||
}
|
||||
|
||||
public static implicit operator StringProperty(string v)
|
||||
{
|
||||
return new StringProperty(v);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// 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.Diagnostics.Tracing;
|
||||
using Microsoft.PowerToys.Telemetry;
|
||||
using Microsoft.PowerToys.Telemetry.Events;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library.Telemetry.Events
|
||||
{
|
||||
[EventData]
|
||||
public class OobeModuleRunEvent : EventBase, IEvent
|
||||
{
|
||||
public string ModuleName { get; set; }
|
||||
|
||||
public PartA_PrivTags PartA_PrivTags => PartA_PrivTags.ProductAndServiceUsage;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
// 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.Diagnostics.Tracing;
|
||||
using Microsoft.PowerToys.Telemetry;
|
||||
using Microsoft.PowerToys.Telemetry.Events;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library.Telemetry.Events
|
||||
{
|
||||
[EventData]
|
||||
public class OobeSectionEvent : EventBase, IEvent
|
||||
{
|
||||
public string Section { get; set; }
|
||||
|
||||
public double TimeOpenedMs { get; set; }
|
||||
|
||||
public PartA_PrivTags PartA_PrivTags => PartA_PrivTags.ProductAndServiceUsage;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// 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.Diagnostics.Tracing;
|
||||
using Microsoft.PowerToys.Telemetry;
|
||||
using Microsoft.PowerToys.Telemetry.Events;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library.Telemetry.Events
|
||||
{
|
||||
[EventData]
|
||||
public class OobeSettingsEvent : EventBase, IEvent
|
||||
{
|
||||
public string ModuleName { get; set; }
|
||||
|
||||
public PartA_PrivTags PartA_PrivTags => PartA_PrivTags.ProductAndServiceUsage;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// 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.Diagnostics.Tracing;
|
||||
using Microsoft.PowerToys.Telemetry;
|
||||
using Microsoft.PowerToys.Telemetry.Events;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library.Telemetry.Events
|
||||
{
|
||||
[EventData]
|
||||
public class OobeStartedEvent : EventBase, IEvent
|
||||
{
|
||||
public bool OobeStarted { get; set; } = true;
|
||||
|
||||
public PartA_PrivTags PartA_PrivTags => PartA_PrivTags.ProductAndServiceUsage;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// 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.Diagnostics.Tracing;
|
||||
using Microsoft.PowerToys.Telemetry;
|
||||
using Microsoft.PowerToys.Telemetry.Events;
|
||||
|
||||
namespace Microsoft.PowerLauncher.Telemetry
|
||||
{
|
||||
[EventData]
|
||||
public class SettingsBootEvent : EventBase, IEvent
|
||||
{
|
||||
public double BootTimeMs { get; set; }
|
||||
|
||||
public PartA_PrivTags PartA_PrivTags => PartA_PrivTags.ProductAndServicePerformance;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
// 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.Diagnostics.Tracing;
|
||||
using Microsoft.PowerToys.Telemetry;
|
||||
using Microsoft.PowerToys.Telemetry.Events;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.Telemetry
|
||||
{
|
||||
[EventData]
|
||||
public class SettingsEnabledEvent : EventBase, IEvent
|
||||
{
|
||||
public string Name { get; set; }
|
||||
|
||||
public bool Value { get; set; }
|
||||
|
||||
public PartA_PrivTags PartA_PrivTags => PartA_PrivTags.ProductAndServiceUsage;
|
||||
}
|
||||
}
|
||||
126
src/settings-ui/Settings.UI.Library/UpdatingSettings.cs
Normal file
126
src/settings-ui/Settings.UI.Library/UpdatingSettings.cs
Normal file
@@ -0,0 +1,126 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.IO.Abstractions;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public class UpdatingSettings
|
||||
{
|
||||
public enum UpdatingState
|
||||
{
|
||||
UpToDate = 0,
|
||||
ErrorDownloading,
|
||||
ReadyToDownload,
|
||||
ReadyToInstall,
|
||||
}
|
||||
|
||||
// Gets or sets a value of the updating state
|
||||
[JsonPropertyName("state")]
|
||||
public UpdatingState State { get; set; }
|
||||
|
||||
// Gets or sets a value of the release page url
|
||||
[JsonPropertyName("releasePageUrl")]
|
||||
public string ReleasePageLink { get; set; }
|
||||
|
||||
// Gets or sets a value of the github last checked date
|
||||
[JsonPropertyName("githubUpdateLastCheckedDate")]
|
||||
public string LastCheckedDate { get; set; }
|
||||
|
||||
// Gets or sets a value of the updating state
|
||||
[JsonPropertyName("downloadedInstallerFilename")]
|
||||
public string DownloadedInstallerFilename { get; set; }
|
||||
|
||||
// Non-localizable strings: Files
|
||||
public const string SettingsFilePath = "\\Microsoft\\PowerToys\\";
|
||||
public const string SettingsFile = "UpdateState.json";
|
||||
|
||||
public string NewVersion
|
||||
{
|
||||
get
|
||||
{
|
||||
if (ReleasePageLink == null)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
string version = ReleasePageLink.Substring(ReleasePageLink.LastIndexOf('/') + 1);
|
||||
return version.Trim();
|
||||
}
|
||||
#pragma warning disable CA1031 // Do not catch general exception types
|
||||
catch (Exception)
|
||||
#pragma warning restore CA1031 // Do not catch general exception types
|
||||
{
|
||||
}
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
public string LastCheckedDateLocalized
|
||||
{
|
||||
get
|
||||
{
|
||||
try
|
||||
{
|
||||
long seconds = long.Parse(LastCheckedDate, CultureInfo.CurrentCulture);
|
||||
var date = DateTimeOffset.FromUnixTimeSeconds(seconds).UtcDateTime;
|
||||
return date.ToLocalTime().ToString(CultureInfo.CurrentCulture);
|
||||
}
|
||||
#pragma warning disable CA1031 // Do not catch general exception types
|
||||
catch (Exception)
|
||||
#pragma warning restore CA1031 // Do not catch general exception types
|
||||
{
|
||||
}
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
public UpdatingSettings()
|
||||
{
|
||||
State = UpdatingState.UpToDate;
|
||||
}
|
||||
|
||||
public static UpdatingSettings LoadSettings()
|
||||
{
|
||||
FileSystem fileSystem = new FileSystem();
|
||||
var localAppDataDir = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
|
||||
var file = localAppDataDir + SettingsFilePath + SettingsFile;
|
||||
|
||||
if (fileSystem.File.Exists(file))
|
||||
{
|
||||
try
|
||||
{
|
||||
Stream inputStream = fileSystem.File.Open(file, FileMode.Open);
|
||||
StreamReader reader = new StreamReader(inputStream);
|
||||
string data = reader.ReadToEnd();
|
||||
inputStream.Close();
|
||||
reader.Dispose();
|
||||
|
||||
return JsonSerializer.Deserialize<UpdatingSettings>(data);
|
||||
}
|
||||
#pragma warning disable CA1031 // Do not catch general exception types
|
||||
catch (Exception)
|
||||
#pragma warning restore CA1031 // Do not catch general exception types
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public string ToJsonString()
|
||||
{
|
||||
return JsonSerializer.Serialize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
139
src/settings-ui/Settings.UI.Library/Utilities/Helper.cs
Normal file
139
src/settings-ui/Settings.UI.Library/Utilities/Helper.cs
Normal file
@@ -0,0 +1,139 @@
|
||||
// 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.IO;
|
||||
using System.IO.Abstractions;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.CustomAction;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library.Utilities
|
||||
{
|
||||
public static class Helper
|
||||
{
|
||||
public static readonly IFileSystem FileSystem = new FileSystem();
|
||||
|
||||
public static bool AllowRunnerToForeground()
|
||||
{
|
||||
var result = false;
|
||||
var processes = Process.GetProcessesByName("PowerToys");
|
||||
if (processes.Length > 0)
|
||||
{
|
||||
var pid = processes[0].Id;
|
||||
result = NativeMethods.AllowSetForegroundWindow(pid);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static string GetSerializedCustomAction(string moduleName, string actionName, string actionValue)
|
||||
{
|
||||
var customAction = new CustomActionDataModel
|
||||
{
|
||||
Name = actionName,
|
||||
Value = actionValue,
|
||||
};
|
||||
|
||||
var moduleCustomAction = new ModuleCustomAction
|
||||
{
|
||||
ModuleAction = customAction,
|
||||
};
|
||||
|
||||
var sendCustomAction = new SendCustomAction(moduleName)
|
||||
{
|
||||
Action = moduleCustomAction,
|
||||
};
|
||||
|
||||
return sendCustomAction.ToJsonString();
|
||||
}
|
||||
|
||||
public static IFileSystemWatcher GetFileWatcher(string moduleName, string fileName, Action onChangedCallback)
|
||||
{
|
||||
var path = FileSystem.Path.Combine(LocalApplicationDataFolder(), $"Microsoft\\PowerToys\\{moduleName}");
|
||||
|
||||
if (!FileSystem.Directory.Exists(path))
|
||||
{
|
||||
FileSystem.Directory.CreateDirectory(path);
|
||||
}
|
||||
|
||||
var watcher = FileSystem.FileSystemWatcher.CreateNew();
|
||||
watcher.Path = path;
|
||||
watcher.Filter = fileName;
|
||||
watcher.NotifyFilter = NotifyFilters.LastWrite;
|
||||
watcher.EnableRaisingEvents = true;
|
||||
|
||||
watcher.Changed += (o, e) => onChangedCallback();
|
||||
|
||||
return watcher;
|
||||
}
|
||||
|
||||
private static string LocalApplicationDataFolder()
|
||||
{
|
||||
return Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
|
||||
}
|
||||
|
||||
public static string GetPowerToysInstallationFolder()
|
||||
{
|
||||
var settingsPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
|
||||
return Directory.GetParent(settingsPath).FullName;
|
||||
}
|
||||
|
||||
private static readonly interop.LayoutMapManaged LayoutMap = new interop.LayoutMapManaged();
|
||||
|
||||
public static string GetKeyName(uint key)
|
||||
{
|
||||
return LayoutMap.GetKeyName(key);
|
||||
}
|
||||
|
||||
public static string GetProductVersion()
|
||||
{
|
||||
return interop.CommonManaged.GetProductVersion();
|
||||
}
|
||||
|
||||
public static int CompareVersions(string version1, string version2)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Split up the version strings into int[]
|
||||
// Example: v10.0.2 -> {10, 0, 2};
|
||||
if (version1 == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(version1));
|
||||
}
|
||||
else if (version2 == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(version2));
|
||||
}
|
||||
|
||||
var v1 = version1.Substring(1).Split('.').Select(int.Parse).ToArray();
|
||||
var v2 = version2.Substring(1).Split('.').Select(int.Parse).ToArray();
|
||||
|
||||
if (v1.Length != 3 || v2.Length != 3)
|
||||
{
|
||||
throw new FormatException();
|
||||
}
|
||||
|
||||
if (v1[0] - v2[0] != 0)
|
||||
{
|
||||
return v1[0] - v2[0];
|
||||
}
|
||||
|
||||
if (v1[1] - v2[1] != 0)
|
||||
{
|
||||
return v1[1] - v2[1];
|
||||
}
|
||||
|
||||
return v1[2] - v2[2];
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw new FormatException("Bad product version format");
|
||||
}
|
||||
}
|
||||
|
||||
public const uint VirtualKeyWindows = interop.Constants.VK_WIN_BOTH;
|
||||
}
|
||||
}
|
||||
21
src/settings-ui/Settings.UI.Library/Utilities/IIOProvider.cs
Normal file
21
src/settings-ui/Settings.UI.Library/Utilities/IIOProvider.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
// 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.
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library.Utilities
|
||||
{
|
||||
public interface IIOProvider
|
||||
{
|
||||
bool FileExists(string path);
|
||||
|
||||
bool DirectoryExists(string path);
|
||||
|
||||
bool CreateDirectory(string path);
|
||||
|
||||
void DeleteDirectory(string path);
|
||||
|
||||
void WriteAllText(string path, string content);
|
||||
|
||||
string ReadAllText(string path);
|
||||
}
|
||||
}
|
||||
81
src/settings-ui/Settings.UI.Library/Utilities/Logger.cs
Normal file
81
src/settings-ui/Settings.UI.Library/Utilities/Logger.cs
Normal file
@@ -0,0 +1,81 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.IO.Abstractions;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library.Utilities
|
||||
{
|
||||
public static class Logger
|
||||
{
|
||||
private static readonly IFileSystem FileSystem = new FileSystem();
|
||||
private static readonly IPath Path = FileSystem.Path;
|
||||
private static readonly IDirectory Directory = FileSystem.Directory;
|
||||
|
||||
private static readonly string ApplicationLogPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Microsoft\\PowerToys\\Settings Logs");
|
||||
|
||||
static Logger()
|
||||
{
|
||||
if (!Directory.Exists(ApplicationLogPath))
|
||||
{
|
||||
Directory.CreateDirectory(ApplicationLogPath);
|
||||
}
|
||||
|
||||
// Using InvariantCulture since this is used for a log file name
|
||||
var logFilePath = Path.Combine(ApplicationLogPath, "Log_" + DateTime.Now.ToString(@"yyyy-MM-dd", CultureInfo.InvariantCulture) + ".txt");
|
||||
|
||||
Trace.Listeners.Add(new TextWriterTraceListener(logFilePath));
|
||||
|
||||
Trace.AutoFlush = true;
|
||||
}
|
||||
|
||||
public static void LogInfo(string message)
|
||||
{
|
||||
Log(message, "INFO");
|
||||
}
|
||||
|
||||
public static void LogError(string message)
|
||||
{
|
||||
Log(message, "ERROR");
|
||||
#if DEBUG
|
||||
Debugger.Break();
|
||||
#endif
|
||||
}
|
||||
|
||||
public static void LogError(string message, Exception e)
|
||||
{
|
||||
Log(
|
||||
message + Environment.NewLine +
|
||||
e?.Message + Environment.NewLine +
|
||||
"Inner exception: " + Environment.NewLine +
|
||||
e?.InnerException?.Message + Environment.NewLine +
|
||||
"Stack trace: " + Environment.NewLine +
|
||||
e?.StackTrace,
|
||||
"ERROR");
|
||||
#if DEBUG
|
||||
Debugger.Break();
|
||||
#endif
|
||||
}
|
||||
|
||||
private static void Log(string message, string type)
|
||||
{
|
||||
Trace.WriteLine(type + ": " + DateTime.Now.TimeOfDay);
|
||||
Trace.Indent();
|
||||
Trace.WriteLine(GetCallerInfo());
|
||||
Trace.WriteLine(message);
|
||||
Trace.Unindent();
|
||||
}
|
||||
|
||||
private static string GetCallerInfo()
|
||||
{
|
||||
StackTrace stackTrace = new StackTrace();
|
||||
|
||||
var methodName = stackTrace.GetFrame(3)?.GetMethod();
|
||||
var className = methodName?.DeclaringType.Name;
|
||||
return "[Method]: " + methodName?.Name + " [Class]: " + className;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
// 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.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library.Utilities
|
||||
{
|
||||
internal static class NativeMethods
|
||||
{
|
||||
[DllImport("user32.dll")]
|
||||
public static extern bool AllowSetForegroundWindow(int dwProcessId);
|
||||
|
||||
public const int SWRESTORE = 9;
|
||||
|
||||
[System.Runtime.InteropServices.DllImport("User32.dll")]
|
||||
public static extern bool SetForegroundWindow(IntPtr handle);
|
||||
|
||||
[System.Runtime.InteropServices.DllImport("User32.dll")]
|
||||
public static extern bool ShowWindow(IntPtr handle, int nCmdShow);
|
||||
|
||||
[System.Runtime.InteropServices.DllImport("User32.dll")]
|
||||
public static extern bool IsIconic(IntPtr handle);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.IO.Abstractions;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library.Utilities
|
||||
{
|
||||
public class SystemIOProvider : IIOProvider
|
||||
{
|
||||
private readonly IDirectory _directory;
|
||||
private readonly IFile _file;
|
||||
|
||||
public SystemIOProvider()
|
||||
: this(new FileSystem())
|
||||
{
|
||||
}
|
||||
|
||||
public SystemIOProvider(IFileSystem fileSystem)
|
||||
: this(fileSystem?.Directory, fileSystem?.File)
|
||||
{
|
||||
}
|
||||
|
||||
private SystemIOProvider(IDirectory directory, IFile file)
|
||||
{
|
||||
_directory = directory ?? throw new ArgumentNullException(nameof(directory));
|
||||
_file = file ?? throw new ArgumentNullException(nameof(file));
|
||||
}
|
||||
|
||||
public bool CreateDirectory(string path)
|
||||
{
|
||||
var directoryInfo = _directory.CreateDirectory(path);
|
||||
return directoryInfo != null;
|
||||
}
|
||||
|
||||
public void DeleteDirectory(string path)
|
||||
{
|
||||
_directory.Delete(path, recursive: true);
|
||||
}
|
||||
|
||||
public bool DirectoryExists(string path)
|
||||
{
|
||||
return _directory.Exists(path);
|
||||
}
|
||||
|
||||
public bool FileExists(string path)
|
||||
{
|
||||
return _file.Exists(path);
|
||||
}
|
||||
|
||||
public string ReadAllText(string path)
|
||||
{
|
||||
return _file.ReadAllText(path);
|
||||
}
|
||||
|
||||
public void WriteAllText(string path, string content)
|
||||
{
|
||||
_file.WriteAllText(path, content);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
// 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.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public class VideoConferenceConfigProperties
|
||||
{
|
||||
public VideoConferenceConfigProperties()
|
||||
{
|
||||
this.MuteCameraAndMicrophoneHotkey = new KeyboardKeysProperty(
|
||||
new HotkeySettings()
|
||||
{
|
||||
Win = true,
|
||||
Ctrl = false,
|
||||
Alt = false,
|
||||
Shift = false,
|
||||
Key = "N",
|
||||
Code = 78,
|
||||
});
|
||||
|
||||
this.MuteMicrophoneHotkey = new KeyboardKeysProperty(
|
||||
new HotkeySettings()
|
||||
{
|
||||
Win = true,
|
||||
Ctrl = false,
|
||||
Alt = false,
|
||||
Shift = true,
|
||||
Key = "A",
|
||||
Code = 65,
|
||||
});
|
||||
|
||||
this.MuteCameraHotkey = new KeyboardKeysProperty(
|
||||
new HotkeySettings()
|
||||
{
|
||||
Win = true,
|
||||
Ctrl = false,
|
||||
Alt = false,
|
||||
Shift = true,
|
||||
Key = "O",
|
||||
Code = 79,
|
||||
});
|
||||
|
||||
this.HideToolbarWhenUnmuted = new BoolProperty(true);
|
||||
}
|
||||
|
||||
[JsonPropertyName("mute_camera_and_microphone_hotkey")]
|
||||
public KeyboardKeysProperty MuteCameraAndMicrophoneHotkey { get; set; }
|
||||
|
||||
[JsonPropertyName("mute_microphone_hotkey")]
|
||||
public KeyboardKeysProperty MuteMicrophoneHotkey { get; set; }
|
||||
|
||||
[JsonPropertyName("mute_camera_hotkey")]
|
||||
public KeyboardKeysProperty MuteCameraHotkey { get; set; }
|
||||
|
||||
[JsonPropertyName("selected_camera")]
|
||||
public StringProperty SelectedCamera { get; set; } = string.Empty;
|
||||
|
||||
[JsonPropertyName("selected_mic")]
|
||||
public StringProperty SelectedMicrophone { get; set; } = string.Empty;
|
||||
|
||||
[JsonPropertyName("toolbar_position")]
|
||||
public StringProperty ToolbarPosition { get; set; } = "Top right corner";
|
||||
|
||||
[JsonPropertyName("toolbar_monitor")]
|
||||
public StringProperty ToolbarMonitor { get; set; } = "Main monitor";
|
||||
|
||||
[JsonPropertyName("camera_overlay_image_path")]
|
||||
public StringProperty CameraOverlayImagePath { get; set; } = string.Empty;
|
||||
|
||||
[JsonPropertyName("theme")]
|
||||
public StringProperty Theme { get; set; }
|
||||
|
||||
[JsonPropertyName("hide_toolbar_when_unmuted")]
|
||||
public BoolProperty HideToolbarWhenUnmuted { get; set; }
|
||||
|
||||
// converts the current to a json string.
|
||||
public string ToJsonString()
|
||||
{
|
||||
return JsonSerializer.Serialize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// 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.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public class VideoConferenceSettings : BasePTModuleSettings, ISettingsConfig
|
||||
{
|
||||
public VideoConferenceSettings()
|
||||
{
|
||||
Version = "1";
|
||||
Name = "Video Conference";
|
||||
Properties = new VideoConferenceConfigProperties();
|
||||
}
|
||||
|
||||
[JsonPropertyName("properties")]
|
||||
public VideoConferenceConfigProperties Properties { get; set; }
|
||||
|
||||
public string GetModuleName()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
|
||||
public bool UpgradeSettingsConfiguration()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
// 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.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public class VideoConferenceSettingsIPCMessage
|
||||
{
|
||||
[JsonPropertyName("powertoys")]
|
||||
public SndVideoConferenceSettings Powertoys { get; set; }
|
||||
|
||||
public VideoConferenceSettingsIPCMessage()
|
||||
{
|
||||
}
|
||||
|
||||
public VideoConferenceSettingsIPCMessage(SndVideoConferenceSettings settings)
|
||||
{
|
||||
this.Powertoys = settings;
|
||||
}
|
||||
|
||||
public string ToJsonString()
|
||||
{
|
||||
return JsonSerializer.Serialize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user