/ src / settings-ui / Settings.UI.Library / HostsSettings.cs
HostsSettings.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.Text.Json;
 7  using System.Text.Json.Serialization;
 8  
 9  using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
10  
11  namespace Microsoft.PowerToys.Settings.UI.Library
12  {
13      public class HostsSettings : BasePTModuleSettings, ISettingsConfig
14      {
15          public const string ModuleName = "Hosts";
16  
17          private static readonly JsonSerializerOptions _serializerOptions = new JsonSerializerOptions
18          {
19              WriteIndented = true,
20          };
21  
22          [JsonPropertyName("properties")]
23          public HostsProperties Properties { get; set; }
24  
25          public HostsSettings()
26          {
27              Properties = new HostsProperties();
28              Version = "1.0";
29              Name = ModuleName;
30          }
31  
32          public virtual void Save(SettingsUtils settingsUtils)
33          {
34              // Save settings to file
35              var options = _serializerOptions;
36  
37              ArgumentNullException.ThrowIfNull(settingsUtils);
38  
39              settingsUtils.SaveSettings(JsonSerializer.Serialize(this, options), ModuleName);
40          }
41  
42          public string GetModuleName() => Name;
43  
44          public bool UpgradeSettingsConfiguration() => false;
45      }
46  }