Skip to content

Commit

Permalink
Merge pull request #29787 from peppy/fix-restart-notifications
Browse files Browse the repository at this point in the history
Fix restart notifications appearing every 30 minutes in some cases
  • Loading branch information
peppy authored Sep 10, 2024
2 parents 1037fbb + 19e4cc8 commit 02f8f22
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions osu.Desktop/Updater/VelopackUpdateManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand All @@ -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
Expand All @@ -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!");
}
Expand All @@ -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);
}
}
Expand Down

0 comments on commit 02f8f22

Please sign in to comment.