Merge pull request #29787 from peppy/fix-restart-notifications

Fix restart notifications appearing every 30 minutes in some cases
This commit is contained in:
Dean Herbert 2024-09-11 02:59:59 +09:00 committed by GitHub
commit 02f8f226f8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 12 additions and 6 deletions

View File

@ -45,14 +45,17 @@ private void load(INotificationOverlay notifications)
private async Task<bool> checkForUpdateAsync(UpdateProgressNotification? notification = null)
{
// should we schedule a retry on completion of this check?
bool scheduleRecheck = true;
// whether to check again in 30 minutes. generally only if there's an error or no update was found (yet).
bool scheduleRecheck = false;
try
{
// Avoid any kind of update checking while gameplay is running.
if (localUserInfo?.IsPlaying.Value == true)
{
scheduleRecheck = true;
return false;
}
// TODO: we should probably be checking if there's a more recent update, rather than shortcutting here.
// Velopack does support this scenario (see https://github.com/ppy/osu/pull/28743#discussion_r1743495975).
@ -67,17 +70,20 @@ private async Task<bool> checkForUpdateAsync(UpdateProgressNotification? notific
return true;
}
});
return true;
}
pendingUpdate = await updateManager.CheckForUpdatesAsync().ConfigureAwait(false);
// Handle no updates available.
// No update is available. We'll check again later.
if (pendingUpdate == null)
{
scheduleRecheck = true;
return false;
}
scheduleRecheck = false;
// An update is found, let's notify the user and start downloading it.
if (notification == null)
{
notification = new UpdateProgressNotification
@ -99,6 +105,7 @@ private async Task<bool> checkForUpdateAsync(UpdateProgressNotification? notific
catch (Exception e)
{
// In the case of an error, a separate notification will be displayed.
scheduleRecheck = true;
notification.FailDownload();
Logger.Error(e, @"update failed!");
}
@ -113,7 +120,6 @@ private async Task<bool> checkForUpdateAsync(UpdateProgressNotification? notific
{
if (scheduleRecheck)
{
// check again in 30 minutes.
Scheduler.AddDelayed(() => Task.Run(async () => await checkForUpdateAsync().ConfigureAwait(false)), 60000 * 30);
}
}