Refactor VeloUpdateManager

This commit is contained in:
smallketchup82 2024-07-04 17:28:49 -04:00
parent 36a3765ee4
commit fae8f5f81b
No known key found for this signature in database
GPG Key ID: 7345B7C561243F1E
1 changed files with 23 additions and 26 deletions

View File

@ -10,12 +10,13 @@
using osu.Game.Overlays.Notifications;
using osu.Game.Screens.Play;
using osu.Game.Updater;
using Velopack.Sources;
namespace osu.Desktop.Updater
{
public partial class VeloUpdateManager : UpdateManager
{
private Velopack.UpdateManager? updateManager;
private readonly Velopack.UpdateManager updateManager;
private INotificationOverlay notificationOverlay = null!;
[Resolved]
@ -24,6 +25,12 @@ public partial class VeloUpdateManager : UpdateManager
[Resolved]
private ILocalUserPlayInfo? localUserInfo { get; set; }
public VeloUpdateManager()
{
const string? github_token = null; // TODO: populate.
updateManager = new Velopack.UpdateManager(new GithubSource(@"https://github.com/ppy/osu", github_token, false));
}
[BackgroundDependencyLoader]
private void load(INotificationOverlay notifications)
{
@ -37,23 +44,21 @@ private async Task<bool> checkForUpdateAsync(UpdateProgressNotification? notific
// should we schedule a retry on completion of this check?
bool scheduleRecheck = true;
const string? github_token = null; // TODO: populate.
try
{
// Avoid any kind of update checking while gameplay is running.
if (localUserInfo?.IsPlaying.Value == true)
return false;
updateManager ??= new Velopack.UpdateManager(new Velopack.Sources.GithubSource(@"https://github.com/ppy/osu", github_token, false));
var info = await updateManager.CheckForUpdatesAsync().ConfigureAwait(false);
// Handle no updates available.
if (info == null)
{
// If there is an update pending restart, show the notification again.
if (updateManager.IsUpdatePendingRestart)
{
// If there's no updates pending restart, bail and retry later.
if (!updateManager.IsUpdatePendingRestart) return false;
// If there is an update pending restart, show the notification to restart again.
notificationOverlay.Post(new UpdateApplicationCompleteNotification
{
Activated = () =>
@ -65,10 +70,6 @@ private async Task<bool> checkForUpdateAsync(UpdateProgressNotification? notific
return true;
}
// Otherwise there's no updates available. Bail and retry later.
return false;
}
scheduleRecheck = false;
if (notification == null)
@ -87,8 +88,6 @@ private async Task<bool> checkForUpdateAsync(UpdateProgressNotification? notific
{
await updateManager.DownloadUpdatesAsync(info, p => notification.Progress = p / 100f).ConfigureAwait(false);
notification.StartInstall();
notification.State = ProgressNotificationState.Completed;
}
catch (Exception e)
@ -98,10 +97,11 @@ private async Task<bool> checkForUpdateAsync(UpdateProgressNotification? notific
Logger.Error(e, @"update failed!");
}
}
catch (Exception)
catch (Exception e)
{
// we'll ignore this and retry later. can be triggered by no internet connection or thread abortion.
scheduleRecheck = true;
Logger.Error(e, @"update check failed!");
}
finally
{
@ -117,9 +117,6 @@ private async Task<bool> checkForUpdateAsync(UpdateProgressNotification? notific
private bool restartToApplyUpdate()
{
if (updateManager == null)
return false;
updateManager.WaitExitThenApplyUpdates(null);
Schedule(() => game.AttemptExit());
return true;