/ src / settings-ui / Settings.UI.Library / WorkspacesSettings.cs
WorkspacesSettings.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 WorkspacesSettings : BasePTModuleSettings, ISettingsConfig, IHotkeyConfig
16      {
17          public const string ModuleName = "Workspaces";
18          public const string ModuleVersion = "0.0.1";
19          private static readonly JsonSerializerOptions _serializerOptions = new JsonSerializerOptions
20          {
21              WriteIndented = true,
22          };
23  
24          public WorkspacesSettings()
25          {
26              Name = ModuleName;
27              Version = ModuleVersion;
28              Properties = new WorkspacesProperties();
29          }
30  
31          [JsonPropertyName("properties")]
32          public WorkspacesProperties Properties { get; set; }
33  
34          public string GetModuleName()
35          {
36              return Name;
37          }
38  
39          public bool UpgradeSettingsConfiguration()
40          {
41              return false;
42          }
43  
44          public ModuleType GetModuleType() => ModuleType.Workspaces;
45  
46          public HotkeyAccessor[] GetAllHotkeyAccessors()
47          {
48              var hotkeyAccessors = new List<HotkeyAccessor>
49              {
50                  new HotkeyAccessor(
51                      () => Properties.Hotkey.Value,
52                      value => Properties.Hotkey.Value = value ?? WorkspacesProperties.DefaultHotkeyValue,
53                      "Workspaces_ActivationShortcut"),
54              };
55  
56              return hotkeyAccessors.ToArray();
57          }
58  
59          public virtual void Save(SettingsUtils settingsUtils)
60          {
61              // Save settings to file
62              var options = _serializerOptions;
63  
64              ArgumentNullException.ThrowIfNull(settingsUtils);
65  
66              settingsUtils.SaveSettings(JsonSerializer.Serialize(this, options), ModuleName);
67          }
68      }
69  }