PowerOcrSettings.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; 6 using System.Collections.Generic; 7 using System.Text.Json; 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 PowerOcrSettings : BasePTModuleSettings, ISettingsConfig, IHotkeyConfig 16 { 17 public const string ModuleName = "TextExtractor"; 18 19 private static readonly JsonSerializerOptions _serializerOptions = new JsonSerializerOptions 20 { 21 WriteIndented = true, 22 }; 23 24 [JsonPropertyName("properties")] 25 public PowerOcrProperties Properties { get; set; } 26 27 public PowerOcrSettings() 28 { 29 Properties = new PowerOcrProperties(); 30 Version = "1"; 31 Name = ModuleName; 32 } 33 34 public virtual void Save(SettingsUtils settingsUtils) 35 { 36 // Save settings to file 37 var options = _serializerOptions; 38 39 ArgumentNullException.ThrowIfNull(settingsUtils); 40 41 settingsUtils.SaveSettings(JsonSerializer.Serialize(this, options), ModuleName); 42 } 43 44 public string GetModuleName() 45 => Name; 46 47 public ModuleType GetModuleType() => ModuleType.PowerOCR; 48 49 public HotkeyAccessor[] GetAllHotkeyAccessors() 50 { 51 var hotkeyAccessors = new List<HotkeyAccessor> 52 { 53 new HotkeyAccessor( 54 () => Properties.ActivationShortcut, 55 value => Properties.ActivationShortcut = value ?? Properties.DefaultActivationShortcut, 56 "Activation_Shortcut"), 57 }; 58 59 return hotkeyAccessors.ToArray(); 60 } 61 62 // This can be utilized in the future if the settings.json file is to be modified/deleted. 63 public bool UpgradeSettingsConfiguration() 64 => false; 65 } 66 }