Merge branch 'master' into score-results-screen

This commit is contained in:
Dan Balasescu 2020-06-15 22:58:33 +09:00 committed by GitHub
commit b4dfd2bbaa
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 @@ public class SquirrelUpdateManager : osu.Game.Updater.UpdateManager
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 @@ private async void checkForUpdateAsync(bool useDeltaPatching = true, UpdateProgr
// 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 @@ private async void checkForUpdateAsync(bool useDeltaPatching = true, UpdateProgr
if (scheduleRecheck)
{
// check again in 30 minutes.
Scheduler.AddDelayed(() => checkForUpdateAsync(), 60000 * 30);
Scheduler.AddDelayed(async () => await checkForUpdateAsync(), 60000 * 30);
}
}
}

View File

@ -622,6 +622,9 @@ protected override void LoadComplete()
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);
@ -654,7 +657,6 @@ protected override void LoadComplete()
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 @@ private void load(Storage storage, OsuConfigManager config, OsuGame game)
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 @@ public class SimpleUpdateManager : UpdateManager
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 @@ protected override void LoadComplete()
{
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 @@ protected override void LoadComplete()
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;