From 77cf39ac0dbdfd5f88a3865b39d7516811219ede Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Mon, 9 Jun 2025 16:05:52 +0900 Subject: [PATCH] Move release stream handling to base class --- osu.Desktop/Updater/VelopackUpdateManager.cs | 32 +++++++------------- osu.Game/Updater/UpdateManager.cs | 19 ++++++++---- 2 files changed, 24 insertions(+), 27 deletions(-) diff --git a/osu.Desktop/Updater/VelopackUpdateManager.cs b/osu.Desktop/Updater/VelopackUpdateManager.cs index 6f22fd5940..51744345a4 100644 --- a/osu.Desktop/Updater/VelopackUpdateManager.cs +++ b/osu.Desktop/Updater/VelopackUpdateManager.cs @@ -4,7 +4,6 @@ using System; using System.Threading.Tasks; using osu.Framework.Allocation; -using osu.Framework.Bindables; using osu.Framework.Logging; using osu.Game; using osu.Game.Configuration; @@ -27,36 +26,27 @@ namespace osu.Desktop.Updater [Resolved] private ILocalUserPlayInfo? localUserInfo { get; set; } - [Resolved] - private OsuConfigManager osuConfigManager { get; set; } = null!; - private bool isInGameplay => localUserInfo?.PlayingState.Value != LocalUserPlayingState.NotPlaying; - private readonly Bindable releaseStream = new Bindable(); private UpdateManager? updateManager; private UpdateInfo? pendingUpdate; + private ReleaseStream? lastReleaseStream; - protected override void LoadComplete() + protected override async Task PerformUpdateCheck() { - // Used by the base implementation. - osuConfigManager.BindWith(OsuSetting.ReleaseStream, releaseStream); - releaseStream.BindValueChanged(_ => onReleaseStreamChanged(), true); - - base.LoadComplete(); - } - - private void onReleaseStreamChanged() - { - updateManager = new UpdateManager(new GithubSource(@"https://github.com/ppy/osu", null, releaseStream.Value == ReleaseStream.Tachyon), new UpdateOptions + if (ReleaseStream.Value != lastReleaseStream) { - AllowVersionDowngrade = true, - }); + updateManager = new UpdateManager(new GithubSource(@"https://github.com/ppy/osu", null, ReleaseStream.Value == Game.Configuration.ReleaseStream.Tachyon), new UpdateOptions + { + AllowVersionDowngrade = true, + }); - Schedule(() => Task.Run(CheckForUpdateAsync)); + lastReleaseStream = ReleaseStream.Value; + } + + return await checkForUpdateAsync().ConfigureAwait(false); } - protected override async Task PerformUpdateCheck() => await checkForUpdateAsync().ConfigureAwait(false); - private async Task checkForUpdateAsync() { // whether to check again in 30 minutes. generally only if there's an error or no update was found (yet). diff --git a/osu.Game/Updater/UpdateManager.cs b/osu.Game/Updater/UpdateManager.cs index c114e3a8d0..354a8da46b 100644 --- a/osu.Game/Updater/UpdateManager.cs +++ b/osu.Game/Updater/UpdateManager.cs @@ -5,6 +5,7 @@ using System.Reflection; using System.Threading.Tasks; using osu.Framework; using osu.Framework.Allocation; +using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Sprites; @@ -39,14 +40,17 @@ namespace osu.Game.Updater [Resolved] protected INotificationOverlay Notifications { get; private set; } = null!; + protected IBindable ReleaseStream => releaseStream; + + private readonly Bindable releaseStream = new Bindable(); + private readonly object updateTaskLock = new object(); + private Task? updateCheckTask; + protected override void LoadComplete() { base.LoadComplete(); - Schedule(() => Task.Run(CheckForUpdateAsync)); - string version = game.Version; - string lastVersion = config.Get(OsuSetting.Version); if (game.IsDeployedBuild && version != lastVersion) @@ -62,11 +66,14 @@ namespace osu.Game.Updater // debug / local compilations will reset to a non-release string. // can be useful to check when an install has transitioned between release and otherwise (see OsuConfigManager's migrations). config.SetValue(OsuSetting.Version, version); + + config.BindWith(OsuSetting.ReleaseStream, releaseStream); + releaseStream.BindValueChanged(_ => scheduleUpdateCheck()); + + scheduleUpdateCheck(); } - private readonly object updateTaskLock = new object(); - - private Task? updateCheckTask; + private void scheduleUpdateCheck() => Schedule(() => Task.Run(CheckForUpdateAsync)); public async Task CheckForUpdateAsync() {