MouseHighlighterSettings.cs
1 // Copyright (c) Microsoft Corporation 2 // The Microsoft Corporation licenses this file to you under the MIT license. 3 // See the LICENSE file in the project root for more information. 4 5 using System.Collections.Generic; 6 using System.Globalization; 7 using System.Runtime.InteropServices; 8 using System.Text.Json.Serialization; 9 using ManagedCommon; 10 using Microsoft.PowerToys.Settings.UI.Library.Helpers; 11 using Microsoft.PowerToys.Settings.UI.Library.Interfaces; 12 13 namespace Microsoft.PowerToys.Settings.UI.Library 14 { 15 public class MouseHighlighterSettings : BasePTModuleSettings, ISettingsConfig, IHotkeyConfig 16 { 17 public const string ModuleName = "MouseHighlighter"; 18 19 [JsonPropertyName("properties")] 20 public MouseHighlighterProperties Properties { get; set; } 21 22 public MouseHighlighterSettings() 23 { 24 Name = ModuleName; 25 Properties = new MouseHighlighterProperties(); 26 Version = "1.2"; 27 } 28 29 public string GetModuleName() 30 { 31 return Name; 32 } 33 34 public ModuleType GetModuleType() => ModuleType.MouseHighlighter; 35 36 public HotkeyAccessor[] GetAllHotkeyAccessors() 37 { 38 var hotkeyAccessors = new List<HotkeyAccessor> 39 { 40 new HotkeyAccessor( 41 () => Properties.ActivationShortcut, 42 value => Properties.ActivationShortcut = value ?? Properties.DefaultActivationShortcut, 43 "MouseUtils_MouseHighlighter_ActivationShortcut"), 44 }; 45 46 return hotkeyAccessors.ToArray(); 47 } 48 49 // This can be utilized in the future if the settings.json file is to be modified/deleted. 50 public bool UpgradeSettingsConfiguration() 51 { 52 if (Version == "1.0" || Version == "1.1") 53 { 54 string opacity; 55 if (Version == "1.0") 56 { 57 opacity = string.Format(CultureInfo.InvariantCulture, "{0:X2}", Properties.HighlightOpacity.Value); 58 } 59 else 60 { 61 // 1.1 62 opacity = string.Format(CultureInfo.InvariantCulture, "{0:X2}", Properties.HighlightOpacity.Value * 255 / 100); 63 } 64 65 Properties.LeftButtonClickColor = new StringProperty(string.Concat("#", opacity, Properties.LeftButtonClickColor.Value.ToString().Substring(1, 6))); 66 Properties.RightButtonClickColor = new StringProperty(string.Concat("#", opacity, Properties.RightButtonClickColor.Value.ToString().Substring(1, 6))); 67 Version = "1.2"; 68 return true; 69 } 70 71 return false; 72 } 73 } 74 }