mirror of
https://github.com/ppy/osu.git
synced 2026-05-28 03:53:45 +08:00
Move release stream handling to base class
This commit is contained in:
@@ -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> releaseStream = new Bindable<ReleaseStream>();
|
||||
private UpdateManager? updateManager;
|
||||
private UpdateInfo? pendingUpdate;
|
||||
private ReleaseStream? lastReleaseStream;
|
||||
|
||||
protected override void LoadComplete()
|
||||
protected override async Task<bool> 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<bool> PerformUpdateCheck() => await checkForUpdateAsync().ConfigureAwait(false);
|
||||
|
||||
private async Task<bool> checkForUpdateAsync()
|
||||
{
|
||||
// whether to check again in 30 minutes. generally only if there's an error or no update was found (yet).
|
||||
|
||||
@@ -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 => releaseStream;
|
||||
|
||||
private readonly Bindable<ReleaseStream> releaseStream = new Bindable<ReleaseStream>();
|
||||
private readonly object updateTaskLock = new object();
|
||||
private Task<bool>? updateCheckTask;
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
Schedule(() => Task.Run(CheckForUpdateAsync));
|
||||
|
||||
string version = game.Version;
|
||||
|
||||
string lastVersion = config.Get<string>(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<bool>? updateCheckTask;
|
||||
private void scheduleUpdateCheck() => Schedule(() => Task.Run(CheckForUpdateAsync));
|
||||
|
||||
public async Task<bool> CheckForUpdateAsync()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user