diff --git a/src/modules/poweraccent/PowerAccent.Core/PowerAccent.Core.csproj b/src/modules/poweraccent/PowerAccent.Core/PowerAccent.Core.csproj index c98f2c9b30ff..95ee5b626fa9 100644 --- a/src/modules/poweraccent/PowerAccent.Core/PowerAccent.Core.csproj +++ b/src/modules/poweraccent/PowerAccent.Core/PowerAccent.Core.csproj @@ -9,6 +9,10 @@ True true true + + true + true + 2 diff --git a/src/modules/poweraccent/PowerAccent.Core/PowerAccent.cs b/src/modules/poweraccent/PowerAccent.Core/PowerAccent.cs index a1802ba428f8..c2f0698f257a 100644 --- a/src/modules/poweraccent/PowerAccent.Core/PowerAccent.cs +++ b/src/modules/poweraccent/PowerAccent.Core/PowerAccent.cs @@ -14,7 +14,7 @@ namespace PowerAccent.Core; -public class PowerAccent : IDisposable +public partial class PowerAccent : IDisposable { private readonly SettingsService _settingService; diff --git a/src/modules/poweraccent/PowerAccent.Core/Services/SettingsService.cs b/src/modules/poweraccent/PowerAccent.Core/Services/SettingsService.cs index b234fcfde41f..099eac14e1bf 100644 --- a/src/modules/poweraccent/PowerAccent.Core/Services/SettingsService.cs +++ b/src/modules/poweraccent/PowerAccent.Core/Services/SettingsService.cs @@ -29,11 +29,6 @@ public SettingsService(KeyboardListener keyboardListener) _watcher = Helper.GetFileWatcher(PowerAccentModuleName, "settings.json", () => { ReadSettings(); }); } - private static readonly JsonSerializerOptions _serializerOptions = new JsonSerializerOptions - { - WriteIndented = true, - }; - private void ReadSettings() { // TODO this IO call should by Async, update GetFileWatcher helper to support async @@ -46,9 +41,8 @@ private void ReadSettings() { Logger.LogInfo("QuickAccent settings.json was missing, creating a new one"); var defaultSettings = new PowerAccentSettings(); - var options = _serializerOptions; - _settingsUtils.SaveSettings(JsonSerializer.Serialize(this, options), PowerAccentModuleName); + _settingsUtils.SaveSettings(JsonSerializer.Serialize(this, SourceGenerationContext.Default.SettingsService), PowerAccentModuleName); } var settings = _settingsUtils.GetSettingsOrDefault(PowerAccentModuleName); diff --git a/src/modules/poweraccent/PowerAccent.Core/Services/SourceGenerationContext.cs b/src/modules/poweraccent/PowerAccent.Core/Services/SourceGenerationContext.cs new file mode 100644 index 000000000000..0b4da67bdda6 --- /dev/null +++ b/src/modules/poweraccent/PowerAccent.Core/Services/SourceGenerationContext.cs @@ -0,0 +1,14 @@ +// Copyright (c) Microsoft Corporation +// The Microsoft Corporation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace PowerAccent.Core.Services +{ + [JsonSourceGenerationOptions(WriteIndented = true)] + [JsonSerializable(typeof(SettingsService))] + public partial class SourceGenerationContext : JsonSerializerContext + { + } +}