Fix completion notification not being posted if completion occurs during NotificationOverlay load

This commit is contained in:
Dean Herbert
2022-09-06 04:07:49 +09:00
parent 510972e3ad
commit 9e3228aa65
3 changed files with 26 additions and 13 deletions

View File

@ -71,7 +71,7 @@ namespace osu.Game.Overlays.Notifications
base.LoadComplete();
// we may have received changes before we were displayed.
updateState();
Scheduler.AddOnce(updateState);
}
private readonly CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
@ -87,13 +87,8 @@ namespace osu.Game.Overlays.Notifications
state = value;
if (IsLoaded)
{
Schedule(updateState);
if (state == ProgressNotificationState.Completed)
CompletionTarget?.Invoke(CreateCompletionNotification());
}
Scheduler.AddOnce(updateState);
attemptPostCompletion();
}
}
@ -146,11 +141,33 @@ namespace osu.Game.Overlays.Notifications
case ProgressNotificationState.Completed:
loadingSpinner.Hide();
attemptPostCompletion();
base.Close();
break;
}
}
private bool completionSent;
/// <summary>
/// Attempt to post a completion notification.
/// </summary>
private void attemptPostCompletion()
{
if (state != ProgressNotificationState.Completed) return;
// This notification may not have been posted yet (and thus may not have a target to post the completion to).
// Completion posting will be re-attempted in a scheduled invocation.
if (CompletionTarget == null)
return;
if (completionSent)
return;
CompletionTarget.Invoke(CreateCompletionNotification());
completionSent = true;
}
private ProgressNotificationState state;
protected virtual Notification CreateCompletionNotification() => new ProgressCompletionNotification