mirror of
https://github.com/osukey/osukey.git
synced 2025-04-29 10:47:22 +09:00
Move UpdateProgressNotification
to base UpdateManager
class
This commit is contained in:
parent
aa823161f1
commit
eca241e9a7
@ -5,26 +5,24 @@ using System;
|
|||||||
using System.Runtime.Versioning;
|
using System.Runtime.Versioning;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Graphics;
|
|
||||||
using osu.Framework.Graphics.Sprites;
|
|
||||||
using osu.Framework.Logging;
|
using osu.Framework.Logging;
|
||||||
using osu.Game;
|
using osu.Game;
|
||||||
using osu.Game.Graphics;
|
|
||||||
using osu.Game.Overlays;
|
using osu.Game.Overlays;
|
||||||
using osu.Game.Overlays.Notifications;
|
using osu.Game.Overlays.Notifications;
|
||||||
using osuTK;
|
|
||||||
using Squirrel;
|
using Squirrel;
|
||||||
using Squirrel.SimpleSplat;
|
using Squirrel.SimpleSplat;
|
||||||
|
using LogLevel = Squirrel.SimpleSplat.LogLevel;
|
||||||
|
using UpdateManager = osu.Game.Updater.UpdateManager;
|
||||||
|
|
||||||
namespace osu.Desktop.Updater
|
namespace osu.Desktop.Updater
|
||||||
{
|
{
|
||||||
[SupportedOSPlatform("windows")]
|
[SupportedOSPlatform("windows")]
|
||||||
public class SquirrelUpdateManager : osu.Game.Updater.UpdateManager
|
public class SquirrelUpdateManager : UpdateManager
|
||||||
{
|
{
|
||||||
private UpdateManager? updateManager;
|
private Squirrel.UpdateManager? updateManager;
|
||||||
private INotificationOverlay notificationOverlay = null!;
|
private INotificationOverlay notificationOverlay = null!;
|
||||||
|
|
||||||
public Task PrepareUpdateAsync() => UpdateManager.RestartAppWhenExited();
|
public Task PrepareUpdateAsync() => Squirrel.UpdateManager.RestartAppWhenExited();
|
||||||
|
|
||||||
private static readonly Logger logger = Logger.GetLogger("updater");
|
private static readonly Logger logger = Logger.GetLogger("updater");
|
||||||
|
|
||||||
@ -35,6 +33,9 @@ namespace osu.Desktop.Updater
|
|||||||
|
|
||||||
private readonly SquirrelLogger squirrelLogger = new SquirrelLogger();
|
private readonly SquirrelLogger squirrelLogger = new SquirrelLogger();
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private OsuGameBase game { get; set; } = null!;
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(INotificationOverlay notifications)
|
private void load(INotificationOverlay notifications)
|
||||||
{
|
{
|
||||||
@ -63,7 +64,14 @@ namespace osu.Desktop.Updater
|
|||||||
if (updatePending)
|
if (updatePending)
|
||||||
{
|
{
|
||||||
// the user may have dismissed the completion notice, so show it again.
|
// the user may have dismissed the completion notice, so show it again.
|
||||||
notificationOverlay.Post(new UpdateCompleteNotification(this));
|
notificationOverlay.Post(new UpdateApplicationCompleteNotification
|
||||||
|
{
|
||||||
|
Activated = () =>
|
||||||
|
{
|
||||||
|
restartToApplyUpdate();
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,19 +83,21 @@ namespace osu.Desktop.Updater
|
|||||||
|
|
||||||
if (notification == null)
|
if (notification == null)
|
||||||
{
|
{
|
||||||
notification = new UpdateProgressNotification(this) { State = ProgressNotificationState.Active };
|
notification = new UpdateProgressNotification
|
||||||
|
{
|
||||||
|
CompletionClickAction = restartToApplyUpdate,
|
||||||
|
};
|
||||||
|
|
||||||
Schedule(() => notificationOverlay.Post(notification));
|
Schedule(() => notificationOverlay.Post(notification));
|
||||||
}
|
}
|
||||||
|
|
||||||
notification.Progress = 0;
|
notification.StartDownload();
|
||||||
notification.Text = @"Downloading update...";
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await updateManager.DownloadReleases(info.ReleasesToApply, p => notification.Progress = p / 100f).ConfigureAwait(false);
|
await updateManager.DownloadReleases(info.ReleasesToApply, p => notification.Progress = p / 100f).ConfigureAwait(false);
|
||||||
|
|
||||||
notification.Progress = 0;
|
notification.StartInstall();
|
||||||
notification.Text = @"Installing update...";
|
|
||||||
|
|
||||||
await updateManager.ApplyReleases(info, p => notification.Progress = p / 100f).ConfigureAwait(false);
|
await updateManager.ApplyReleases(info, p => notification.Progress = p / 100f).ConfigureAwait(false);
|
||||||
|
|
||||||
@ -107,9 +117,7 @@ namespace osu.Desktop.Updater
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// In the case of an error, a separate notification will be displayed.
|
// In the case of an error, a separate notification will be displayed.
|
||||||
notification.State = ProgressNotificationState.Cancelled;
|
notification.FailDownload();
|
||||||
notification.Close();
|
|
||||||
|
|
||||||
Logger.Error(e, @"update failed!");
|
Logger.Error(e, @"update failed!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -131,78 +139,24 @@ namespace osu.Desktop.Updater
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool restartToApplyUpdate()
|
||||||
|
{
|
||||||
|
PrepareUpdateAsync()
|
||||||
|
.ContinueWith(_ => Schedule(() => game.AttemptExit()));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
protected override void Dispose(bool isDisposing)
|
protected override void Dispose(bool isDisposing)
|
||||||
{
|
{
|
||||||
base.Dispose(isDisposing);
|
base.Dispose(isDisposing);
|
||||||
updateManager?.Dispose();
|
updateManager?.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
private class UpdateCompleteNotification : ProgressCompletionNotification
|
|
||||||
{
|
|
||||||
[Resolved]
|
|
||||||
private OsuGame game { get; set; } = null!;
|
|
||||||
|
|
||||||
public UpdateCompleteNotification(SquirrelUpdateManager updateManager)
|
|
||||||
{
|
|
||||||
Text = @"Update ready to install. Click to restart!";
|
|
||||||
|
|
||||||
Activated = () =>
|
|
||||||
{
|
|
||||||
updateManager.PrepareUpdateAsync()
|
|
||||||
.ContinueWith(_ => updateManager.Schedule(() => game.AttemptExit()));
|
|
||||||
return true;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class UpdateProgressNotification : ProgressNotification
|
|
||||||
{
|
|
||||||
private readonly SquirrelUpdateManager updateManager;
|
|
||||||
|
|
||||||
public UpdateProgressNotification(SquirrelUpdateManager updateManager)
|
|
||||||
{
|
|
||||||
this.updateManager = updateManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override Notification CreateCompletionNotification()
|
|
||||||
{
|
|
||||||
return new UpdateCompleteNotification(updateManager);
|
|
||||||
}
|
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
|
||||||
private void load(OsuColour colours)
|
|
||||||
{
|
|
||||||
IconContent.AddRange(new Drawable[]
|
|
||||||
{
|
|
||||||
new SpriteIcon
|
|
||||||
{
|
|
||||||
Anchor = Anchor.Centre,
|
|
||||||
Origin = Anchor.Centre,
|
|
||||||
Icon = FontAwesome.Solid.Upload,
|
|
||||||
Size = new Vector2(20),
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class SquirrelLogger : ILogger, IDisposable
|
private class SquirrelLogger : ILogger, IDisposable
|
||||||
{
|
{
|
||||||
public Squirrel.SimpleSplat.LogLevel Level { get; set; } = Squirrel.SimpleSplat.LogLevel.Info;
|
public LogLevel Level { get; set; } = LogLevel.Info;
|
||||||
|
|
||||||
public void Write(string message, Squirrel.SimpleSplat.LogLevel logLevel)
|
public void Write(string message, LogLevel logLevel)
|
||||||
{
|
{
|
||||||
if (logLevel < Level)
|
if (logLevel < Level)
|
||||||
return;
|
return;
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
#nullable disable
|
|
||||||
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Graphics.Sprites;
|
using osu.Framework.Graphics.Sprites;
|
||||||
using osu.Game.Configuration;
|
using osu.Game.Configuration;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Overlays;
|
using osu.Game.Overlays;
|
||||||
using osu.Game.Overlays.Notifications;
|
using osu.Game.Overlays.Notifications;
|
||||||
|
using osuTK;
|
||||||
|
|
||||||
namespace osu.Game.Updater
|
namespace osu.Game.Updater
|
||||||
{
|
{
|
||||||
@ -27,13 +27,13 @@ namespace osu.Game.Updater
|
|||||||
GetType() != typeof(UpdateManager);
|
GetType() != typeof(UpdateManager);
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private OsuConfigManager config { get; set; }
|
private OsuConfigManager config { get; set; } = null!;
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private OsuGameBase game { get; set; }
|
private OsuGameBase game { get; set; } = null!;
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
protected INotificationOverlay Notifications { get; private set; }
|
protected INotificationOverlay Notifications { get; private set; } = null!;
|
||||||
|
|
||||||
protected override void LoadComplete()
|
protected override void LoadComplete()
|
||||||
{
|
{
|
||||||
@ -59,7 +59,7 @@ namespace osu.Game.Updater
|
|||||||
|
|
||||||
private readonly object updateTaskLock = new object();
|
private readonly object updateTaskLock = new object();
|
||||||
|
|
||||||
private Task<bool> updateCheckTask;
|
private Task<bool>? updateCheckTask;
|
||||||
|
|
||||||
public async Task<bool> CheckForUpdateAsync()
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user