Skip to content

Commit

Permalink
Avoid updates and update notifications appearing in more gameplay cases
Browse files Browse the repository at this point in the history
  • Loading branch information
peppy committed Oct 1, 2024
1 parent 3d54f4a commit 4b1c2c0
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions osu.Desktop/Updater/VelopackUpdateManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public partial class VelopackUpdateManager : Game.Updater.UpdateManager
[Resolved]
private ILocalUserPlayInfo? localUserInfo { get; set; }

private bool isInGameplay => localUserInfo?.PlayingState.Value != LocalUserPlayingStates.NotPlaying;

private UpdateInfo? pendingUpdate;

public VelopackUpdateManager()
Expand All @@ -51,7 +53,7 @@ private async Task<bool> checkForUpdateAsync(UpdateProgressNotification? notific
try
{
// Avoid any kind of update checking while gameplay is running.
if (localUserInfo?.IsPlaying.Value == true)
if (isInGameplay)
{
scheduleRecheck = true;
return false;
Expand All @@ -61,14 +63,17 @@ private async Task<bool> checkForUpdateAsync(UpdateProgressNotification? notific
// Velopack does support this scenario (see https://github.com/ppy/osu/pull/28743#discussion_r1743495975).
if (pendingUpdate != null)
{
// If there is an update pending restart, show the notification to restart again.
notificationOverlay.Post(new UpdateApplicationCompleteNotification
runOutsideOfGameplay(() =>
{
Activated = () =>
// If there is an update pending restart, show the notification to restart again.
notificationOverlay.Post(new UpdateApplicationCompleteNotification
{
Task.Run(restartToApplyUpdate);
return true;
}
Activated = () =>
{
Task.Run(restartToApplyUpdate);
return true;
}
});
});

return true;
Expand Down Expand Up @@ -104,7 +109,7 @@ private async Task<bool> checkForUpdateAsync(UpdateProgressNotification? notific
{
await updateManager.DownloadUpdatesAsync(pendingUpdate, p => notification.Progress = p / 100f).ConfigureAwait(false);

notification.State = ProgressNotificationState.Completed;
runOutsideOfGameplay(() => notification.State = ProgressNotificationState.Completed);
}
catch (Exception e)
{
Expand All @@ -131,6 +136,17 @@ private async Task<bool> checkForUpdateAsync(UpdateProgressNotification? notific
return true;
}

private void runOutsideOfGameplay(Action action)
{
if (isInGameplay)
{
Scheduler.AddDelayed(() => runOutsideOfGameplay(action), 1000);
return;
}

action();
}

private async Task restartToApplyUpdate()
{
await updateManager.WaitExitThenApplyUpdatesAsync(pendingUpdate?.TargetFullRelease).ConfigureAwait(false);
Expand Down

0 comments on commit 4b1c2c0

Please sign in to comment.