2023-02-24 13:30:30 +00:00
|
|
|
|
// 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.
|
|
|
|
|
|
|
2023-10-11 15:58:19 +01:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Text.Json;
|
2023-02-24 13:30:30 +00:00
|
|
|
|
using System.Text.Json.Serialization;
|
2024-10-17 05:14:57 -04:00
|
|
|
|
|
2023-02-24 13:30:30 +00:00
|
|
|
|
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
|
2024-11-26 15:37:59 +00:00
|
|
|
|
using MouseJump.Common.Helpers;
|
|
|
|
|
|
using MouseJump.Common.Models.Settings;
|
2023-02-24 13:30:30 +00:00
|
|
|
|
|
|
|
|
|
|
namespace Microsoft.PowerToys.Settings.UI.Library
|
|
|
|
|
|
{
|
|
|
|
|
|
public class MouseJumpSettings : BasePTModuleSettings, ISettingsConfig
|
|
|
|
|
|
{
|
|
|
|
|
|
public const string ModuleName = "MouseJump";
|
|
|
|
|
|
|
2023-12-28 13:37:13 +03:00
|
|
|
|
private static readonly JsonSerializerOptions _serializerOptions = new JsonSerializerOptions
|
|
|
|
|
|
{
|
|
|
|
|
|
WriteIndented = true,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2023-02-24 13:30:30 +00:00
|
|
|
|
[JsonPropertyName("properties")]
|
|
|
|
|
|
public MouseJumpProperties Properties { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
public MouseJumpSettings()
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = ModuleName;
|
|
|
|
|
|
Properties = new MouseJumpProperties();
|
2024-11-26 15:37:59 +00:00
|
|
|
|
Version = "1.1";
|
2023-02-24 13:30:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-10-11 15:58:19 +01:00
|
|
|
|
public void Save(ISettingsUtils settingsUtils)
|
|
|
|
|
|
{
|
|
|
|
|
|
// Save settings to file
|
2023-12-28 13:37:13 +03:00
|
|
|
|
var options = _serializerOptions;
|
2023-10-11 15:58:19 +01:00
|
|
|
|
|
2023-11-22 12:46:59 -05:00
|
|
|
|
ArgumentNullException.ThrowIfNull(settingsUtils);
|
2023-10-11 15:58:19 +01:00
|
|
|
|
|
|
|
|
|
|
settingsUtils.SaveSettings(JsonSerializer.Serialize(this, options), ModuleName);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-02-24 13:30:30 +00:00
|
|
|
|
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()
|
|
|
|
|
|
{
|
2024-11-26 15:37:59 +00:00
|
|
|
|
/*
|
|
|
|
|
|
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;
|
2023-02-24 13:30:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|