Move UpdateProgressNotification to base UpdateManager class

This commit is contained in:
Dean Herbert
2022-09-12 14:52:11 +09:00
parent aa823161f1
commit eca241e9a7
2 changed files with 99 additions and 85 deletions

View File

@ -1,16 +1,16 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
#nullable disable
using System.Threading.Tasks;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Game.Configuration;
using osu.Game.Graphics;
using osu.Game.Overlays;
using osu.Game.Overlays.Notifications;
using osuTK;
namespace osu.Game.Updater
{
@ -27,13 +27,13 @@ namespace osu.Game.Updater
GetType() != typeof(UpdateManager);
[Resolved]
private OsuConfigManager config { get; set; }
private OsuConfigManager config { get; set; } = null!;
[Resolved]
private OsuGameBase game { get; set; }
private OsuGameBase game { get; set; } = null!;
[Resolved]
protected INotificationOverlay Notifications { get; private set; }
protected INotificationOverlay Notifications { get; private set; } = null!;
protected override void LoadComplete()
{
@ -59,7 +59,7 @@ namespace osu.Game.Updater
private readonly object updateTaskLock = new object();
private Task<bool> updateCheckTask;
private Task<bool>? updateCheckTask;
public async Task<bool> CheckForUpdateAsync()
{
@ -109,5 +109,65 @@ namespace osu.Game.Updater
};
}
}
protected class UpdateApplicationCompleteNotification : ProgressCompletionNotification
{
public UpdateApplicationCompleteNotification()
{
Text = @"Update ready to install. Click to restart!";
}
}
public class UpdateProgressNotification : ProgressNotification
{
protected override Notification CreateCompletionNotification() => new UpdateApplicationCompleteNotification();
[BackgroundDependencyLoader]
private void load()
{
IconContent.AddRange(new Drawable[]
{
new SpriteIcon
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Icon = FontAwesome.Solid.Upload,
Size = new Vector2(14),
}
});
}
public override void Close()
{
// cancelling updates is not currently supported by the underlying updater.
// only allow dismissing for now.
switch (State)
{
case ProgressNotificationState.Cancelled:
base.Close();
break;
}
}
public void StartDownload()
{
State = ProgressNotificationState.Active;
Progress = 0;
Text = @"Downloading update...";
}
public void StartInstall()
{
Progress = 0;
Text = @"Installing update...";
}
public void FailDownload()
{
State = ProgressNotificationState.Cancelled;
Close();
}
}
}
}