From fae8f5f81b4d2de10fe1e2f2e58f0258158a794b Mon Sep 17 00:00:00 2001 From: smallketchup82 Date: Thu, 4 Jul 2024 17:28:49 -0400 Subject: [PATCH] Refactor VeloUpdateManager --- osu.Desktop/Updater/VeloUpdateManager.cs | 49 +++++++++++------------- 1 file changed, 23 insertions(+), 26 deletions(-) diff --git a/osu.Desktop/Updater/VeloUpdateManager.cs b/osu.Desktop/Updater/VeloUpdateManager.cs index 8fc68f77cd..137e48f135 100644 --- a/osu.Desktop/Updater/VeloUpdateManager.cs +++ b/osu.Desktop/Updater/VeloUpdateManager.cs @@ -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,36 +44,30 @@ private async Task 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) - { - notificationOverlay.Post(new UpdateApplicationCompleteNotification - { - Activated = () => - { - restartToApplyUpdate(); - return true; - } - }); - return true; - } + // If there's no updates pending restart, bail and retry later. + if (!updateManager.IsUpdatePendingRestart) return false; - // Otherwise there's no updates available. Bail and retry later. - return false; + // If there is an update pending restart, show the notification to restart again. + notificationOverlay.Post(new UpdateApplicationCompleteNotification + { + Activated = () => + { + restartToApplyUpdate(); + return true; + } + }); + return true; } scheduleRecheck = false; @@ -87,8 +88,6 @@ private async Task 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 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 checkForUpdateAsync(UpdateProgressNotification? notific private bool restartToApplyUpdate() { - if (updateManager == null) - return false; - updateManager.WaitExitThenApplyUpdates(null); Schedule(() => game.AttemptExit()); return true;