From 8b8c7d1e7f6172fe11a3629b0cd1e1cd516bffea Mon Sep 17 00:00:00 2001 From: lincube Date: Fri, 24 Apr 2026 20:55:33 +0800 Subject: [PATCH] Use AppJsonContext for startup state serialization Switch serialization to the source-generated System.Text.Json context: add JsonSerializable(typeof(StartupAttemptRecord)) to AppJsonContext and replace the previous JsonSerializerOptions-based Serialize/Deserialize calls with AppJsonContext.Default.StartupAttemptRecord. Also remove the now-unused SerializerOptions field. Additionally, update .gitignore to exclude /test-aot-publish. --- .gitignore | 1 + LanMountainDesktop.Launcher/AppJsonContext.cs | 1 + .../Services/StartupAttemptRegistry.cs | 8 ++------ 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index cb9265e..a2037bb 100644 --- a/.gitignore +++ b/.gitignore @@ -514,3 +514,4 @@ nul /*.AppImage /velopack-output-local-verify /velopack-output-local +/test-aot-publish diff --git a/LanMountainDesktop.Launcher/AppJsonContext.cs b/LanMountainDesktop.Launcher/AppJsonContext.cs index 495e3f8..cb8571e 100644 --- a/LanMountainDesktop.Launcher/AppJsonContext.cs +++ b/LanMountainDesktop.Launcher/AppJsonContext.cs @@ -38,4 +38,5 @@ namespace LanMountainDesktop.Launcher; [JsonSerializable(typeof(GitHubRelease))] [JsonSerializable(typeof(GitHubAsset))] [JsonSerializable(typeof(List))] +[JsonSerializable(typeof(StartupAttemptRecord))] internal sealed partial class AppJsonContext : JsonSerializerContext; diff --git a/LanMountainDesktop.Launcher/Services/StartupAttemptRegistry.cs b/LanMountainDesktop.Launcher/Services/StartupAttemptRegistry.cs index a6d3476..6291c58 100644 --- a/LanMountainDesktop.Launcher/Services/StartupAttemptRegistry.cs +++ b/LanMountainDesktop.Launcher/Services/StartupAttemptRegistry.cs @@ -10,10 +10,6 @@ namespace LanMountainDesktop.Launcher.Services; internal sealed class StartupAttemptRegistry { private static readonly TimeSpan CoordinatorHeartbeatTimeout = TimeSpan.FromSeconds(10); - private static readonly JsonSerializerOptions SerializerOptions = new() - { - WriteIndented = true - }; private readonly string _statePath; private readonly string _mutexName; @@ -429,7 +425,7 @@ internal sealed class StartupAttemptRegistry try { var json = File.ReadAllText(_statePath); - return JsonSerializer.Deserialize(json, SerializerOptions); + return JsonSerializer.Deserialize(json, AppJsonContext.Default.StartupAttemptRecord); } catch { @@ -445,7 +441,7 @@ internal sealed class StartupAttemptRegistry Directory.CreateDirectory(directory); } - File.WriteAllText(_statePath, JsonSerializer.Serialize(record, SerializerOptions)); + File.WriteAllText(_statePath, JsonSerializer.Serialize(record, AppJsonContext.Default.StartupAttemptRecord)); } private static bool IsAttachable(StartupAttemptRecord record)