1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 11:35:35 +08:00

Merge pull request #8965 from Craftplacer/update-button

Add "Check for updates" button
This commit is contained in:
Dan Balasescu 2020-06-15 22:55:04 +09:00 committed by GitHub
commit 84596a166b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 64 additions and 14 deletions

View File

@ -30,18 +30,16 @@ namespace osu.Desktop.Updater
private static readonly Logger logger = Logger.GetLogger("updater");
[BackgroundDependencyLoader]
private void load(NotificationOverlay notification, OsuGameBase game)
private void load(NotificationOverlay notification)
{
notificationOverlay = notification;
if (game.IsDeployedBuild)
{
Splat.Locator.CurrentMutable.Register(() => new SquirrelLogger(), typeof(Splat.ILogger));
Schedule(() => Task.Run(() => checkForUpdateAsync()));
}
Splat.Locator.CurrentMutable.Register(() => new SquirrelLogger(), typeof(Splat.ILogger));
}
private async void checkForUpdateAsync(bool useDeltaPatching = true, UpdateProgressNotification notification = null)
protected override async Task PerformUpdateCheck() => await checkForUpdateAsync();
private async Task checkForUpdateAsync(bool useDeltaPatching = true, UpdateProgressNotification notification = null)
{
// should we schedule a retry on completion of this check?
bool scheduleRecheck = true;
@ -83,7 +81,7 @@ namespace osu.Desktop.Updater
// could fail if deltas are unavailable for full update path (https://github.com/Squirrel/Squirrel.Windows/issues/959)
// try again without deltas.
checkForUpdateAsync(false, notification);
await checkForUpdateAsync(false, notification);
scheduleRecheck = false;
}
else
@ -102,7 +100,7 @@ namespace osu.Desktop.Updater
if (scheduleRecheck)
{
// check again in 30 minutes.
Scheduler.AddDelayed(() => checkForUpdateAsync(), 60000 * 30);
Scheduler.AddDelayed(async () => await checkForUpdateAsync(), 60000 * 30);
}
}
}

View File

@ -611,6 +611,9 @@ namespace osu.Game
loadComponentSingleFile(screenshotManager, Add);
// dependency on notification overlay, dependent by settings overlay
loadComponentSingleFile(CreateUpdateManager(), Add, true);
// overlay elements
loadComponentSingleFile(beatmapListing = new BeatmapListingOverlay(), overlayContent.Add, true);
loadComponentSingleFile(dashboard = new DashboardOverlay(), overlayContent.Add, true);
@ -643,7 +646,6 @@ namespace osu.Game
chatOverlay.State.ValueChanged += state => channelManager.HighPollRate.Value = state.NewValue == Visibility.Visible;
Add(externalLinkOpener = new ExternalLinkOpener());
Add(CreateUpdateManager()); // dependency on notification overlay
// side overlays which cancel each other.
var singleDisplaySideOverlays = new OverlayContainer[] { Settings, notifications };

View File

@ -1,19 +1,26 @@
// 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.
using System.Threading.Tasks;
using osu.Framework;
using osu.Framework.Allocation;
using osu.Framework.Platform;
using osu.Framework.Screens;
using osu.Game.Configuration;
using osu.Game.Overlays.Settings.Sections.Maintenance;
using osu.Game.Updater;
namespace osu.Game.Overlays.Settings.Sections.General
{
public class UpdateSettings : SettingsSubsection
{
[Resolved(CanBeNull = true)]
private UpdateManager updateManager { get; set; }
protected override string Header => "Updates";
private SettingsButton checkForUpdatesButton;
[BackgroundDependencyLoader(true)]
private void load(Storage storage, OsuConfigManager config, OsuGame game)
{
@ -23,6 +30,19 @@ namespace osu.Game.Overlays.Settings.Sections.General
Bindable = config.GetBindable<ReleaseStream>(OsuSetting.ReleaseStream),
});
if (updateManager?.CanCheckForUpdate == true)
{
Add(checkForUpdatesButton = new SettingsButton
{
Text = "Check for updates",
Action = () =>
{
checkForUpdatesButton.Enabled.Value = false;
Task.Run(updateManager.CheckForUpdateAsync).ContinueWith(t => Schedule(() => checkForUpdatesButton.Enabled.Value = true));
}
});
}
if (RuntimeInfo.IsDesktop)
{
Add(new SettingsButton

View File

@ -28,12 +28,9 @@ namespace osu.Game.Updater
private void load(OsuGameBase game)
{
version = game.Version;
if (game.IsDeployedBuild)
Schedule(() => Task.Run(checkForUpdateAsync));
}
private async void checkForUpdateAsync()
protected override async Task PerformUpdateCheck()
{
try
{

View File

@ -1,6 +1,7 @@
// 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.
using System.Threading.Tasks;
using osu.Framework.Allocation;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
@ -16,6 +17,13 @@ namespace osu.Game.Updater
/// </summary>
public class UpdateManager : CompositeDrawable
{
/// <summary>
/// Whether this UpdateManager should be or is capable of checking for updates.
/// </summary>
public bool CanCheckForUpdate => game.IsDeployedBuild &&
// only implementations will actually check for updates.
GetType() != typeof(UpdateManager);
[Resolved]
private OsuConfigManager config { get; set; }
@ -29,7 +37,10 @@ namespace osu.Game.Updater
{
base.LoadComplete();
Schedule(() => Task.Run(CheckForUpdateAsync));
var version = game.Version;
var lastVersion = config.Get<string>(OsuSetting.Version);
if (game.IsDeployedBuild && version != lastVersion)
@ -44,6 +55,28 @@ namespace osu.Game.Updater
config.Set(OsuSetting.Version, version);
}
private readonly object updateTaskLock = new object();
private Task updateCheckTask;
public async Task CheckForUpdateAsync()
{
if (!CanCheckForUpdate)
return;
Task waitTask;
lock (updateTaskLock)
waitTask = (updateCheckTask ??= PerformUpdateCheck());
await waitTask;
lock (updateTaskLock)
updateCheckTask = null;
}
protected virtual Task PerformUpdateCheck() => Task.CompletedTask;
private class UpdateCompleteNotification : SimpleNotification
{
private readonly string version;