-
Notifications
You must be signed in to change notification settings - Fork 6.9k
/
Copy pathMouseWithoutBordersSettings.cs
109 lines (89 loc) · 3.72 KB
/
MouseWithoutBordersSettings.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// 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.Text.Json;
using System.Text.Json.Serialization;
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
namespace Microsoft.PowerToys.Settings.UI.Library
{
public class MouseWithoutBordersSettings : BasePTModuleSettings, ISettingsConfig
{
public const string ModuleName = "MouseWithoutBorders";
private static readonly JsonSerializerOptions _serializerOptions = new JsonSerializerOptions
{
WriteIndented = true,
MaxDepth = 0,
IncludeFields = true,
};
[JsonPropertyName("properties")]
public MouseWithoutBordersProperties Properties { get; set; }
public MouseWithoutBordersSettings()
{
Name = ModuleName;
Properties = new MouseWithoutBordersProperties();
Version = "1.1";
}
public string GetModuleName()
{
return Name;
}
public HotkeySettings ConvertMouseWithoutBordersHotKeyToPowerToys(int value)
{
// VK_A <= value <= VK_Z
if (value >= 0x41 && value <= 0x5A)
{
return new HotkeySettings(false, true, true, false, value);
}
else
{
// Disabled state
return new HotkeySettings(false, false, false, false, 0);
}
}
// This can be utilized in the future if the settings.json file is to be modified/deleted.
public bool UpgradeSettingsConfiguration()
{
#pragma warning disable CS0618 // We use obsolete members to upgrade them
bool downgradedThenUpgraded = Version != "1.0" && (Properties.HotKeyToggleEasyMouse != null ||
Properties.HotKeyLockMachine != null ||
Properties.HotKeyReconnect != null ||
Properties.HotKeySwitch2AllPC != null);
if (Version == "1.0" || downgradedThenUpgraded)
{
Version = "1.1";
if (Properties.HotKeyToggleEasyMouse != null)
{
Properties.ToggleEasyMouseShortcut = ConvertMouseWithoutBordersHotKeyToPowerToys(Properties.HotKeyToggleEasyMouse.Value);
}
if (Properties.HotKeyLockMachine != null)
{
Properties.LockMachineShortcut = ConvertMouseWithoutBordersHotKeyToPowerToys(Properties.HotKeyLockMachine.Value);
}
if (Properties.HotKeyReconnect != null)
{
Properties.ReconnectShortcut = ConvertMouseWithoutBordersHotKeyToPowerToys(Properties.HotKeyReconnect.Value);
}
if (Properties.HotKeySwitch2AllPC != null)
{
Properties.Switch2AllPCShortcut = ConvertMouseWithoutBordersHotKeyToPowerToys(Properties.HotKeySwitch2AllPC.Value);
}
Properties.HotKeyToggleEasyMouse = null;
Properties.HotKeyLockMachine = null;
Properties.HotKeyReconnect = null;
Properties.HotKeySwitch2AllPC = null;
return true;
}
return false;
#pragma warning restore CS0618
}
public virtual void Save(ISettingsUtils settingsUtils)
{
// Save settings to file
var options = _serializerOptions;
ArgumentNullException.ThrowIfNull(settingsUtils);
settingsUtils.SaveSettings(JsonSerializer.Serialize(this, options), ModuleName);
}
}
}