diff --git a/DiscordChatExporter.Cli.Tests/DiscordChatExporter.Cli.Tests.csproj b/DiscordChatExporter.Cli.Tests/DiscordChatExporter.Cli.Tests.csproj index a1ad6476..6f7c2ec5 100644 --- a/DiscordChatExporter.Cli.Tests/DiscordChatExporter.Cli.Tests.csproj +++ b/DiscordChatExporter.Cli.Tests/DiscordChatExporter.Cli.Tests.csproj @@ -20,7 +20,7 @@ - + diff --git a/DiscordChatExporter.Core/DiscordChatExporter.Core.csproj b/DiscordChatExporter.Core/DiscordChatExporter.Core.csproj index c0a434c1..1013a403 100644 --- a/DiscordChatExporter.Core/DiscordChatExporter.Core.csproj +++ b/DiscordChatExporter.Core/DiscordChatExporter.Core.csproj @@ -9,7 +9,7 @@ - + \ No newline at end of file diff --git a/DiscordChatExporter.Gui/DiscordChatExporter.Gui.csproj b/DiscordChatExporter.Gui/DiscordChatExporter.Gui.csproj index 00321377..3eeb1118 100644 --- a/DiscordChatExporter.Gui/DiscordChatExporter.Gui.csproj +++ b/DiscordChatExporter.Gui/DiscordChatExporter.Gui.csproj @@ -5,7 +5,6 @@ DiscordChatExporter ..\favicon.ico true - true $(NoWarn);IL2104 @@ -27,7 +26,7 @@ - + diff --git a/DiscordChatExporter.Gui/Services/SettingsService.cs b/DiscordChatExporter.Gui/Services/SettingsService.cs index 04e40a45..05e72383 100644 --- a/DiscordChatExporter.Gui/Services/SettingsService.cs +++ b/DiscordChatExporter.Gui/Services/SettingsService.cs @@ -1,5 +1,6 @@ using System; using System.IO; +using System.Text.Json.Serialization; using Cogwheel; using CommunityToolkit.Mvvm.ComponentModel; using DiscordChatExporter.Core.Exporting; @@ -8,57 +9,126 @@ using DiscordChatExporter.Gui.Models; namespace DiscordChatExporter.Gui.Services; +// Can't use [ObservableProperty] here because System.Text.Json's source generator doesn't see +// the generated properties. [INotifyPropertyChanged] public partial class SettingsService() - : SettingsBase(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Settings.dat")) + : SettingsBase( + Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Settings.dat"), + SerializerContext.Default + ) { - [ObservableProperty] private bool _isUkraineSupportMessageEnabled = true; + public bool IsUkraineSupportMessageEnabled + { + get => _isUkraineSupportMessageEnabled; + set => SetProperty(ref _isUkraineSupportMessageEnabled, value); + } - [ObservableProperty] private ThemeVariant _theme; + public ThemeVariant Theme + { + get => _theme; + set => SetProperty(ref _theme, value); + } - [ObservableProperty] private bool _isAutoUpdateEnabled = true; + public bool IsAutoUpdateEnabled + { + get => _isAutoUpdateEnabled; + set => SetProperty(ref _isAutoUpdateEnabled, value); + } - [ObservableProperty] private bool _isTokenPersisted = true; + public bool IsTokenPersisted + { + get => _isTokenPersisted; + set => SetProperty(ref _isTokenPersisted, value); + } - [ObservableProperty] private ThreadInclusionMode _threadInclusionMode; + public ThreadInclusionMode ThreadInclusionMode + { + get => _threadInclusionMode; + set => SetProperty(ref _threadInclusionMode, value); + } - [ObservableProperty] private string? _locale; + public string? Locale + { + get => _locale; + set => SetProperty(ref _locale, value); + } - [ObservableProperty] private bool _isUtcNormalizationEnabled; + public bool IsUtcNormalizationEnabled + { + get => _isUtcNormalizationEnabled; + set => SetProperty(ref _isUtcNormalizationEnabled, value); + } - [ObservableProperty] private int _parallelLimit = 1; + public int ParallelLimit + { + get => _parallelLimit; + set => SetProperty(ref _parallelLimit, value); + } - [ObservableProperty] private string? _lastToken; + public string? LastToken + { + get => _lastToken; + set => SetProperty(ref _lastToken, value); + } - [ObservableProperty] private ExportFormat _lastExportFormat = ExportFormat.HtmlDark; + public ExportFormat LastExportFormat + { + get => _lastExportFormat; + set => SetProperty(ref _lastExportFormat, value); + } - [ObservableProperty] private string? _lastPartitionLimitValue; + public string? LastPartitionLimitValue + { + get => _lastPartitionLimitValue; + set => SetProperty(ref _lastPartitionLimitValue, value); + } - [ObservableProperty] private string? _lastMessageFilterValue; + public string? LastMessageFilterValue + { + get => _lastMessageFilterValue; + set => SetProperty(ref _lastMessageFilterValue, value); + } - [ObservableProperty] private bool _lastShouldFormatMarkdown = true; + public bool LastShouldFormatMarkdown + { + get => _lastShouldFormatMarkdown; + set => SetProperty(ref _lastShouldFormatMarkdown, value); + } - [ObservableProperty] private bool _lastShouldDownloadAssets; + public bool LastShouldDownloadAssets + { + get => _lastShouldDownloadAssets; + set => SetProperty(ref _lastShouldDownloadAssets, value); + } - [ObservableProperty] private bool _lastShouldReuseAssets; + public bool LastShouldReuseAssets + { + get => _lastShouldReuseAssets; + set => SetProperty(ref _lastShouldReuseAssets, value); + } - [ObservableProperty] private string? _lastAssetsDirPath; + public string? LastAssetsDirPath + { + get => _lastAssetsDirPath; + set => SetProperty(ref _lastAssetsDirPath, value); + } public override void Save() { @@ -72,3 +142,9 @@ public partial class SettingsService() LastToken = lastToken; } } + +public partial class SettingsService +{ + [JsonSerializable(typeof(SettingsService))] + private partial class SerializerContext : JsonSerializerContext; +}