PowerLauncherSettings.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 PowerLauncherSettings : BasePTModuleSettings, ISettingsConfig, IHotkeyConfig 16 { 17 public const string ModuleName = "PowerToys Run"; 18 19 private static readonly JsonSerializerOptions _serializerOptions = new JsonSerializerOptions 20 { 21 WriteIndented = true, 22 DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, 23 }; 24 25 [JsonPropertyName("properties")] 26 public PowerLauncherProperties Properties { get; set; } 27 28 [JsonPropertyName("plugins")] 29 public IEnumerable<PowerLauncherPluginSettings> Plugins { get; set; } = new List<PowerLauncherPluginSettings>(); 30 31 public PowerLauncherSettings() 32 { 33 Properties = new PowerLauncherProperties(); 34 Version = "1.0"; 35 Name = ModuleName; 36 } 37 38 public virtual void Save(SettingsUtils settingsUtils) 39 { 40 // Save settings to file 41 var options = _serializerOptions; 42 43 ArgumentNullException.ThrowIfNull(settingsUtils); 44 45 settingsUtils.SaveSettings(JsonSerializer.Serialize(this, options), ModuleName); 46 } 47 48 public string GetModuleName() 49 { 50 return Name; 51 } 52 53 public ModuleType GetModuleType() => ModuleType.PowerLauncher; 54 55 public HotkeyAccessor[] GetAllHotkeyAccessors() 56 { 57 var hotkeyAccessors = new List<HotkeyAccessor> 58 { 59 new HotkeyAccessor( 60 () => Properties.OpenPowerLauncher, 61 value => Properties.OpenPowerLauncher = value ?? Properties.DefaultOpenPowerLauncher, 62 "PowerLauncher_OpenPowerLauncher"), 63 }; 64 65 return hotkeyAccessors.ToArray(); 66 } 67 68 // This can be utilized in the future if the settings.json file is to be modified/deleted. 69 public bool UpgradeSettingsConfiguration() 70 { 71 return false; 72 } 73 } 74 }