mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-03 09:46:54 +02:00
<!-- Enter a brief description/summary of your PR here. What does it fix/what does it change/how was it tested (even manually, if necessary)? --> ## Summary of the Pull Request This PR removes the ISettingsUtils and ISettingsPath interfaces to reduce some complexity. They only existed so the classes can be used with moq. But this is also possible by using virtual methods which is cleaner. <!-- Please review the items on the PR checklist before submitting--> ## PR Checklist - [ ] Closes: #xxx <!-- - [ ] Closes: #yyy (add separate lines for additional resolved issues) --> - [ ] **Communication:** I've discussed this with core contributors already. If the work hasn't been agreed, this work might be rejected - [x] **Tests:** Added/updated and all pass - [ ] **Localization:** All end-user-facing strings can be localized - [ ] **Dev docs:** Added/updated - [ ] **New binaries:** Added on the required places - [ ] [JSON for signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json) for new binaries - [ ] [WXS for installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs) for new binaries and localization folder - [ ] [YML for CI pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml) for new test projects - [ ] [YML for signed pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml) - [ ] **Documentation updated:** If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys) and link it here: #xxx
140 lines
5.9 KiB
C#
140 lines
5.9 KiB
C#
// Copyright (c) Microsoft Corporation
|
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
|
// See the LICENSE file in the project root for more information.
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text.Json;
|
|
using System.Text.Json.Serialization;
|
|
using ManagedCommon;
|
|
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
|
|
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
|
|
using MouseJump.Common.Helpers;
|
|
using MouseJump.Common.Models.Settings;
|
|
|
|
namespace Microsoft.PowerToys.Settings.UI.Library
|
|
{
|
|
public class MouseJumpSettings : BasePTModuleSettings, ISettingsConfig, IHotkeyConfig
|
|
{
|
|
public const string ModuleName = "MouseJump";
|
|
|
|
private static readonly JsonSerializerOptions _serializerOptions = new JsonSerializerOptions
|
|
{
|
|
WriteIndented = true,
|
|
};
|
|
|
|
[JsonPropertyName("properties")]
|
|
public MouseJumpProperties Properties { get; set; }
|
|
|
|
public MouseJumpSettings()
|
|
{
|
|
Name = ModuleName;
|
|
Properties = new MouseJumpProperties();
|
|
Version = "1.1";
|
|
}
|
|
|
|
public void Save(SettingsUtils settingsUtils)
|
|
{
|
|
// Save settings to file
|
|
var options = _serializerOptions;
|
|
|
|
ArgumentNullException.ThrowIfNull(settingsUtils);
|
|
|
|
settingsUtils.SaveSettings(JsonSerializer.Serialize(this, options), ModuleName);
|
|
}
|
|
|
|
public string GetModuleName()
|
|
{
|
|
return Name;
|
|
}
|
|
|
|
public ModuleType GetModuleType() => ModuleType.MouseJump;
|
|
|
|
public HotkeyAccessor[] GetAllHotkeyAccessors()
|
|
{
|
|
var hotkeyAccessors = new List<HotkeyAccessor>
|
|
{
|
|
new HotkeyAccessor(
|
|
() => Properties.ActivationShortcut,
|
|
value => Properties.ActivationShortcut = value ?? Properties.DefaultActivationShortcut,
|
|
"MouseUtils_MouseJump_ActivationShortcut"),
|
|
};
|
|
|
|
return hotkeyAccessors.ToArray();
|
|
}
|
|
|
|
// This can be utilized in the future if the settings.json file is to be modified/deleted.
|
|
public bool UpgradeSettingsConfiguration()
|
|
{
|
|
/*
|
|
v1.0 - initial version
|
|
|
|
* DefaultActivationShortcut
|
|
* activation_shortcut
|
|
* thumbnail_size
|
|
* name
|
|
* version
|
|
*/
|
|
var upgraded = false;
|
|
|
|
if (this.Version == "1.0")
|
|
{
|
|
/*
|
|
v1.1 - added preview style settings
|
|
|
|
* preview_type
|
|
* background_color_1
|
|
* background_color_2
|
|
* border_thickness
|
|
* border_color
|
|
* border_3d_depth
|
|
* border_padding
|
|
* bezel_thickness
|
|
* bezel_color
|
|
* bezel_3d_depth
|
|
* screen_margin
|
|
* screen_color_1
|
|
* screen_color_2
|
|
*/
|
|
this.Version = "1.1";
|
|
|
|
// note - there's an issue where ITwoWayPipeMessageIPCManagedMethods.Send overwrites
|
|
// the settings file version as "1.0" regardless of the actual version. as a result,
|
|
// the UpgradeSettingsConfiguration can get triggered even if the config has already
|
|
// been upgraded, so we need to do an additional check to make sure values haven't
|
|
// already been upgraded before we overwrite them with default values.
|
|
if (string.IsNullOrEmpty(this.Properties.PreviewType))
|
|
{
|
|
// set default values for custom preview style
|
|
var previewStyle = StyleHelper.BezelledPreviewStyle;
|
|
this.Properties.PreviewType = PreviewType.Bezelled.ToString();
|
|
this.Properties.BackgroundColor1 = ConfigHelper.SerializeToConfigColorString(
|
|
ConfigHelper.ToUnnamedColor(previewStyle.CanvasStyle.BackgroundStyle.Color1));
|
|
this.Properties.BackgroundColor2 = ConfigHelper.SerializeToConfigColorString(
|
|
ConfigHelper.ToUnnamedColor(previewStyle.CanvasStyle.BackgroundStyle.Color2));
|
|
this.Properties.BorderThickness = (int)previewStyle.CanvasStyle.BorderStyle.Top;
|
|
this.Properties.BorderColor = ConfigHelper.SerializeToConfigColorString(
|
|
ConfigHelper.ToUnnamedColor(previewStyle.CanvasStyle.BorderStyle.Color));
|
|
this.Properties.Border3dDepth = (int)previewStyle.CanvasStyle.BorderStyle.Depth;
|
|
this.Properties.BorderPadding = (int)previewStyle.CanvasStyle.PaddingStyle.Top;
|
|
this.Properties.BezelThickness = (int)previewStyle.ScreenStyle.BorderStyle.Top;
|
|
this.Properties.BezelColor = ConfigHelper.SerializeToConfigColorString(
|
|
ConfigHelper.ToUnnamedColor(previewStyle.ScreenStyle.BorderStyle.Color));
|
|
this.Properties.Bezel3dDepth = (int)previewStyle.ScreenStyle.BorderStyle.Depth;
|
|
this.Properties.ScreenMargin = (int)previewStyle.ScreenStyle.MarginStyle.Top;
|
|
this.Properties.ScreenColor1 = ConfigHelper.SerializeToConfigColorString(
|
|
ConfigHelper.ToUnnamedColor(previewStyle.ScreenStyle.BackgroundStyle.Color1));
|
|
this.Properties.ScreenColor2 = ConfigHelper.SerializeToConfigColorString(
|
|
ConfigHelper.ToUnnamedColor(previewStyle.ScreenStyle.BackgroundStyle.Color2));
|
|
}
|
|
|
|
// we still need to flag the settings as "upgraded" so that the new version gets written
|
|
// back to the config file, even if we didn't actually change and setting values
|
|
upgraded = true;
|
|
}
|
|
|
|
return upgraded;
|
|
}
|
|
}
|
|
}
|