Skip to content

Commit 7b7a5e2

Browse files
authored
fix(updates): persist background check timestamp (#242)
1 parent 1859a51 commit 7b7a5e2

3 files changed

Lines changed: 17 additions & 14 deletions

File tree

src/Foundry/Services/Settings/JsonAppSettingsService.cs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ namespace Foundry.Services.Settings;
1919
internal sealed partial class JsonAppSettingsService : IAppSettingsService
2020
{
2121
private readonly ILogger logger;
22+
private readonly object saveLock = new();
2223

2324
/// <summary>
2425
/// Initializes a new instance of the <see cref="JsonAppSettingsService"/> class.
@@ -46,16 +47,19 @@ public JsonAppSettingsService(ILogger logger)
4647
/// <inheritdoc />
4748
public void Save()
4849
{
49-
try
50+
lock (saveLock)
5051
{
51-
Directory.CreateDirectory(Constants.SettingsDirectoryPath);
52-
string json = JsonSerializer.Serialize(Current, FoundryAppSettingsJsonContext.Default.FoundryAppSettings);
53-
File.WriteAllText(Constants.AppSettingsPath, json);
54-
}
55-
catch (Exception ex)
56-
{
57-
logger.Error(ex, "Failed to save app settings. SettingsPath={SettingsPath}", Constants.AppSettingsPath);
58-
throw;
52+
try
53+
{
54+
Directory.CreateDirectory(Constants.SettingsDirectoryPath);
55+
string json = JsonSerializer.Serialize(Current, FoundryAppSettingsJsonContext.Default.FoundryAppSettings);
56+
File.WriteAllText(Constants.AppSettingsPath, json);
57+
}
58+
catch (Exception ex)
59+
{
60+
logger.Error(ex, "Failed to save app settings. SettingsPath={SettingsPath}", Constants.AppSettingsPath);
61+
throw;
62+
}
5963
}
6064
}
6165

src/Foundry/Services/Updates/ApplicationUpdateService.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,9 @@ private void ClearPendingUpdate()
316316

317317
private ApplicationUpdateCheckResult PublishCheckResult(ApplicationUpdateCheckResult result)
318318
{
319+
appSettingsService.Current.Updates.LastCheckedAt = DateTimeOffset.Now;
320+
appSettingsService.Save();
321+
319322
updateStateService.Publish(result);
320323
return result;
321324
}

src/Foundry/ViewModels/Settings/AppUpdateSettingViewModel.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,6 @@ private async Task CheckForUpdateAsync()
131131
try
132132
{
133133
ApplicationUpdateCheckResult result = await applicationUpdateService.CheckForUpdatesAsync();
134-
DateTimeOffset checkedAt = DateTimeOffset.Now;
135-
appSettingsService.Current.Updates.LastCheckedAt = checkedAt;
136-
appSettingsService.Save();
137-
138-
LastUpdateCheck = FormatLastUpdateCheck(checkedAt);
139134
ApplyCurrentUpdateState(result);
140135
}
141136
finally
@@ -242,6 +237,7 @@ private void OnLanguageChanged(object? sender, ApplicationLanguageChangedEventAr
242237
private void ApplyCurrentUpdateState(ApplicationUpdateCheckResult? result)
243238
{
244239
currentCheckResult = result;
240+
LastUpdateCheck = FormatLastUpdateCheck(appSettingsService.Current.Updates.LastCheckedAt);
245241

246242
if (result is null)
247243
{

0 commit comments

Comments
 (0)