mirror of
https://github.com/wwiinnddyy/LanMountainDesktop.git
synced 2026-06-22 17:24:27 +08:00
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.
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -514,3 +514,4 @@ nul
|
|||||||
/*.AppImage
|
/*.AppImage
|
||||||
/velopack-output-local-verify
|
/velopack-output-local-verify
|
||||||
/velopack-output-local
|
/velopack-output-local
|
||||||
|
/test-aot-publish
|
||||||
|
|||||||
@@ -38,4 +38,5 @@ namespace LanMountainDesktop.Launcher;
|
|||||||
[JsonSerializable(typeof(GitHubRelease))]
|
[JsonSerializable(typeof(GitHubRelease))]
|
||||||
[JsonSerializable(typeof(GitHubAsset))]
|
[JsonSerializable(typeof(GitHubAsset))]
|
||||||
[JsonSerializable(typeof(List<GitHubRelease>))]
|
[JsonSerializable(typeof(List<GitHubRelease>))]
|
||||||
|
[JsonSerializable(typeof(StartupAttemptRecord))]
|
||||||
internal sealed partial class AppJsonContext : JsonSerializerContext;
|
internal sealed partial class AppJsonContext : JsonSerializerContext;
|
||||||
|
|||||||
@@ -10,10 +10,6 @@ namespace LanMountainDesktop.Launcher.Services;
|
|||||||
internal sealed class StartupAttemptRegistry
|
internal sealed class StartupAttemptRegistry
|
||||||
{
|
{
|
||||||
private static readonly TimeSpan CoordinatorHeartbeatTimeout = TimeSpan.FromSeconds(10);
|
private static readonly TimeSpan CoordinatorHeartbeatTimeout = TimeSpan.FromSeconds(10);
|
||||||
private static readonly JsonSerializerOptions SerializerOptions = new()
|
|
||||||
{
|
|
||||||
WriteIndented = true
|
|
||||||
};
|
|
||||||
|
|
||||||
private readonly string _statePath;
|
private readonly string _statePath;
|
||||||
private readonly string _mutexName;
|
private readonly string _mutexName;
|
||||||
@@ -429,7 +425,7 @@ internal sealed class StartupAttemptRegistry
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
var json = File.ReadAllText(_statePath);
|
var json = File.ReadAllText(_statePath);
|
||||||
return JsonSerializer.Deserialize<StartupAttemptRecord>(json, SerializerOptions);
|
return JsonSerializer.Deserialize(json, AppJsonContext.Default.StartupAttemptRecord);
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
@@ -445,7 +441,7 @@ internal sealed class StartupAttemptRegistry
|
|||||||
Directory.CreateDirectory(directory);
|
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)
|
private static bool IsAttachable(StartupAttemptRecord record)
|
||||||
|
|||||||
Reference in New Issue
Block a user