mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-08 20:27:36 +02:00
[fxcop] Settings UI library (part 4) - project/namespace renames (#7403)
* Rename Interface to Interfaces in namespaces * Rename Lib to Library in namespaces * Rename project and directory and enable fxcop * Add CA2213 suppression * Minor fixes
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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.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());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
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,
|
||||
}
|
||||
|
||||
public class ColorPickerProperties
|
||||
{
|
||||
public ColorPickerProperties()
|
||||
{
|
||||
ActivationShortcut = new HotkeySettings(true, false, false, true, 0x43);
|
||||
ChangeCursor = false;
|
||||
}
|
||||
|
||||
public HotkeySettings ActivationShortcut { get; set; }
|
||||
|
||||
[JsonPropertyName("changecursor")]
|
||||
[JsonConverter(typeof(BoolPropertyJsonConverter))]
|
||||
public bool ChangeCursor { get; set; }
|
||||
|
||||
[JsonPropertyName("copiedcolorrepresentation")]
|
||||
public ColorRepresentationType CopiedColorRepresentation { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
=> JsonSerializer.Serialize(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
// 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()
|
||||
{
|
||||
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,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
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,161 @@
|
||||
// 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 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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,104 @@
|
||||
// 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
|
||||
{
|
||||
public static readonly HotkeySettings DefaultHotkeyValue = new HotkeySettings(true, false, false, false, 0xc0);
|
||||
|
||||
public FZConfigProperties()
|
||||
{
|
||||
FancyzonesShiftDrag = new BoolProperty(ConfigDefaults.DefaultFancyzonesShiftDrag);
|
||||
FancyzonesOverrideSnapHotkeys = new BoolProperty();
|
||||
FancyzonesMouseSwitch = new BoolProperty();
|
||||
FancyzonesMoveWindowsAcrossMonitors = new BoolProperty();
|
||||
FancyzonesMoveWindowsBasedOnPosition = new BoolProperty();
|
||||
FancyzonesDisplayChangeMoveWindows = new BoolProperty();
|
||||
FancyzonesZoneSetChangeMoveWindows = new BoolProperty();
|
||||
FancyzonesAppLastZoneMoveWindows = new BoolProperty();
|
||||
FancyzonesOpenWindowOnActiveMonitor = new BoolProperty();
|
||||
FancyzonesRestoreSize = new BoolProperty();
|
||||
UseCursorposEditorStartupscreen = new BoolProperty(ConfigDefaults.DefaultUseCursorposEditorStartupscreen);
|
||||
FancyzonesShowOnAllMonitors = new BoolProperty();
|
||||
FancyzonesSpanZonesAcrossMonitors = new BoolProperty();
|
||||
FancyzonesZoneHighlightColor = new StringProperty(ConfigDefaults.DefaultFancyZonesZoneHighlightColor);
|
||||
FancyzonesHighlightOpacity = new IntProperty(50);
|
||||
FancyzonesEditorHotkey = new KeyboardKeysProperty(DefaultHotkeyValue);
|
||||
FancyzonesMakeDraggedWindowTransparent = new BoolProperty();
|
||||
FancyzonesExcludedApps = new StringProperty();
|
||||
FancyzonesInActiveColor = new StringProperty(ConfigDefaults.DefaultFancyZonesInActiveColor);
|
||||
FancyzonesBorderColor = new StringProperty(ConfigDefaults.DefaultFancyzonesBorderColor);
|
||||
}
|
||||
|
||||
[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_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("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_excluded_apps")]
|
||||
public StringProperty FancyzonesExcludedApps { get; set; }
|
||||
|
||||
[JsonPropertyName("fancyzones_zoneBorderColor")]
|
||||
public StringProperty FancyzonesBorderColor { get; set; }
|
||||
|
||||
[JsonPropertyName("fancyzones_zoneColor")]
|
||||
public StringProperty FancyzonesInActiveColor { get; set; }
|
||||
|
||||
// converts the current to a json string.
|
||||
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 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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 FancyZonesSettingsIPCMessage
|
||||
{
|
||||
[JsonPropertyName("powertoys")]
|
||||
public SndFancyZonesSettings Powertoys { get; set; }
|
||||
|
||||
public FancyZonesSettingsIPCMessage()
|
||||
{
|
||||
}
|
||||
|
||||
public FancyZonesSettingsIPCMessage(SndFancyZonesSettings settings)
|
||||
{
|
||||
Powertoys = settings;
|
||||
}
|
||||
|
||||
public string ToJsonString()
|
||||
{
|
||||
return JsonSerializer.Serialize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
// 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 packaged.
|
||||
[JsonPropertyName("packaged")]
|
||||
public bool Packaged { get; set; }
|
||||
|
||||
// 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()
|
||||
{
|
||||
Packaged = false;
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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,130 @@
|
||||
// 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;
|
||||
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 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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 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();
|
||||
|
||||
void SaveSettings(string jsonSettings, string powertoy = "", string fileName = "settings.json");
|
||||
|
||||
bool SettingsExists(string powertoy = "", string fileName = "settings.json");
|
||||
|
||||
void DeleteSettings(string powertoy = "");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
// 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 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(new ObservableCollection<ImageSize>()
|
||||
{
|
||||
new ImageSize(0, "Small", ResizeFit.Fit, 854, 480, ResizeUnit.Pixel),
|
||||
new ImageSize(1, "Medium", ResizeFit.Fit, 1366, 768, ResizeUnit.Pixel),
|
||||
new ImageSize(2, "Large", ResizeFit.Fit, 1920, 1080, ResizeUnit.Pixel),
|
||||
new ImageSize(3, "Phone", ResizeFit.Fit, 320, 568, ResizeUnit.Pixel),
|
||||
});
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
[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,
|
||||
}
|
||||
}
|
||||
@@ -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.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 = "ImageResizer";
|
||||
|
||||
[JsonPropertyName("properties")]
|
||||
public ImageResizerProperties Properties { get; set; }
|
||||
|
||||
public ImageResizerSettings()
|
||||
{
|
||||
Version = "1";
|
||||
Name = ModuleName;
|
||||
Properties = new ImageResizerProperties();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
244
src/core/Microsoft.PowerToys.Settings.UI.Library/ImageSize.cs
Normal file
244
src/core/Microsoft.PowerToys.Settings.UI.Library/ImageSize.cs
Normal file
@@ -0,0 +1,244 @@
|
||||
// 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)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 100;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool EnableEtraBoxes
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Unit == 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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; }
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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,57 @@
|
||||
<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>Microsoft.PowerToys.Settings.UI.Lib</AssemblyName>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
</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.Text.Json" Version="4.7.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\interop.vcxproj" />
|
||||
<ProjectReference Include="..\..\common\ManagedTelemetry\Telemetry\Telemetry.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -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,61 @@
|
||||
// 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 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("disable_drive_detection_warning")]
|
||||
public bool DisableDriveDetectionWarning { get; set; }
|
||||
|
||||
[JsonPropertyName("clear_input_on_launch")]
|
||||
public bool ClearInputOnLaunch { 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;
|
||||
DisableDriveDetectionWarning = false;
|
||||
ClearInputOnLaunch = false;
|
||||
MaximumNumberOfResults = 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
// 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 PowerLauncherSettings : BasePTModuleSettings, ISettingsConfig
|
||||
{
|
||||
public const string ModuleName = "PowerToys Run";
|
||||
|
||||
[JsonPropertyName("properties")]
|
||||
public PowerLauncherProperties Properties { get; set; }
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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,69 @@
|
||||
// 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;
|
||||
}
|
||||
|
||||
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 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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 PowerRenameProperties
|
||||
{
|
||||
public PowerRenameProperties()
|
||||
{
|
||||
PersistState = new BoolProperty();
|
||||
MRUEnabled = new BoolProperty();
|
||||
MaxMRUSize = new IntProperty();
|
||||
ShowIcon = new BoolProperty();
|
||||
ExtendedContextMenuOnly = 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; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
// 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;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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.GetSettings<T>(settingsItem.GetModuleName());
|
||||
}
|
||||
|
||||
return settingsConfig;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != null)
|
||||
{
|
||||
settingsConfig = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
// 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.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 IIOProvider _ioProvider;
|
||||
|
||||
public SettingsUtils(IIOProvider ioProvider)
|
||||
{
|
||||
_ioProvider = ioProvider ?? throw new ArgumentNullException(nameof(ioProvider));
|
||||
}
|
||||
|
||||
private bool SettingsFolderExists(string powertoy)
|
||||
{
|
||||
return _ioProvider.DirectoryExists(System.IO.Path.Combine(LocalApplicationDataFolder(), $"Microsoft\\PowerToys\\{powertoy}"));
|
||||
}
|
||||
|
||||
private void CreateSettingsFolder(string powertoy)
|
||||
{
|
||||
_ioProvider.CreateDirectory(System.IO.Path.Combine(LocalApplicationDataFolder(), $"Microsoft\\PowerToys\\{powertoy}"));
|
||||
}
|
||||
|
||||
public void DeleteSettings(string powertoy = "")
|
||||
{
|
||||
_ioProvider.DeleteDirectory(System.IO.Path.Combine(LocalApplicationDataFolder(), $"Microsoft\\PowerToys\\{powertoy}"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get path to the json settings file.
|
||||
/// </summary>
|
||||
/// <returns>string path.</returns>
|
||||
public static string GetSettingsPath(string powertoy, string fileName = DefaultFileName)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(powertoy))
|
||||
{
|
||||
return System.IO.Path.Combine(
|
||||
LocalApplicationDataFolder(),
|
||||
$"Microsoft\\PowerToys\\{fileName}");
|
||||
}
|
||||
|
||||
return System.IO.Path.Combine(
|
||||
LocalApplicationDataFolder(),
|
||||
$"Microsoft\\PowerToys\\{powertoy}\\{fileName}");
|
||||
}
|
||||
|
||||
public bool SettingsExists(string powertoy = DefaultModuleName, string fileName = DefaultFileName)
|
||||
{
|
||||
return _ioProvider.FileExists(GetSettingsPath(powertoy, fileName));
|
||||
}
|
||||
|
||||
/// <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 GetSettings<T>(string powertoy = DefaultModuleName, string fileName = DefaultFileName)
|
||||
where T : ISettingsConfig, new()
|
||||
{
|
||||
if (SettingsExists(powertoy, fileName))
|
||||
{
|
||||
// Given the file already exists, to deserialize the file and read it's 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;
|
||||
}
|
||||
else
|
||||
{
|
||||
// If the settings file does not exist, 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 = _ioProvider.ReadAllText(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 (!SettingsFolderExists(powertoy))
|
||||
{
|
||||
CreateSettingsFolder(powertoy);
|
||||
}
|
||||
|
||||
_ioProvider.WriteAllText(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
|
||||
}
|
||||
}
|
||||
|
||||
private static string LocalApplicationDataFolder()
|
||||
{
|
||||
return Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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.Text.Json.Serialization;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public class ShortcutGuideProperties
|
||||
{
|
||||
public ShortcutGuideProperties()
|
||||
{
|
||||
OverlayOpacity = new IntProperty(90);
|
||||
PressTime = new IntProperty(900);
|
||||
Theme = new StringProperty("system");
|
||||
}
|
||||
|
||||
[JsonPropertyName("overlay_opacity")]
|
||||
public IntProperty OverlayOpacity { get; set; }
|
||||
|
||||
[JsonPropertyName("press_time")]
|
||||
public IntProperty PressTime { get; set; }
|
||||
|
||||
[JsonPropertyName("theme")]
|
||||
public StringProperty Theme { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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.Text.Json;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public class SndFancyZonesSettings
|
||||
{
|
||||
public FancyZonesSettings FancyZones { get; set; }
|
||||
|
||||
public SndFancyZonesSettings()
|
||||
{
|
||||
}
|
||||
|
||||
public SndFancyZonesSettings(FancyZonesSettings settings)
|
||||
{
|
||||
FancyZones = 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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 setnt 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 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,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 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
// 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.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 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 FileSystemWatcher GetFileWatcher(string moduleName, string fileName, Action onChangedCallback)
|
||||
{
|
||||
var path = Path.Combine(LocalApplicationDataFolder(), $"Microsoft\\PowerToys\\{moduleName}");
|
||||
|
||||
if (!Directory.Exists(path))
|
||||
{
|
||||
Directory.CreateDirectory(path);
|
||||
}
|
||||
|
||||
var watcher = new FileSystemWatcher
|
||||
{
|
||||
Path = path,
|
||||
Filter = fileName,
|
||||
NotifyFilter = NotifyFilters.LastWrite,
|
||||
EnableRaisingEvents = true,
|
||||
};
|
||||
|
||||
watcher.Changed += (o, e) => onChangedCallback();
|
||||
|
||||
return watcher;
|
||||
}
|
||||
|
||||
private static string LocalApplicationDataFolder()
|
||||
{
|
||||
return Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
// 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;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library.Utilities
|
||||
{
|
||||
public static class Logger
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
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, 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");
|
||||
}
|
||||
|
||||
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,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;
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -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.IO;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library.Utilities
|
||||
{
|
||||
public class SystemIOProvider : IIOProvider
|
||||
{
|
||||
public bool CreateDirectory(string path)
|
||||
{
|
||||
var directioryInfo = Directory.CreateDirectory(path);
|
||||
return directioryInfo != 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,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.Globalization;
|
||||
using System.Text.Json;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
|
||||
{
|
||||
public class ColorPickerViewModel : Observable
|
||||
{
|
||||
private GeneralSettings GeneralSettingsConfig { get; set; }
|
||||
|
||||
private readonly ISettingsUtils _settingsUtils;
|
||||
|
||||
private ColorPickerSettings _colorPickerSettings;
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
GeneralSettingsConfig = settingsRepository.SettingsConfig;
|
||||
|
||||
_settingsUtils = settingsUtils ?? throw new ArgumentNullException(nameof(settingsUtils));
|
||||
if (_settingsUtils.SettingsExists(ColorPickerSettings.ModuleName))
|
||||
{
|
||||
_colorPickerSettings = _settingsUtils.GetSettings<ColorPickerSettings>(ColorPickerSettings.ModuleName);
|
||||
}
|
||||
else
|
||||
{
|
||||
_colorPickerSettings = new ColorPickerSettings();
|
||||
}
|
||||
|
||||
_isEnabled = GeneralSettingsConfig.Enabled.ColorPicker;
|
||||
|
||||
// set the callback functions value to hangle outgoing IPC message.
|
||||
SendConfigMSG = ipcMSGCallBackFunc;
|
||||
}
|
||||
|
||||
public bool IsEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
return _isEnabled;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (_isEnabled != value)
|
||||
{
|
||||
_isEnabled = value;
|
||||
OnPropertyChanged(nameof(IsEnabled));
|
||||
|
||||
// Set the status of ColorPicker in the general settings
|
||||
GeneralSettingsConfig.Enabled.ColorPicker = value;
|
||||
OutGoingGeneralSettings outgoing = new OutGoingGeneralSettings(GeneralSettingsConfig);
|
||||
|
||||
SendConfigMSG(outgoing.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool ChangeCursor
|
||||
{
|
||||
get
|
||||
{
|
||||
return _colorPickerSettings.Properties.ChangeCursor;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (_colorPickerSettings.Properties.ChangeCursor != value)
|
||||
{
|
||||
_colorPickerSettings.Properties.ChangeCursor = value;
|
||||
OnPropertyChanged(nameof(ChangeCursor));
|
||||
NotifySettingsChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public HotkeySettings ActivationShortcut
|
||||
{
|
||||
get
|
||||
{
|
||||
return _colorPickerSettings.Properties.ActivationShortcut;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (_colorPickerSettings.Properties.ActivationShortcut != value)
|
||||
{
|
||||
_colorPickerSettings.Properties.ActivationShortcut = value;
|
||||
OnPropertyChanged(nameof(ActivationShortcut));
|
||||
NotifySettingsChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int CopiedColorRepresentationIndex
|
||||
{
|
||||
get
|
||||
{
|
||||
return (int)_colorPickerSettings.Properties.CopiedColorRepresentation;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (_colorPickerSettings.Properties.CopiedColorRepresentation != (ColorRepresentationType)value)
|
||||
{
|
||||
_colorPickerSettings.Properties.CopiedColorRepresentation = (ColorRepresentationType)value;
|
||||
OnPropertyChanged(nameof(CopiedColorRepresentationIndex));
|
||||
NotifySettingsChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void NotifySettingsChanged()
|
||||
{
|
||||
// Using InvariantCulture as this is an IPC message
|
||||
SendConfigMSG(
|
||||
string.Format(
|
||||
CultureInfo.InvariantCulture,
|
||||
"{{ \"powertoys\": {{ \"{0}\": {1} }} }}",
|
||||
ColorPickerSettings.ModuleName,
|
||||
JsonSerializer.Serialize(_colorPickerSettings)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels.Commands
|
||||
{
|
||||
public class ButtonClickCommand : ICommand
|
||||
{
|
||||
private readonly Action _execute;
|
||||
|
||||
public ButtonClickCommand(Action execute)
|
||||
{
|
||||
_execute = execute;
|
||||
}
|
||||
|
||||
// Occurs when changes occur that affect whether or not the command should execute.
|
||||
public event EventHandler CanExecuteChanged;
|
||||
|
||||
// Defines the method that determines whether the command can execute in its current state.
|
||||
public bool CanExecute(object parameter)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// Defines the method to be called when the command is invoked.
|
||||
public void Execute(object parameter)
|
||||
{
|
||||
_execute();
|
||||
}
|
||||
|
||||
public void OnCanExecuteChanged() => CanExecuteChanged?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels.Commands
|
||||
{
|
||||
public class RelayCommand : ICommand
|
||||
{
|
||||
private readonly Action _execute;
|
||||
private readonly Func<bool> _canExecute;
|
||||
|
||||
public event EventHandler CanExecuteChanged;
|
||||
|
||||
public RelayCommand(Action execute)
|
||||
: this(execute, null)
|
||||
{
|
||||
}
|
||||
|
||||
public RelayCommand(Action execute, Func<bool> canExecute)
|
||||
{
|
||||
_execute = execute ?? throw new ArgumentNullException(nameof(execute));
|
||||
_canExecute = canExecute;
|
||||
}
|
||||
|
||||
public bool CanExecute(object parameter) => _canExecute == null || _canExecute();
|
||||
|
||||
public void Execute(object parameter) => _execute();
|
||||
|
||||
public void OnCanExecuteChanged() => CanExecuteChanged?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels.Commands
|
||||
{
|
||||
public class RelayCommand<T> : ICommand
|
||||
{
|
||||
private readonly Action<T> execute;
|
||||
|
||||
private readonly Func<T, bool> canExecute;
|
||||
|
||||
public event EventHandler CanExecuteChanged;
|
||||
|
||||
public RelayCommand(Action<T> execute)
|
||||
: this(execute, null)
|
||||
{
|
||||
}
|
||||
|
||||
public RelayCommand(Action<T> execute, Func<T, bool> canExecute)
|
||||
{
|
||||
this.execute = execute ?? throw new ArgumentNullException(nameof(execute));
|
||||
this.canExecute = canExecute;
|
||||
}
|
||||
|
||||
public bool CanExecute(object parameter) => canExecute == null || canExecute((T)parameter);
|
||||
|
||||
public void Execute(object parameter) => execute((T)parameter);
|
||||
|
||||
public void OnCanExecuteChanged() => CanExecuteChanged?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,565 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Globalization;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.ViewModels.Commands;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
|
||||
{
|
||||
public class FancyZonesViewModel : Observable
|
||||
{
|
||||
private GeneralSettings GeneralSettingsConfig { get; set; }
|
||||
|
||||
private const string ModuleName = FancyZonesSettings.ModuleName;
|
||||
|
||||
public ButtonClickCommand LaunchEditorEventHandler { get; set; }
|
||||
|
||||
private FancyZonesSettings Settings { get; set; }
|
||||
|
||||
private Func<string, int> SendConfigMSG { get; }
|
||||
|
||||
private string settingsConfigFileFolder = string.Empty;
|
||||
|
||||
public FancyZonesViewModel(ISettingsRepository<GeneralSettings> settingsRepository, ISettingsRepository<FancyZonesSettings> moduleSettingsRepository, Func<string, int> ipcMSGCallBackFunc, string configFileSubfolder = "")
|
||||
{
|
||||
// To obtain the general settings configurations of PowerToys Settings.
|
||||
if (settingsRepository == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(settingsRepository));
|
||||
}
|
||||
|
||||
GeneralSettingsConfig = settingsRepository.SettingsConfig;
|
||||
settingsConfigFileFolder = configFileSubfolder;
|
||||
|
||||
// To obtain the settings configurations of Fancy zones.
|
||||
if (moduleSettingsRepository == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(moduleSettingsRepository));
|
||||
}
|
||||
|
||||
Settings = moduleSettingsRepository.SettingsConfig;
|
||||
|
||||
LaunchEditorEventHandler = new ButtonClickCommand(LaunchEditor);
|
||||
|
||||
_shiftDrag = Settings.Properties.FancyzonesShiftDrag.Value;
|
||||
_mouseSwitch = Settings.Properties.FancyzonesMouseSwitch.Value;
|
||||
_overrideSnapHotkeys = Settings.Properties.FancyzonesOverrideSnapHotkeys.Value;
|
||||
_moveWindowsAcrossMonitors = Settings.Properties.FancyzonesMoveWindowsAcrossMonitors.Value;
|
||||
_moveWindowsBasedOnPosition = Settings.Properties.FancyzonesMoveWindowsBasedOnPosition.Value;
|
||||
_displayChangemoveWindows = Settings.Properties.FancyzonesDisplayChangeMoveWindows.Value;
|
||||
_zoneSetChangeMoveWindows = Settings.Properties.FancyzonesZoneSetChangeMoveWindows.Value;
|
||||
_appLastZoneMoveWindows = Settings.Properties.FancyzonesAppLastZoneMoveWindows.Value;
|
||||
_openWindowOnActiveMonitor = Settings.Properties.FancyzonesOpenWindowOnActiveMonitor.Value;
|
||||
_restoreSize = Settings.Properties.FancyzonesRestoreSize.Value;
|
||||
_useCursorPosEditorStartupScreen = Settings.Properties.UseCursorposEditorStartupscreen.Value;
|
||||
_showOnAllMonitors = Settings.Properties.FancyzonesShowOnAllMonitors.Value;
|
||||
_spanZonesAcrossMonitors = Settings.Properties.FancyzonesSpanZonesAcrossMonitors.Value;
|
||||
_makeDraggedWindowTransparent = Settings.Properties.FancyzonesMakeDraggedWindowTransparent.Value;
|
||||
_highlightOpacity = Settings.Properties.FancyzonesHighlightOpacity.Value;
|
||||
_excludedApps = Settings.Properties.FancyzonesExcludedApps.Value;
|
||||
EditorHotkey = Settings.Properties.FancyzonesEditorHotkey.Value;
|
||||
|
||||
// set the callback functions value to hangle outgoing IPC message.
|
||||
SendConfigMSG = ipcMSGCallBackFunc;
|
||||
|
||||
string inactiveColor = Settings.Properties.FancyzonesInActiveColor.Value;
|
||||
_zoneInActiveColor = !string.IsNullOrEmpty(inactiveColor) ? inactiveColor : "#F5FCFF";
|
||||
|
||||
string borderColor = Settings.Properties.FancyzonesBorderColor.Value;
|
||||
_zoneBorderColor = !string.IsNullOrEmpty(borderColor) ? borderColor : "#FFFFFF";
|
||||
|
||||
string highlightColor = Settings.Properties.FancyzonesZoneHighlightColor.Value;
|
||||
_zoneHighlightColor = !string.IsNullOrEmpty(highlightColor) ? highlightColor : "#0078D7";
|
||||
|
||||
_isEnabled = GeneralSettingsConfig.Enabled.FancyZones;
|
||||
}
|
||||
|
||||
private bool _isEnabled;
|
||||
private bool _shiftDrag;
|
||||
private bool _mouseSwitch;
|
||||
private bool _overrideSnapHotkeys;
|
||||
private bool _moveWindowsAcrossMonitors;
|
||||
private bool _moveWindowsBasedOnPosition;
|
||||
private bool _displayChangemoveWindows;
|
||||
private bool _zoneSetChangeMoveWindows;
|
||||
private bool _appLastZoneMoveWindows;
|
||||
private bool _openWindowOnActiveMonitor;
|
||||
private bool _spanZonesAcrossMonitors;
|
||||
private bool _restoreSize;
|
||||
private bool _useCursorPosEditorStartupScreen;
|
||||
private bool _showOnAllMonitors;
|
||||
private bool _makeDraggedWindowTransparent;
|
||||
|
||||
private int _highlightOpacity;
|
||||
private string _excludedApps;
|
||||
private HotkeySettings _editorHotkey;
|
||||
private string _zoneInActiveColor;
|
||||
private string _zoneBorderColor;
|
||||
private string _zoneHighlightColor;
|
||||
|
||||
public bool IsEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
return _isEnabled;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _isEnabled)
|
||||
{
|
||||
_isEnabled = value;
|
||||
|
||||
// Set the status of FancyZones in the general settings configuration
|
||||
GeneralSettingsConfig.Enabled.FancyZones = value;
|
||||
OutGoingGeneralSettings snd = new OutGoingGeneralSettings(GeneralSettingsConfig);
|
||||
|
||||
SendConfigMSG(snd.ToString());
|
||||
OnPropertyChanged(nameof(IsEnabled));
|
||||
OnPropertyChanged(nameof(SnapHotkeysCategoryEnabled));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool SnapHotkeysCategoryEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
return _isEnabled && _overrideSnapHotkeys;
|
||||
}
|
||||
}
|
||||
|
||||
public bool ShiftDrag
|
||||
{
|
||||
get
|
||||
{
|
||||
return _shiftDrag;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _shiftDrag)
|
||||
{
|
||||
_shiftDrag = value;
|
||||
Settings.Properties.FancyzonesShiftDrag.Value = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool MouseSwitch
|
||||
{
|
||||
get
|
||||
{
|
||||
return _mouseSwitch;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _mouseSwitch)
|
||||
{
|
||||
_mouseSwitch = value;
|
||||
Settings.Properties.FancyzonesMouseSwitch.Value = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string GetSettingsSubPath()
|
||||
{
|
||||
return settingsConfigFileFolder + "\\" + ModuleName;
|
||||
}
|
||||
|
||||
public bool OverrideSnapHotkeys
|
||||
{
|
||||
get
|
||||
{
|
||||
return _overrideSnapHotkeys;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _overrideSnapHotkeys)
|
||||
{
|
||||
_overrideSnapHotkeys = value;
|
||||
Settings.Properties.FancyzonesOverrideSnapHotkeys.Value = value;
|
||||
NotifyPropertyChanged();
|
||||
OnPropertyChanged(nameof(SnapHotkeysCategoryEnabled));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool MoveWindowsAcrossMonitors
|
||||
{
|
||||
get
|
||||
{
|
||||
return _moveWindowsAcrossMonitors;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _moveWindowsAcrossMonitors)
|
||||
{
|
||||
_moveWindowsAcrossMonitors = value;
|
||||
Settings.Properties.FancyzonesMoveWindowsAcrossMonitors.Value = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool MoveWindowsBasedOnPosition
|
||||
{
|
||||
get
|
||||
{
|
||||
return _moveWindowsBasedOnPosition;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _moveWindowsBasedOnPosition)
|
||||
{
|
||||
_moveWindowsBasedOnPosition = value;
|
||||
Settings.Properties.FancyzonesMoveWindowsBasedOnPosition.Value = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool DisplayChangeMoveWindows
|
||||
{
|
||||
get
|
||||
{
|
||||
return _displayChangemoveWindows;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _displayChangemoveWindows)
|
||||
{
|
||||
_displayChangemoveWindows = value;
|
||||
Settings.Properties.FancyzonesDisplayChangeMoveWindows.Value = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool ZoneSetChangeMoveWindows
|
||||
{
|
||||
get
|
||||
{
|
||||
return _zoneSetChangeMoveWindows;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _zoneSetChangeMoveWindows)
|
||||
{
|
||||
_zoneSetChangeMoveWindows = value;
|
||||
Settings.Properties.FancyzonesZoneSetChangeMoveWindows.Value = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool AppLastZoneMoveWindows
|
||||
{
|
||||
get
|
||||
{
|
||||
return _appLastZoneMoveWindows;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _appLastZoneMoveWindows)
|
||||
{
|
||||
_appLastZoneMoveWindows = value;
|
||||
Settings.Properties.FancyzonesAppLastZoneMoveWindows.Value = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool OpenWindowOnActiveMonitor
|
||||
{
|
||||
get
|
||||
{
|
||||
return _openWindowOnActiveMonitor;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _openWindowOnActiveMonitor)
|
||||
{
|
||||
_openWindowOnActiveMonitor = value;
|
||||
Settings.Properties.FancyzonesOpenWindowOnActiveMonitor.Value = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool RestoreSize
|
||||
{
|
||||
get
|
||||
{
|
||||
return _restoreSize;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _restoreSize)
|
||||
{
|
||||
_restoreSize = value;
|
||||
Settings.Properties.FancyzonesRestoreSize.Value = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool UseCursorPosEditorStartupScreen
|
||||
{
|
||||
get
|
||||
{
|
||||
return _useCursorPosEditorStartupScreen;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _useCursorPosEditorStartupScreen)
|
||||
{
|
||||
_useCursorPosEditorStartupScreen = value;
|
||||
Settings.Properties.UseCursorposEditorStartupscreen.Value = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool ShowOnAllMonitors
|
||||
{
|
||||
get
|
||||
{
|
||||
return _showOnAllMonitors;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _showOnAllMonitors)
|
||||
{
|
||||
_showOnAllMonitors = value;
|
||||
Settings.Properties.FancyzonesShowOnAllMonitors.Value = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool SpanZonesAcrossMonitors
|
||||
{
|
||||
get
|
||||
{
|
||||
return _spanZonesAcrossMonitors;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _spanZonesAcrossMonitors)
|
||||
{
|
||||
_spanZonesAcrossMonitors = value;
|
||||
Settings.Properties.FancyzonesSpanZonesAcrossMonitors.Value = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool MakeDraggedWindowsTransparent
|
||||
{
|
||||
get
|
||||
{
|
||||
return _makeDraggedWindowTransparent;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _makeDraggedWindowTransparent)
|
||||
{
|
||||
_makeDraggedWindowTransparent = value;
|
||||
Settings.Properties.FancyzonesMakeDraggedWindowTransparent.Value = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// For the following setters we use OrdinalIgnoreCase string comparison since
|
||||
// we expect value to be a hex code.
|
||||
public string ZoneHighlightColor
|
||||
{
|
||||
get
|
||||
{
|
||||
return _zoneHighlightColor;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
// The fallback value is based on ToRGBHex's behavior, which returns
|
||||
// #FFFFFF if any exceptions are encountered, e.g. from passing in a null value.
|
||||
// This extra handling is added here to deal with FxCop warnings.
|
||||
value = (value != null) ? ToRGBHex(value) : "#FFFFFF";
|
||||
if (!value.Equals(_zoneHighlightColor, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
_zoneHighlightColor = value;
|
||||
Settings.Properties.FancyzonesZoneHighlightColor.Value = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string ZoneBorderColor
|
||||
{
|
||||
get
|
||||
{
|
||||
return _zoneBorderColor;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
// The fallback value is based on ToRGBHex's behavior, which returns
|
||||
// #FFFFFF if any exceptions are encountered, e.g. from passing in a null value.
|
||||
// This extra handling is added here to deal with FxCop warnings.
|
||||
value = (value != null) ? ToRGBHex(value) : "#FFFFFF";
|
||||
if (!value.Equals(_zoneBorderColor, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
_zoneBorderColor = value;
|
||||
Settings.Properties.FancyzonesBorderColor.Value = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string ZoneInActiveColor
|
||||
{
|
||||
get
|
||||
{
|
||||
return _zoneInActiveColor;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
// The fallback value is based on ToRGBHex's behavior, which returns
|
||||
// #FFFFFF if any exceptions are encountered, e.g. from passing in a null value.
|
||||
// This extra handling is added here to deal with FxCop warnings.
|
||||
value = (value != null) ? ToRGBHex(value) : "#FFFFFF";
|
||||
if (!value.Equals(_zoneInActiveColor, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
_zoneInActiveColor = value;
|
||||
Settings.Properties.FancyzonesInActiveColor.Value = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int HighlightOpacity
|
||||
{
|
||||
get
|
||||
{
|
||||
return _highlightOpacity;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _highlightOpacity)
|
||||
{
|
||||
_highlightOpacity = value;
|
||||
Settings.Properties.FancyzonesHighlightOpacity.Value = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public HotkeySettings EditorHotkey
|
||||
{
|
||||
get
|
||||
{
|
||||
return _editorHotkey;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _editorHotkey)
|
||||
{
|
||||
if (value == null || value.IsEmpty())
|
||||
{
|
||||
_editorHotkey = FZConfigProperties.DefaultHotkeyValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
_editorHotkey = value;
|
||||
}
|
||||
|
||||
Settings.Properties.FancyzonesEditorHotkey.Value = _editorHotkey;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string ExcludedApps
|
||||
{
|
||||
get
|
||||
{
|
||||
return _excludedApps;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _excludedApps)
|
||||
{
|
||||
_excludedApps = value;
|
||||
Settings.Properties.FancyzonesExcludedApps.Value = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void LaunchEditor()
|
||||
{
|
||||
// send message to launch the zones editor;
|
||||
SendConfigMSG("{\"action\":{\"FancyZones\":{\"action_name\":\"ToggledFZEditor\", \"value\":\"\"}}}");
|
||||
}
|
||||
|
||||
public void NotifyPropertyChanged([CallerMemberName] string propertyName = null)
|
||||
{
|
||||
OnPropertyChanged(propertyName);
|
||||
if (SendConfigMSG != null)
|
||||
{
|
||||
SndFancyZonesSettings outsettings = new SndFancyZonesSettings(Settings);
|
||||
SndModuleSettings<SndFancyZonesSettings> ipcMessage = new SndModuleSettings<SndFancyZonesSettings>(outsettings);
|
||||
SendConfigMSG(ipcMessage.ToJsonString());
|
||||
}
|
||||
}
|
||||
|
||||
private static string ToRGBHex(string color)
|
||||
{
|
||||
// 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";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,384 @@
|
||||
// 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.Runtime.CompilerServices;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.ViewModels.Commands;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
|
||||
{
|
||||
public class GeneralViewModel : Observable
|
||||
{
|
||||
private GeneralSettings GeneralSettingsConfig { get; set; }
|
||||
|
||||
public ButtonClickCommand CheckForUpdatesEventHandler { get; set; }
|
||||
|
||||
public ButtonClickCommand RestartElevatedButtonEventHandler { get; set; }
|
||||
|
||||
public Func<string, int> UpdateUIThemeCallBack { get; }
|
||||
|
||||
public Func<string, int> SendConfigMSG { get; }
|
||||
|
||||
public Func<string, int> SendRestartAsAdminConfigMSG { get; }
|
||||
|
||||
public Func<string, int> SendCheckForUpdatesConfigMSG { get; }
|
||||
|
||||
public string RunningAsUserDefaultText { get; set; }
|
||||
|
||||
public string RunningAsAdminDefaultText { get; set; }
|
||||
|
||||
private string _settingsConfigFileFolder = string.Empty;
|
||||
|
||||
public GeneralViewModel(ISettingsRepository<GeneralSettings> settingsRepository, string runAsAdminText, string runAsUserText, bool isElevated, bool isAdmin, Func<string, int> updateTheme, Func<string, int> ipcMSGCallBackFunc, Func<string, int> ipcMSGRestartAsAdminMSGCallBackFunc, Func<string, int> ipcMSGCheckForUpdatesCallBackFunc, string configFileSubfolder = "")
|
||||
{
|
||||
CheckForUpdatesEventHandler = new ButtonClickCommand(CheckForUpdatesClick);
|
||||
RestartElevatedButtonEventHandler = new ButtonClickCommand(RestartElevated);
|
||||
|
||||
// To obtain the general settings configuration of PowerToys if it exists, else to create a new file and return the default configurations.
|
||||
if (settingsRepository == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(settingsRepository));
|
||||
}
|
||||
|
||||
GeneralSettingsConfig = settingsRepository.SettingsConfig;
|
||||
|
||||
// set the callback functions value to hangle outgoing IPC message.
|
||||
SendConfigMSG = ipcMSGCallBackFunc;
|
||||
SendCheckForUpdatesConfigMSG = ipcMSGCheckForUpdatesCallBackFunc;
|
||||
SendRestartAsAdminConfigMSG = ipcMSGRestartAsAdminMSGCallBackFunc;
|
||||
|
||||
// set the callback function value to update the UI theme.
|
||||
UpdateUIThemeCallBack = updateTheme;
|
||||
|
||||
UpdateUIThemeCallBack(GeneralSettingsConfig.Theme);
|
||||
|
||||
// Update Settings file folder:
|
||||
_settingsConfigFileFolder = configFileSubfolder;
|
||||
|
||||
// Using Invariant here as these are internal strings and fxcop
|
||||
// expects strings to be normalized to uppercase. While the theme names
|
||||
// are represented in lowercase everywhere else, we'll use uppercase
|
||||
// normalization for switch statements
|
||||
switch (GeneralSettingsConfig.Theme.ToUpperInvariant())
|
||||
{
|
||||
case "LIGHT":
|
||||
_isLightThemeRadioButtonChecked = true;
|
||||
break;
|
||||
case "DARK":
|
||||
_isDarkThemeRadioButtonChecked = true;
|
||||
break;
|
||||
case "SYSTEM":
|
||||
_isSystemThemeRadioButtonChecked = true;
|
||||
break;
|
||||
}
|
||||
|
||||
_startup = GeneralSettingsConfig.Startup;
|
||||
_autoDownloadUpdates = GeneralSettingsConfig.AutoDownloadUpdates;
|
||||
_isElevated = isElevated;
|
||||
_runElevated = GeneralSettingsConfig.RunElevated;
|
||||
|
||||
RunningAsUserDefaultText = runAsUserText;
|
||||
RunningAsAdminDefaultText = runAsAdminText;
|
||||
|
||||
_isAdmin = isAdmin;
|
||||
}
|
||||
|
||||
private bool _packaged;
|
||||
private bool _startup;
|
||||
private bool _isElevated;
|
||||
private bool _runElevated;
|
||||
private bool _isAdmin;
|
||||
private bool _isDarkThemeRadioButtonChecked;
|
||||
private bool _isLightThemeRadioButtonChecked;
|
||||
private bool _isSystemThemeRadioButtonChecked;
|
||||
private bool _autoDownloadUpdates;
|
||||
|
||||
private string _latestAvailableVersion = string.Empty;
|
||||
|
||||
// Gets or sets a value indicating whether packaged.
|
||||
public bool Packaged
|
||||
{
|
||||
get
|
||||
{
|
||||
return _packaged;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (_packaged != value)
|
||||
{
|
||||
_packaged = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Gets or sets a value indicating whether run powertoys on start-up.
|
||||
public bool Startup
|
||||
{
|
||||
get
|
||||
{
|
||||
return _startup;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (_startup != value)
|
||||
{
|
||||
_startup = value;
|
||||
GeneralSettingsConfig.Startup = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string RunningAsText
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!IsElevated)
|
||||
{
|
||||
return RunningAsUserDefaultText;
|
||||
}
|
||||
else
|
||||
{
|
||||
return RunningAsAdminDefaultText;
|
||||
}
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
OnPropertyChanged("RunningAsAdminText");
|
||||
}
|
||||
}
|
||||
|
||||
// Gets or sets a value indicating whether the powertoy elevated.
|
||||
public bool IsElevated
|
||||
{
|
||||
get
|
||||
{
|
||||
return _isElevated;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (_isElevated != value)
|
||||
{
|
||||
_isElevated = value;
|
||||
OnPropertyChanged(nameof(IsElevated));
|
||||
OnPropertyChanged(nameof(IsAdminButtonEnabled));
|
||||
OnPropertyChanged("RunningAsAdminText");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsAdminButtonEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
return !IsElevated;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
OnPropertyChanged(nameof(IsAdminButtonEnabled));
|
||||
}
|
||||
}
|
||||
|
||||
// Gets or sets a value indicating whether powertoys should run elevated.
|
||||
public bool RunElevated
|
||||
{
|
||||
get
|
||||
{
|
||||
return _runElevated;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (_runElevated != value)
|
||||
{
|
||||
_runElevated = value;
|
||||
GeneralSettingsConfig.RunElevated = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Gets a value indicating whether the user is part of administrators group.
|
||||
public bool IsAdmin
|
||||
{
|
||||
get
|
||||
{
|
||||
return _isAdmin;
|
||||
}
|
||||
}
|
||||
|
||||
public bool AutoDownloadUpdates
|
||||
{
|
||||
get
|
||||
{
|
||||
return _autoDownloadUpdates;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (_autoDownloadUpdates != value)
|
||||
{
|
||||
_autoDownloadUpdates = value;
|
||||
GeneralSettingsConfig.AutoDownloadUpdates = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "This may throw if the XAML page is not initialized in tests (https://github.com/microsoft/PowerToys/pull/2676)")]
|
||||
public bool IsDarkThemeRadioButtonChecked
|
||||
{
|
||||
get
|
||||
{
|
||||
return _isDarkThemeRadioButtonChecked;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value == true)
|
||||
{
|
||||
GeneralSettingsConfig.Theme = "dark";
|
||||
_isDarkThemeRadioButtonChecked = value;
|
||||
try
|
||||
{
|
||||
UpdateUIThemeCallBack(GeneralSettingsConfig.Theme);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.LogError("Exception encountered when changing Settings theme", e);
|
||||
}
|
||||
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "This may throw if the XAML page is not initialized in tests (https://github.com/microsoft/PowerToys/pull/2676)")]
|
||||
public bool IsLightThemeRadioButtonChecked
|
||||
{
|
||||
get
|
||||
{
|
||||
return _isLightThemeRadioButtonChecked;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value == true)
|
||||
{
|
||||
GeneralSettingsConfig.Theme = "light";
|
||||
_isLightThemeRadioButtonChecked = value;
|
||||
try
|
||||
{
|
||||
UpdateUIThemeCallBack(GeneralSettingsConfig.Theme);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.LogError("Exception encountered when changing Settings theme", e);
|
||||
}
|
||||
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "This may throw if the XAML page is not initialized in tests (https://github.com/microsoft/PowerToys/pull/2676)")]
|
||||
public bool IsSystemThemeRadioButtonChecked
|
||||
{
|
||||
get
|
||||
{
|
||||
return _isSystemThemeRadioButtonChecked;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value == true)
|
||||
{
|
||||
GeneralSettingsConfig.Theme = "system";
|
||||
_isSystemThemeRadioButtonChecked = value;
|
||||
try
|
||||
{
|
||||
UpdateUIThemeCallBack(GeneralSettingsConfig.Theme);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.LogError("Exception encountered when changing Settings theme", e);
|
||||
}
|
||||
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// FxCop suggests marking this member static, but it is accessed through
|
||||
// an instance in autogenerated files (GeneralPage.g.cs) and will break
|
||||
// the file if modified
|
||||
#pragma warning disable CA1822 // Mark members as static
|
||||
public string PowerToysVersion
|
||||
#pragma warning restore CA1822 // Mark members as static
|
||||
{
|
||||
get
|
||||
{
|
||||
return Helper.GetProductVersion();
|
||||
}
|
||||
}
|
||||
|
||||
// Temp string. Appears when a user clicks "Check for updates" button and shows latest version available on the Github.
|
||||
public string LatestAvailableVersion
|
||||
{
|
||||
get
|
||||
{
|
||||
return _latestAvailableVersion;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (_latestAvailableVersion != value)
|
||||
{
|
||||
_latestAvailableVersion = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void NotifyPropertyChanged([CallerMemberName] string propertyName = null)
|
||||
{
|
||||
// Notify UI of property change
|
||||
OnPropertyChanged(propertyName);
|
||||
OutGoingGeneralSettings outsettings = new OutGoingGeneralSettings(GeneralSettingsConfig);
|
||||
|
||||
SendConfigMSG(outsettings.ToString());
|
||||
}
|
||||
|
||||
// callback function to launch the URL to check for updates.
|
||||
private void CheckForUpdatesClick()
|
||||
{
|
||||
GeneralSettingsConfig.CustomActionName = "check_for_updates";
|
||||
|
||||
OutGoingGeneralSettings outsettings = new OutGoingGeneralSettings(GeneralSettingsConfig);
|
||||
GeneralSettingsCustomAction customaction = new GeneralSettingsCustomAction(outsettings);
|
||||
|
||||
SendCheckForUpdatesConfigMSG(customaction.ToString());
|
||||
}
|
||||
|
||||
public void RestartElevated()
|
||||
{
|
||||
GeneralSettingsConfig.CustomActionName = "restart_elevation";
|
||||
|
||||
OutGoingGeneralSettings outsettings = new OutGoingGeneralSettings(GeneralSettingsConfig);
|
||||
GeneralSettingsCustomAction customaction = new GeneralSettingsCustomAction(outsettings);
|
||||
|
||||
SendRestartAsAdminConfigMSG(customaction.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,370 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
|
||||
{
|
||||
public class ImageResizerViewModel : Observable
|
||||
{
|
||||
private GeneralSettings GeneralSettingsConfig { get; set; }
|
||||
|
||||
private readonly ISettingsUtils _settingsUtils;
|
||||
|
||||
private ImageResizerSettings Settings { get; set; }
|
||||
|
||||
private const string ModuleName = ImageResizerSettings.ModuleName;
|
||||
|
||||
private Func<string, int> SendConfigMSG { get; }
|
||||
|
||||
[SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "Exceptions should not crash the program but will be logged until we can understand common exception scenarios")]
|
||||
public ImageResizerViewModel(ISettingsUtils settingsUtils, ISettingsRepository<GeneralSettings> settingsRepository, Func<string, int> ipcMSGCallBackFunc)
|
||||
{
|
||||
_settingsUtils = settingsUtils ?? throw new ArgumentNullException(nameof(settingsUtils));
|
||||
|
||||
// To obtain the general settings configurations of PowerToys.
|
||||
if (settingsRepository == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(settingsRepository));
|
||||
}
|
||||
|
||||
GeneralSettingsConfig = settingsRepository.SettingsConfig;
|
||||
|
||||
try
|
||||
{
|
||||
Settings = _settingsUtils.GetSettings<ImageResizerSettings>(ModuleName);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.LogError($"Exception encountered while reading {ModuleName} settings.", e);
|
||||
#if DEBUG
|
||||
if (e is ArgumentException || e is ArgumentNullException || e is PathTooLongException)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
#endif
|
||||
Settings = new ImageResizerSettings();
|
||||
_settingsUtils.SaveSettings(Settings.ToJsonString(), ModuleName);
|
||||
}
|
||||
|
||||
// set the callback functions value to hangle outgoing IPC message.
|
||||
SendConfigMSG = ipcMSGCallBackFunc;
|
||||
|
||||
_isEnabled = GeneralSettingsConfig.Enabled.ImageResizer;
|
||||
_advancedSizes = Settings.Properties.ImageresizerSizes.Value;
|
||||
_jpegQualityLevel = Settings.Properties.ImageresizerJpegQualityLevel.Value;
|
||||
_pngInterlaceOption = Settings.Properties.ImageresizerPngInterlaceOption.Value;
|
||||
_tiffCompressOption = Settings.Properties.ImageresizerTiffCompressOption.Value;
|
||||
_fileName = Settings.Properties.ImageresizerFileName.Value;
|
||||
_keepDateModified = Settings.Properties.ImageresizerKeepDateModified.Value;
|
||||
_encoderGuidId = GetEncoderIndex(Settings.Properties.ImageresizerFallbackEncoder.Value);
|
||||
|
||||
int i = 0;
|
||||
foreach (ImageSize size in _advancedSizes)
|
||||
{
|
||||
size.Id = i;
|
||||
i++;
|
||||
size.PropertyChanged += SizePropertyChanged;
|
||||
}
|
||||
}
|
||||
|
||||
private bool _isEnabled;
|
||||
private ObservableCollection<ImageSize> _advancedSizes = new ObservableCollection<ImageSize>();
|
||||
private int _jpegQualityLevel;
|
||||
private int _pngInterlaceOption;
|
||||
private int _tiffCompressOption;
|
||||
private string _fileName;
|
||||
private bool _keepDateModified;
|
||||
private int _encoderGuidId;
|
||||
|
||||
public bool IsEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
return _isEnabled;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _isEnabled)
|
||||
{
|
||||
// To set the status of ImageResizer in the General PowerToys settings.
|
||||
_isEnabled = value;
|
||||
GeneralSettingsConfig.Enabled.ImageResizer = value;
|
||||
OutGoingGeneralSettings snd = new OutGoingGeneralSettings(GeneralSettingsConfig);
|
||||
|
||||
SendConfigMSG(snd.ToString());
|
||||
OnPropertyChanged(nameof(IsEnabled));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#pragma warning disable CA2227 // Collection properties should be read only
|
||||
public ObservableCollection<ImageSize> Sizes
|
||||
#pragma warning restore CA2227 // Collection properties should be read only
|
||||
{
|
||||
get
|
||||
{
|
||||
return _advancedSizes;
|
||||
}
|
||||
|
||||
// FxCop demands collection properties to be read-only, but this
|
||||
// setter is used in autogenerated files (ImageResizerPage.g.cs)
|
||||
// and replacing the setter with its own method will break the file
|
||||
set
|
||||
{
|
||||
SavesImageSizes(value);
|
||||
_advancedSizes = value;
|
||||
OnPropertyChanged(nameof(Sizes));
|
||||
}
|
||||
}
|
||||
|
||||
public int JPEGQualityLevel
|
||||
{
|
||||
get
|
||||
{
|
||||
return _jpegQualityLevel;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (_jpegQualityLevel != value)
|
||||
{
|
||||
_jpegQualityLevel = value;
|
||||
Settings.Properties.ImageresizerJpegQualityLevel.Value = value;
|
||||
_settingsUtils.SaveSettings(Settings.ToJsonString(), ModuleName);
|
||||
OnPropertyChanged(nameof(JPEGQualityLevel));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int PngInterlaceOption
|
||||
{
|
||||
get
|
||||
{
|
||||
return _pngInterlaceOption;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (_pngInterlaceOption != value)
|
||||
{
|
||||
_pngInterlaceOption = value;
|
||||
Settings.Properties.ImageresizerPngInterlaceOption.Value = value;
|
||||
_settingsUtils.SaveSettings(Settings.ToJsonString(), ModuleName);
|
||||
OnPropertyChanged(nameof(PngInterlaceOption));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int TiffCompressOption
|
||||
{
|
||||
get
|
||||
{
|
||||
return _tiffCompressOption;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (_tiffCompressOption != value)
|
||||
{
|
||||
_tiffCompressOption = value;
|
||||
Settings.Properties.ImageresizerTiffCompressOption.Value = value;
|
||||
_settingsUtils.SaveSettings(Settings.ToJsonString(), ModuleName);
|
||||
OnPropertyChanged(nameof(TiffCompressOption));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string FileName
|
||||
{
|
||||
get
|
||||
{
|
||||
return _fileName;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(value))
|
||||
{
|
||||
_fileName = value;
|
||||
Settings.Properties.ImageresizerFileName.Value = value;
|
||||
_settingsUtils.SaveSettings(Settings.ToJsonString(), ModuleName);
|
||||
OnPropertyChanged(nameof(FileName));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool KeepDateModified
|
||||
{
|
||||
get
|
||||
{
|
||||
return _keepDateModified;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_keepDateModified = value;
|
||||
Settings.Properties.ImageresizerKeepDateModified.Value = value;
|
||||
_settingsUtils.SaveSettings(Settings.ToJsonString(), ModuleName);
|
||||
OnPropertyChanged(nameof(KeepDateModified));
|
||||
}
|
||||
}
|
||||
|
||||
public int Encoder
|
||||
{
|
||||
get
|
||||
{
|
||||
return _encoderGuidId;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (_encoderGuidId != value)
|
||||
{
|
||||
_encoderGuidId = value;
|
||||
_settingsUtils.SaveSettings(Settings.Properties.ImageresizerSizes.ToJsonString(), ModuleName, "sizes.json");
|
||||
Settings.Properties.ImageresizerFallbackEncoder.Value = GetEncoderGuid(value);
|
||||
_settingsUtils.SaveSettings(Settings.ToJsonString(), ModuleName);
|
||||
OnPropertyChanged(nameof(Encoder));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string EncoderGuid
|
||||
{
|
||||
get
|
||||
{
|
||||
return ImageResizerViewModel.GetEncoderGuid(_encoderGuidId);
|
||||
}
|
||||
}
|
||||
|
||||
public void AddRow()
|
||||
{
|
||||
ObservableCollection<ImageSize> imageSizes = Sizes;
|
||||
int maxId = imageSizes.Count > 0 ? imageSizes.OrderBy(x => x.Id).Last().Id : -1;
|
||||
ImageSize newSize = new ImageSize(maxId + 1);
|
||||
newSize.PropertyChanged += SizePropertyChanged;
|
||||
imageSizes.Add(newSize);
|
||||
_advancedSizes = imageSizes;
|
||||
SavesImageSizes(imageSizes);
|
||||
}
|
||||
|
||||
public void DeleteImageSize(int id)
|
||||
{
|
||||
ImageSize size = _advancedSizes.Where<ImageSize>(x => x.Id == id).First();
|
||||
ObservableCollection<ImageSize> imageSizes = Sizes;
|
||||
imageSizes.Remove(size);
|
||||
|
||||
_advancedSizes = imageSizes;
|
||||
SavesImageSizes(imageSizes);
|
||||
}
|
||||
|
||||
public void SavesImageSizes(ObservableCollection<ImageSize> imageSizes)
|
||||
{
|
||||
_settingsUtils.SaveSettings(Settings.Properties.ImageresizerSizes.ToJsonString(), ModuleName, "sizes.json");
|
||||
Settings.Properties.ImageresizerSizes = new ImageResizerSizes(imageSizes);
|
||||
_settingsUtils.SaveSettings(Settings.ToJsonString(), ModuleName);
|
||||
}
|
||||
|
||||
public static string GetEncoderGuid(int value)
|
||||
{
|
||||
// PNG Encoder guid
|
||||
if (value == 0)
|
||||
{
|
||||
return "1b7cfaf4-713f-473c-bbcd-6137425faeaf";
|
||||
}
|
||||
|
||||
// Bitmap Encoder guid
|
||||
else if (value == 1)
|
||||
{
|
||||
return "0af1d87e-fcfe-4188-bdeb-a7906471cbe3";
|
||||
}
|
||||
|
||||
// JPEG Encoder guid
|
||||
else if (value == 2)
|
||||
{
|
||||
return "19e4a5aa-5662-4fc5-a0c0-1758028e1057";
|
||||
}
|
||||
|
||||
// Tiff encoder guid.
|
||||
else if (value == 3)
|
||||
{
|
||||
return "163bcc30-e2e9-4f0b-961d-a3e9fdb788a3";
|
||||
}
|
||||
|
||||
// Tiff encoder guid.
|
||||
else if (value == 4)
|
||||
{
|
||||
return "57a37caa-367a-4540-916b-f183c5093a4b";
|
||||
}
|
||||
|
||||
// Gif encoder guid.
|
||||
else if (value == 5)
|
||||
{
|
||||
return "1f8a5601-7d4d-4cbd-9c82-1bc8d4eeb9a5";
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static int GetEncoderIndex(string value)
|
||||
{
|
||||
// PNG Encoder guid
|
||||
if (value == "1b7cfaf4-713f-473c-bbcd-6137425faeaf")
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Bitmap Encoder guid
|
||||
else if (value == "0af1d87e-fcfe-4188-bdeb-a7906471cbe3")
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
// JPEG Encoder guid
|
||||
else if (value == "19e4a5aa-5662-4fc5-a0c0-1758028e1057")
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
// Tiff encoder guid.
|
||||
else if (value == "163bcc30-e2e9-4f0b-961d-a3e9fdb788a3")
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
|
||||
// Tiff encoder guid.
|
||||
else if (value == "57a37caa-367a-4540-916b-f183c5093a4b")
|
||||
{
|
||||
return 4;
|
||||
}
|
||||
|
||||
// Gif encoder guid.
|
||||
else if (value == "1f8a5601-7d4d-4cbd-9c82-1bc8d4eeb9a5")
|
||||
{
|
||||
return 5;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
public void SizePropertyChanged(object sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
ImageSize modifiedSize = (ImageSize)sender;
|
||||
ObservableCollection<ImageSize> imageSizes = Sizes;
|
||||
imageSizes.Where<ImageSize>(x => x.Id == modifiedSize.Id).First().Update(modifiedSize);
|
||||
_advancedSizes = imageSizes;
|
||||
SavesImageSizes(imageSizes);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,249 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.ViewModels.Commands;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
|
||||
{
|
||||
public class KeyboardManagerViewModel : Observable
|
||||
{
|
||||
private GeneralSettings GeneralSettingsConfig { get; set; }
|
||||
|
||||
private readonly ISettingsUtils _settingsUtils;
|
||||
|
||||
private const string PowerToyName = KeyboardManagerSettings.ModuleName;
|
||||
private const string RemapKeyboardActionName = "RemapKeyboard";
|
||||
private const string RemapKeyboardActionValue = "Open Remap Keyboard Window";
|
||||
private const string EditShortcutActionName = "EditShortcut";
|
||||
private const string EditShortcutActionValue = "Open Edit Shortcut Window";
|
||||
private const string JsonFileType = ".json";
|
||||
private const string ProfileFileMutexName = "PowerToys.KeyboardManager.ConfigMutex";
|
||||
private const int ProfileFileMutexWaitTimeoutMilliseconds = 1000;
|
||||
|
||||
public KeyboardManagerSettings Settings { get; set; }
|
||||
|
||||
private ICommand _remapKeyboardCommand;
|
||||
private ICommand _editShortcutCommand;
|
||||
private KeyboardManagerProfile _profile;
|
||||
|
||||
private Func<string, int> SendConfigMSG { get; }
|
||||
|
||||
private Func<List<KeysDataModel>, int> FilterRemapKeysList { get; }
|
||||
|
||||
[SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "Exceptions should not crash the program but will be logged until we can understand common exception scenarios")]
|
||||
public KeyboardManagerViewModel(ISettingsUtils settingsUtils, ISettingsRepository<GeneralSettings> settingsRepository, Func<string, int> ipcMSGCallBackFunc, Func<List<KeysDataModel>, int> filterRemapKeysList)
|
||||
{
|
||||
if (settingsRepository == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(settingsRepository));
|
||||
}
|
||||
|
||||
GeneralSettingsConfig = settingsRepository.SettingsConfig;
|
||||
|
||||
// set the callback functions value to hangle outgoing IPC message.
|
||||
SendConfigMSG = ipcMSGCallBackFunc;
|
||||
FilterRemapKeysList = filterRemapKeysList;
|
||||
|
||||
_settingsUtils = settingsUtils ?? throw new ArgumentNullException(nameof(settingsUtils));
|
||||
|
||||
if (_settingsUtils.SettingsExists(PowerToyName))
|
||||
{
|
||||
try
|
||||
{
|
||||
Settings = _settingsUtils.GetSettings<KeyboardManagerSettings>(PowerToyName);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.LogError($"Exception encountered while reading {PowerToyName} settings.", e);
|
||||
#if DEBUG
|
||||
if (e is ArgumentException || e is ArgumentNullException || e is PathTooLongException)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// Load profile.
|
||||
if (!LoadProfile())
|
||||
{
|
||||
_profile = new KeyboardManagerProfile();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Settings = new KeyboardManagerSettings();
|
||||
_settingsUtils.SaveSettings(Settings.ToJsonString(), PowerToyName);
|
||||
}
|
||||
}
|
||||
|
||||
public bool Enabled
|
||||
{
|
||||
get
|
||||
{
|
||||
return GeneralSettingsConfig.Enabled.KeyboardManager;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (GeneralSettingsConfig.Enabled.KeyboardManager != value)
|
||||
{
|
||||
GeneralSettingsConfig.Enabled.KeyboardManager = value;
|
||||
OnPropertyChanged(nameof(Enabled));
|
||||
OutGoingGeneralSettings outgoing = new OutGoingGeneralSettings(GeneralSettingsConfig);
|
||||
|
||||
SendConfigMSG(outgoing.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// store remappings
|
||||
public List<KeysDataModel> RemapKeys
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_profile != null)
|
||||
{
|
||||
return _profile.RemapKeys.InProcessRemapKeys;
|
||||
}
|
||||
else
|
||||
{
|
||||
return new List<KeysDataModel>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static List<AppSpecificKeysDataModel> CombineShortcutLists(List<KeysDataModel> globalShortcutList, List<AppSpecificKeysDataModel> appSpecificShortcutList)
|
||||
{
|
||||
if (globalShortcutList == null && appSpecificShortcutList == null)
|
||||
{
|
||||
return new List<AppSpecificKeysDataModel>();
|
||||
}
|
||||
else if (globalShortcutList == null)
|
||||
{
|
||||
return appSpecificShortcutList;
|
||||
}
|
||||
else if (appSpecificShortcutList == null)
|
||||
{
|
||||
return globalShortcutList.ConvertAll(x => new AppSpecificKeysDataModel { OriginalKeys = x.OriginalKeys, NewRemapKeys = x.NewRemapKeys, TargetApp = "All Apps" }).ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
return globalShortcutList.ConvertAll(x => new AppSpecificKeysDataModel { OriginalKeys = x.OriginalKeys, NewRemapKeys = x.NewRemapKeys, TargetApp = "All Apps" }).Concat(appSpecificShortcutList).ToList();
|
||||
}
|
||||
}
|
||||
|
||||
public List<AppSpecificKeysDataModel> RemapShortcuts
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_profile != null)
|
||||
{
|
||||
return CombineShortcutLists(_profile.RemapShortcuts.GlobalRemapShortcuts, _profile.RemapShortcuts.AppSpecificRemapShortcuts);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new List<AppSpecificKeysDataModel>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ICommand RemapKeyboardCommand => _remapKeyboardCommand ?? (_remapKeyboardCommand = new RelayCommand(OnRemapKeyboard));
|
||||
|
||||
public ICommand EditShortcutCommand => _editShortcutCommand ?? (_editShortcutCommand = new RelayCommand(OnEditShortcut));
|
||||
|
||||
// Note: FxCop suggests calling ConfigureAwait() for the following methods,
|
||||
// and calling ConfigureAwait(true) has the same behavior as not explicitly
|
||||
// calling it (continuations are scheduled on the task-creating thread)
|
||||
private async void OnRemapKeyboard()
|
||||
{
|
||||
await Task.Run(() => OnRemapKeyboardBackground()).ConfigureAwait(true);
|
||||
}
|
||||
|
||||
private async void OnEditShortcut()
|
||||
{
|
||||
await Task.Run(() => OnEditShortcutBackground()).ConfigureAwait(true);
|
||||
}
|
||||
|
||||
private async Task OnRemapKeyboardBackground()
|
||||
{
|
||||
Helper.AllowRunnerToForeground();
|
||||
SendConfigMSG(Helper.GetSerializedCustomAction(PowerToyName, RemapKeyboardActionName, RemapKeyboardActionValue));
|
||||
await Task.CompletedTask.ConfigureAwait(true);
|
||||
}
|
||||
|
||||
private async Task OnEditShortcutBackground()
|
||||
{
|
||||
Helper.AllowRunnerToForeground();
|
||||
SendConfigMSG(Helper.GetSerializedCustomAction(PowerToyName, EditShortcutActionName, EditShortcutActionValue));
|
||||
await Task.CompletedTask.ConfigureAwait(true);
|
||||
}
|
||||
|
||||
public void NotifyFileChanged()
|
||||
{
|
||||
OnPropertyChanged(nameof(RemapKeys));
|
||||
OnPropertyChanged(nameof(RemapShortcuts));
|
||||
}
|
||||
|
||||
[SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "Exceptions here (especially mutex errors) should not halt app execution, but they will be logged.")]
|
||||
public bool LoadProfile()
|
||||
{
|
||||
var success = true;
|
||||
|
||||
try
|
||||
{
|
||||
using (var profileFileMutex = Mutex.OpenExisting(ProfileFileMutexName))
|
||||
{
|
||||
if (profileFileMutex.WaitOne(ProfileFileMutexWaitTimeoutMilliseconds))
|
||||
{
|
||||
// update the UI element here.
|
||||
try
|
||||
{
|
||||
string fileName = Settings.Properties.ActiveConfiguration.Value + JsonFileType;
|
||||
|
||||
if (_settingsUtils.SettingsExists(PowerToyName, fileName))
|
||||
{
|
||||
_profile = _settingsUtils.GetSettings<KeyboardManagerProfile>(PowerToyName, fileName);
|
||||
}
|
||||
else
|
||||
{
|
||||
// The KBM process out of runner creates the default.json file if it does not exist.
|
||||
success = false;
|
||||
}
|
||||
|
||||
FilterRemapKeysList(_profile?.RemapKeys?.InProcessRemapKeys);
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Make sure to release the mutex.
|
||||
profileFileMutex.ReleaseMutex();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
success = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// Failed to load the configuration.
|
||||
Logger.LogError($"Exception encountered when loading {PowerToyName} profile", e);
|
||||
success = false;
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,288 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text.Json;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
|
||||
{
|
||||
public class PowerLauncherViewModel : Observable
|
||||
{
|
||||
private GeneralSettings GeneralSettingsConfig { get; set; }
|
||||
|
||||
private readonly ISettingsUtils _settingsUtils;
|
||||
|
||||
private PowerLauncherSettings settings;
|
||||
|
||||
public delegate void SendCallback(PowerLauncherSettings settings);
|
||||
|
||||
private readonly SendCallback callback;
|
||||
|
||||
private Func<string, int> SendConfigMSG { get; }
|
||||
|
||||
public PowerLauncherViewModel(ISettingsUtils settingsUtils, ISettingsRepository<GeneralSettings> settingsRepository, Func<string, int> ipcMSGCallBackFunc, int defaultKeyCode)
|
||||
{
|
||||
_settingsUtils = settingsUtils ?? throw new ArgumentNullException(nameof(settingsUtils));
|
||||
|
||||
// To obtain the general Settings configurations of PowerToys
|
||||
if (settingsRepository == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(settingsRepository));
|
||||
}
|
||||
|
||||
GeneralSettingsConfig = settingsRepository.SettingsConfig;
|
||||
|
||||
// set the callback functions value to hangle outgoing IPC message.
|
||||
SendConfigMSG = ipcMSGCallBackFunc;
|
||||
callback = (PowerLauncherSettings settings) =>
|
||||
{
|
||||
// Propagate changes to Power Launcher through IPC
|
||||
// Using InvariantCulture as this is an IPC message
|
||||
SendConfigMSG(
|
||||
string.Format(
|
||||
CultureInfo.InvariantCulture,
|
||||
"{{ \"powertoys\": {{ \"{0}\": {1} }} }}",
|
||||
PowerLauncherSettings.ModuleName,
|
||||
JsonSerializer.Serialize(settings)));
|
||||
};
|
||||
|
||||
if (_settingsUtils.SettingsExists(PowerLauncherSettings.ModuleName))
|
||||
{
|
||||
settings = _settingsUtils.GetSettings<PowerLauncherSettings>(PowerLauncherSettings.ModuleName);
|
||||
}
|
||||
else
|
||||
{
|
||||
settings = new PowerLauncherSettings();
|
||||
settings.Properties.OpenPowerLauncher.Alt = true;
|
||||
settings.Properties.OpenPowerLauncher.Code = defaultKeyCode;
|
||||
settings.Properties.MaximumNumberOfResults = 4;
|
||||
callback(settings);
|
||||
}
|
||||
}
|
||||
|
||||
public PowerLauncherViewModel(PowerLauncherSettings settings, SendCallback callback)
|
||||
{
|
||||
this.settings = settings;
|
||||
this.callback = callback;
|
||||
}
|
||||
|
||||
private void UpdateSettings([CallerMemberName] string propertyName = null)
|
||||
{
|
||||
// Notify UI of property change
|
||||
OnPropertyChanged(propertyName);
|
||||
|
||||
callback(settings);
|
||||
}
|
||||
|
||||
public bool EnablePowerLauncher
|
||||
{
|
||||
get
|
||||
{
|
||||
return GeneralSettingsConfig.Enabled.PowerLauncher;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (GeneralSettingsConfig.Enabled.PowerLauncher != value)
|
||||
{
|
||||
GeneralSettingsConfig.Enabled.PowerLauncher = value;
|
||||
OnPropertyChanged(nameof(EnablePowerLauncher));
|
||||
OutGoingGeneralSettings outgoing = new OutGoingGeneralSettings(GeneralSettingsConfig);
|
||||
SendConfigMSG(outgoing.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string SearchResultPreference
|
||||
{
|
||||
get
|
||||
{
|
||||
return settings.Properties.SearchResultPreference;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (settings.Properties.SearchResultPreference != value)
|
||||
{
|
||||
settings.Properties.SearchResultPreference = value;
|
||||
UpdateSettings();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string SearchTypePreference
|
||||
{
|
||||
get
|
||||
{
|
||||
return settings.Properties.SearchTypePreference;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (settings.Properties.SearchTypePreference != value)
|
||||
{
|
||||
settings.Properties.SearchTypePreference = value;
|
||||
UpdateSettings();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int MaximumNumberOfResults
|
||||
{
|
||||
get
|
||||
{
|
||||
return settings.Properties.MaximumNumberOfResults;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (settings.Properties.MaximumNumberOfResults != value)
|
||||
{
|
||||
settings.Properties.MaximumNumberOfResults = value;
|
||||
UpdateSettings();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public HotkeySettings OpenPowerLauncher
|
||||
{
|
||||
get
|
||||
{
|
||||
return settings.Properties.OpenPowerLauncher;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (settings.Properties.OpenPowerLauncher != value)
|
||||
{
|
||||
settings.Properties.OpenPowerLauncher = value;
|
||||
UpdateSettings();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public HotkeySettings OpenFileLocation
|
||||
{
|
||||
get
|
||||
{
|
||||
return settings.Properties.OpenFileLocation;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (settings.Properties.OpenFileLocation != value)
|
||||
{
|
||||
settings.Properties.OpenFileLocation = value;
|
||||
UpdateSettings();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public HotkeySettings CopyPathLocation
|
||||
{
|
||||
get
|
||||
{
|
||||
return settings.Properties.CopyPathLocation;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (settings.Properties.CopyPathLocation != value)
|
||||
{
|
||||
settings.Properties.CopyPathLocation = value;
|
||||
UpdateSettings();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool OverrideWinRKey
|
||||
{
|
||||
get
|
||||
{
|
||||
return settings.Properties.OverrideWinkeyR;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (settings.Properties.OverrideWinkeyR != value)
|
||||
{
|
||||
settings.Properties.OverrideWinkeyR = value;
|
||||
UpdateSettings();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool OverrideWinSKey
|
||||
{
|
||||
get
|
||||
{
|
||||
return settings.Properties.OverrideWinkeyS;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (settings.Properties.OverrideWinkeyS != value)
|
||||
{
|
||||
settings.Properties.OverrideWinkeyS = value;
|
||||
UpdateSettings();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool IgnoreHotkeysInFullScreen
|
||||
{
|
||||
get
|
||||
{
|
||||
return settings.Properties.IgnoreHotkeysInFullscreen;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (settings.Properties.IgnoreHotkeysInFullscreen != value)
|
||||
{
|
||||
settings.Properties.IgnoreHotkeysInFullscreen = value;
|
||||
UpdateSettings();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool ClearInputOnLaunch
|
||||
{
|
||||
get
|
||||
{
|
||||
return settings.Properties.ClearInputOnLaunch;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (settings.Properties.ClearInputOnLaunch != value)
|
||||
{
|
||||
settings.Properties.ClearInputOnLaunch = value;
|
||||
UpdateSettings();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool DisableDriveDetectionWarning
|
||||
{
|
||||
get
|
||||
{
|
||||
return settings.Properties.DisableDriveDetectionWarning;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (settings.Properties.DisableDriveDetectionWarning != value)
|
||||
{
|
||||
settings.Properties.DisableDriveDetectionWarning = value;
|
||||
UpdateSettings();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
|
||||
{
|
||||
public class PowerPreviewViewModel : Observable
|
||||
{
|
||||
private const string ModuleName = PowerPreviewSettings.ModuleName;
|
||||
|
||||
private PowerPreviewSettings Settings { get; set; }
|
||||
|
||||
private Func<string, int> SendConfigMSG { get; }
|
||||
|
||||
private string _settingsConfigFileFolder = string.Empty;
|
||||
|
||||
private GeneralSettings GeneralSettingsConfig { get; set; }
|
||||
|
||||
public PowerPreviewViewModel(ISettingsRepository<PowerPreviewSettings> moduleSettingsRepository, ISettingsRepository<GeneralSettings> generalSettingsRepository, Func<string, int> ipcMSGCallBackFunc, string configFileSubfolder = "")
|
||||
{
|
||||
// Update Settings file folder:
|
||||
_settingsConfigFileFolder = configFileSubfolder;
|
||||
|
||||
// To obtain the general Settings configurations of PowerToys
|
||||
if (generalSettingsRepository == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(generalSettingsRepository));
|
||||
}
|
||||
|
||||
GeneralSettingsConfig = generalSettingsRepository.SettingsConfig;
|
||||
|
||||
// To obtain the PowerPreview settings if it exists.
|
||||
// If the file does not exist, to create a new one and return the default settings configurations.
|
||||
if (moduleSettingsRepository == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(moduleSettingsRepository));
|
||||
}
|
||||
|
||||
Settings = moduleSettingsRepository.SettingsConfig;
|
||||
|
||||
// set the callback functions value to hangle outgoing IPC message.
|
||||
SendConfigMSG = ipcMSGCallBackFunc;
|
||||
|
||||
_svgRenderIsEnabled = Settings.Properties.EnableSvgPreview;
|
||||
_svgThumbnailIsEnabled = Settings.Properties.EnableSvgThumbnail;
|
||||
_mdRenderIsEnabled = Settings.Properties.EnableMdPreview;
|
||||
}
|
||||
|
||||
private bool _svgRenderIsEnabled;
|
||||
private bool _mdRenderIsEnabled;
|
||||
private bool _svgThumbnailIsEnabled;
|
||||
|
||||
public bool SVGRenderIsEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
return _svgRenderIsEnabled;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _svgRenderIsEnabled)
|
||||
{
|
||||
_svgRenderIsEnabled = value;
|
||||
Settings.Properties.EnableSvgPreview = value;
|
||||
RaisePropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool SVGThumbnailIsEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
return _svgThumbnailIsEnabled;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _svgThumbnailIsEnabled)
|
||||
{
|
||||
_svgThumbnailIsEnabled = value;
|
||||
Settings.Properties.EnableSvgThumbnail = value;
|
||||
RaisePropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool MDRenderIsEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
return _mdRenderIsEnabled;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _mdRenderIsEnabled)
|
||||
{
|
||||
_mdRenderIsEnabled = value;
|
||||
Settings.Properties.EnableMdPreview = value;
|
||||
RaisePropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string GetSettingsSubPath()
|
||||
{
|
||||
return _settingsConfigFileFolder + "\\" + ModuleName;
|
||||
}
|
||||
|
||||
public bool IsElevated
|
||||
{
|
||||
get
|
||||
{
|
||||
return GeneralSettingsConfig.IsElevated;
|
||||
}
|
||||
}
|
||||
|
||||
private void RaisePropertyChanged([CallerMemberName] string propertyName = null)
|
||||
{
|
||||
// Notify UI of property change
|
||||
OnPropertyChanged(propertyName);
|
||||
|
||||
if (SendConfigMSG != null)
|
||||
{
|
||||
SndPowerPreviewSettings snd = new SndPowerPreviewSettings(Settings);
|
||||
SndModuleSettings<SndPowerPreviewSettings> ipcMessage = new SndModuleSettings<SndPowerPreviewSettings>(snd);
|
||||
SendConfigMSG(ipcMessage.ToJsonString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,220 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
|
||||
{
|
||||
public class PowerRenameViewModel : Observable
|
||||
{
|
||||
private GeneralSettings GeneralSettingsConfig { get; set; }
|
||||
|
||||
private readonly ISettingsUtils _settingsUtils;
|
||||
|
||||
private const string ModuleName = PowerRenameSettings.ModuleName;
|
||||
|
||||
private string _settingsConfigFileFolder = string.Empty;
|
||||
|
||||
private PowerRenameSettings Settings { get; set; }
|
||||
|
||||
private Func<string, int> SendConfigMSG { get; }
|
||||
|
||||
[SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "Exceptions should not crash the program but will be logged until we can understand common exception scenarios")]
|
||||
public PowerRenameViewModel(ISettingsUtils settingsUtils, ISettingsRepository<GeneralSettings> settingsRepository, Func<string, int> ipcMSGCallBackFunc, string configFileSubfolder = "")
|
||||
{
|
||||
// Update Settings file folder:
|
||||
_settingsConfigFileFolder = configFileSubfolder;
|
||||
_settingsUtils = settingsUtils ?? throw new ArgumentNullException(nameof(settingsUtils));
|
||||
|
||||
if (settingsRepository == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(settingsRepository));
|
||||
}
|
||||
|
||||
GeneralSettingsConfig = settingsRepository.SettingsConfig;
|
||||
|
||||
try
|
||||
{
|
||||
PowerRenameLocalProperties localSettings = _settingsUtils.GetSettings<PowerRenameLocalProperties>(GetSettingsSubPath(), "power-rename-settings.json");
|
||||
Settings = new PowerRenameSettings(localSettings);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.LogError($"Exception encountered while reading {ModuleName} settings.", e);
|
||||
#if DEBUG
|
||||
if (e is ArgumentException || e is ArgumentNullException || e is PathTooLongException)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
#endif
|
||||
PowerRenameLocalProperties localSettings = new PowerRenameLocalProperties();
|
||||
Settings = new PowerRenameSettings(localSettings);
|
||||
_settingsUtils.SaveSettings(localSettings.ToJsonString(), GetSettingsSubPath(), "power-rename-settings.json");
|
||||
}
|
||||
|
||||
// set the callback functions value to hangle outgoing IPC message.
|
||||
SendConfigMSG = ipcMSGCallBackFunc;
|
||||
|
||||
_powerRenameEnabledOnContextMenu = Settings.Properties.ShowIcon.Value;
|
||||
_powerRenameEnabledOnContextExtendedMenu = Settings.Properties.ExtendedContextMenuOnly.Value;
|
||||
_powerRenameRestoreFlagsOnLaunch = Settings.Properties.PersistState.Value;
|
||||
_powerRenameMaxDispListNumValue = Settings.Properties.MaxMRUSize.Value;
|
||||
_autoComplete = Settings.Properties.MRUEnabled.Value;
|
||||
_powerRenameEnabled = GeneralSettingsConfig.Enabled.PowerRename;
|
||||
}
|
||||
|
||||
private bool _powerRenameEnabled;
|
||||
private bool _powerRenameEnabledOnContextMenu;
|
||||
private bool _powerRenameEnabledOnContextExtendedMenu;
|
||||
private bool _powerRenameRestoreFlagsOnLaunch;
|
||||
private int _powerRenameMaxDispListNumValue;
|
||||
private bool _autoComplete;
|
||||
|
||||
public bool IsEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
return _powerRenameEnabled;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _powerRenameEnabled)
|
||||
{
|
||||
GeneralSettingsConfig.Enabled.PowerRename = value;
|
||||
OutGoingGeneralSettings snd = new OutGoingGeneralSettings(GeneralSettingsConfig);
|
||||
|
||||
SendConfigMSG(snd.ToString());
|
||||
|
||||
_powerRenameEnabled = value;
|
||||
OnPropertyChanged(nameof(IsEnabled));
|
||||
RaisePropertyChanged(nameof(GlobalAndMruEnabled));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool MRUEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
return _autoComplete;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _autoComplete)
|
||||
{
|
||||
_autoComplete = value;
|
||||
Settings.Properties.MRUEnabled.Value = value;
|
||||
RaisePropertyChanged();
|
||||
RaisePropertyChanged(nameof(GlobalAndMruEnabled));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool GlobalAndMruEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
return _autoComplete && _powerRenameEnabled;
|
||||
}
|
||||
}
|
||||
|
||||
public bool EnabledOnContextMenu
|
||||
{
|
||||
get
|
||||
{
|
||||
return _powerRenameEnabledOnContextMenu;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _powerRenameEnabledOnContextMenu)
|
||||
{
|
||||
_powerRenameEnabledOnContextMenu = value;
|
||||
Settings.Properties.ShowIcon.Value = value;
|
||||
RaisePropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool EnabledOnContextExtendedMenu
|
||||
{
|
||||
get
|
||||
{
|
||||
return _powerRenameEnabledOnContextExtendedMenu;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _powerRenameEnabledOnContextExtendedMenu)
|
||||
{
|
||||
_powerRenameEnabledOnContextExtendedMenu = value;
|
||||
Settings.Properties.ExtendedContextMenuOnly.Value = value;
|
||||
RaisePropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool RestoreFlagsOnLaunch
|
||||
{
|
||||
get
|
||||
{
|
||||
return _powerRenameRestoreFlagsOnLaunch;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _powerRenameRestoreFlagsOnLaunch)
|
||||
{
|
||||
_powerRenameRestoreFlagsOnLaunch = value;
|
||||
Settings.Properties.PersistState.Value = value;
|
||||
RaisePropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int MaxDispListNum
|
||||
{
|
||||
get
|
||||
{
|
||||
return _powerRenameMaxDispListNumValue;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _powerRenameMaxDispListNumValue)
|
||||
{
|
||||
_powerRenameMaxDispListNumValue = value;
|
||||
Settings.Properties.MaxMRUSize.Value = value;
|
||||
RaisePropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string GetSettingsSubPath()
|
||||
{
|
||||
return _settingsConfigFileFolder + "\\" + ModuleName;
|
||||
}
|
||||
|
||||
private void RaisePropertyChanged([CallerMemberName] string propertyName = null)
|
||||
{
|
||||
// Notify UI of property change
|
||||
OnPropertyChanged(propertyName);
|
||||
|
||||
if (SendConfigMSG != null)
|
||||
{
|
||||
SndPowerRenameSettings snd = new SndPowerRenameSettings(Settings);
|
||||
SndModuleSettings<SndPowerRenameSettings> ipcMessage = new SndModuleSettings<SndPowerRenameSettings>(snd);
|
||||
SendConfigMSG(ipcMessage.ToJsonString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,186 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
|
||||
{
|
||||
public class ShortcutGuideViewModel : Observable
|
||||
{
|
||||
private GeneralSettings GeneralSettingsConfig { get; set; }
|
||||
|
||||
private ShortcutGuideSettings Settings { get; set; }
|
||||
|
||||
private const string ModuleName = ShortcutGuideSettings.ModuleName;
|
||||
|
||||
private Func<string, int> SendConfigMSG { get; }
|
||||
|
||||
private string _settingsConfigFileFolder = string.Empty;
|
||||
|
||||
public ShortcutGuideViewModel(ISettingsRepository<GeneralSettings> settingsRepository, ISettingsRepository<ShortcutGuideSettings> moduleSettingsRepository, Func<string, int> ipcMSGCallBackFunc, string configFileSubfolder = "")
|
||||
{
|
||||
// Update Settings file folder:
|
||||
_settingsConfigFileFolder = configFileSubfolder;
|
||||
|
||||
// To obtain the general PowerToys settings.
|
||||
if (settingsRepository == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(settingsRepository));
|
||||
}
|
||||
|
||||
GeneralSettingsConfig = settingsRepository.SettingsConfig;
|
||||
|
||||
// To obtain the shortcut guide settings, if the file exists.
|
||||
// If not, to create a file with the default settings and to return the default configurations.
|
||||
if (moduleSettingsRepository == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(moduleSettingsRepository));
|
||||
}
|
||||
|
||||
Settings = moduleSettingsRepository.SettingsConfig;
|
||||
|
||||
// set the callback functions value to hangle outgoing IPC message.
|
||||
SendConfigMSG = ipcMSGCallBackFunc;
|
||||
|
||||
_isEnabled = GeneralSettingsConfig.Enabled.ShortcutGuide;
|
||||
_pressTime = Settings.Properties.PressTime.Value;
|
||||
_opacity = Settings.Properties.OverlayOpacity.Value;
|
||||
|
||||
string theme = Settings.Properties.Theme.Value;
|
||||
|
||||
if (theme == "dark")
|
||||
{
|
||||
_themeIndex = 0;
|
||||
}
|
||||
|
||||
if (theme == "light")
|
||||
{
|
||||
_themeIndex = 1;
|
||||
}
|
||||
|
||||
if (theme == "system")
|
||||
{
|
||||
_themeIndex = 2;
|
||||
}
|
||||
}
|
||||
|
||||
private bool _isEnabled;
|
||||
private int _themeIndex;
|
||||
private int _pressTime;
|
||||
private int _opacity;
|
||||
|
||||
public bool IsEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
return _isEnabled;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != _isEnabled)
|
||||
{
|
||||
_isEnabled = value;
|
||||
|
||||
// To update the status of shortcut guide in General PowerToy settings.
|
||||
GeneralSettingsConfig.Enabled.ShortcutGuide = value;
|
||||
OutGoingGeneralSettings snd = new OutGoingGeneralSettings(GeneralSettingsConfig);
|
||||
|
||||
SendConfigMSG(snd.ToString());
|
||||
OnPropertyChanged(nameof(IsEnabled));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int ThemeIndex
|
||||
{
|
||||
get
|
||||
{
|
||||
return _themeIndex;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (_themeIndex != value)
|
||||
{
|
||||
if (value == 0)
|
||||
{
|
||||
// set theme to dark.
|
||||
Settings.Properties.Theme.Value = "dark";
|
||||
_themeIndex = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
|
||||
if (value == 1)
|
||||
{
|
||||
// set theme to light.
|
||||
Settings.Properties.Theme.Value = "light";
|
||||
_themeIndex = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
|
||||
if (value == 2)
|
||||
{
|
||||
// set theme to system default.
|
||||
Settings.Properties.Theme.Value = "system";
|
||||
_themeIndex = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int PressTime
|
||||
{
|
||||
get
|
||||
{
|
||||
return _pressTime;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (_pressTime != value)
|
||||
{
|
||||
_pressTime = value;
|
||||
Settings.Properties.PressTime.Value = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int OverlayOpacity
|
||||
{
|
||||
get
|
||||
{
|
||||
return _opacity;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (_opacity != value)
|
||||
{
|
||||
_opacity = value;
|
||||
Settings.Properties.OverlayOpacity.Value = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string GetSettingsSubPath()
|
||||
{
|
||||
return _settingsConfigFileFolder + "\\" + ModuleName;
|
||||
}
|
||||
|
||||
public void NotifyPropertyChanged([CallerMemberName] string propertyName = null)
|
||||
{
|
||||
OnPropertyChanged(propertyName);
|
||||
SndShortcutGuideSettings outsettings = new SndShortcutGuideSettings(Settings);
|
||||
SndModuleSettings<SndShortcutGuideSettings> ipcMessage = new SndModuleSettings<SndShortcutGuideSettings>(outsettings);
|
||||
SendConfigMSG(ipcMessage.ToJsonString());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user