mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Ensure auto-update checks happen on startup even if the UI never opens
This commit is contained in:
parent
4c38073431
commit
76f7d9c157
@ -31,6 +31,7 @@ public class UpdateService : IUpdateService
|
|||||||
private readonly IUpdatingClient _updatingClient;
|
private readonly IUpdatingClient _updatingClient;
|
||||||
|
|
||||||
private bool _suspendAutoCheck;
|
private bool _suspendAutoCheck;
|
||||||
|
private DateTime _lastAutoUpdateCheck;
|
||||||
|
|
||||||
public UpdateService(ILogger logger,
|
public UpdateService(ILogger logger,
|
||||||
ISettingsService settingsService,
|
ISettingsService settingsService,
|
||||||
@ -109,6 +110,11 @@ public class UpdateService : IUpdateService
|
|||||||
|
|
||||||
private async void HandleAutoUpdateEvent(object? sender, EventArgs e)
|
private async void HandleAutoUpdateEvent(object? sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
// The event can trigger from multiple sources with a timer acting as a fallback, only actual perform an action once per max 59 minutes
|
||||||
|
if (DateTime.UtcNow - _lastAutoUpdateCheck < TimeSpan.FromMinutes(59))
|
||||||
|
return;
|
||||||
|
_lastAutoUpdateCheck = DateTime.UtcNow;
|
||||||
|
|
||||||
if (!_autoCheck.Value || _suspendAutoCheck)
|
if (!_autoCheck.Value || _suspendAutoCheck)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -148,6 +154,8 @@ public class UpdateService : IUpdateService
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public async Task<bool> CheckForUpdate()
|
public async Task<bool> CheckForUpdate()
|
||||||
{
|
{
|
||||||
|
_logger.Information("Performing auto-update check");
|
||||||
|
|
||||||
IOperationResult<IGetNextReleaseResult> result = await _updatingClient.GetNextRelease.ExecuteAsync(Constants.CurrentVersion, Channel, _updatePlatform);
|
IOperationResult<IGetNextReleaseResult> result = await _updatingClient.GetNextRelease.ExecuteAsync(Constants.CurrentVersion, Channel, _updatePlatform);
|
||||||
result.EnsureNoErrors();
|
result.EnsureNoErrors();
|
||||||
|
|
||||||
@ -161,12 +169,18 @@ public class UpdateService : IUpdateService
|
|||||||
// Unless auto install is enabled, only offer it once per session
|
// Unless auto install is enabled, only offer it once per session
|
||||||
if (!_autoInstall.Value)
|
if (!_autoInstall.Value)
|
||||||
_suspendAutoCheck = true;
|
_suspendAutoCheck = true;
|
||||||
|
|
||||||
// If the window is open show the changelog, don't auto-update while the user is busy
|
// If the window is open show the changelog, don't auto-update while the user is busy
|
||||||
if (_mainWindowService.IsMainWindowOpen || !_autoInstall.Value)
|
if (_mainWindowService.IsMainWindowOpen || !_autoInstall.Value)
|
||||||
|
{
|
||||||
|
_logger.Information("New update available, offering version {AvailableVersion}", CachedLatestRelease.Version);
|
||||||
ShowUpdateNotification(CachedLatestRelease);
|
ShowUpdateNotification(CachedLatestRelease);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
_logger.Information("New update available, auto-installing version {AvailableVersion}", CachedLatestRelease.Version);
|
||||||
await AutoInstallUpdate(CachedLatestRelease);
|
await AutoInstallUpdate(CachedLatestRelease);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -227,6 +241,10 @@ public class UpdateService : IUpdateService
|
|||||||
}
|
}
|
||||||
|
|
||||||
ProcessReleaseStatus();
|
ProcessReleaseStatus();
|
||||||
|
|
||||||
|
// Trigger the auto update event so that it doesn't take an hour for the first check to happen
|
||||||
|
HandleAutoUpdateEvent(this, EventArgs.Empty);
|
||||||
|
|
||||||
_logger.Information("Update service initialized for {Channel} channel", Channel);
|
_logger.Information("Update service initialized for {Channel} channel", Channel);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user