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"); private static readonly Logger logger = Logger.GetLogger("updater");
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(NotificationOverlay notification, OsuGameBase game) private void load(NotificationOverlay notification)
{ {
notificationOverlay = notification; notificationOverlay = notification;
if (game.IsDeployedBuild) Splat.Locator.CurrentMutable.Register(() => new SquirrelLogger(), typeof(Splat.ILogger));
{
Splat.Locator.CurrentMutable.Register(() => new SquirrelLogger(), typeof(Splat.ILogger));
Schedule(() => Task.Run(() => checkForUpdateAsync()));
}
} }
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? // should we schedule a retry on completion of this check?
bool scheduleRecheck = true; 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) // could fail if deltas are unavailable for full update path (https://github.com/Squirrel/Squirrel.Windows/issues/959)
// try again without deltas. // try again without deltas.
checkForUpdateAsync(false, notification); await checkForUpdateAsync(false, notification);
scheduleRecheck = false; scheduleRecheck = false;
} }
else else
@ -102,7 +100,7 @@ private async void checkForUpdateAsync(bool useDeltaPatching = true, UpdateProgr
if (scheduleRecheck) if (scheduleRecheck)
{ {
// check again in 30 minutes. // 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); loadComponentSingleFile(screenshotManager, Add);
// dependency on notification overlay, dependent by settings overlay
loadComponentSingleFile(CreateUpdateManager(), Add, true);
// overlay elements // overlay elements
loadComponentSingleFile(beatmapListing = new BeatmapListingOverlay(), overlayContent.Add, true); loadComponentSingleFile(beatmapListing = new BeatmapListingOverlay(), overlayContent.Add, true);
loadComponentSingleFile(dashboard = new DashboardOverlay(), 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; chatOverlay.State.ValueChanged += state => channelManager.HighPollRate.Value = state.NewValue == Visibility.Visible;
Add(externalLinkOpener = new ExternalLinkOpener()); Add(externalLinkOpener = new ExternalLinkOpener());
Add(CreateUpdateManager()); // dependency on notification overlay
// side overlays which cancel each other. // side overlays which cancel each other.
var singleDisplaySideOverlays = new OverlayContainer[] { Settings, notifications }; 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. // 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. // See the LICENCE file in the repository root for full licence text.
using System.Threading.Tasks;
using osu.Framework; using osu.Framework;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Platform; using osu.Framework.Platform;
using osu.Framework.Screens; using osu.Framework.Screens;
using osu.Game.Configuration; using osu.Game.Configuration;
using osu.Game.Overlays.Settings.Sections.Maintenance; using osu.Game.Overlays.Settings.Sections.Maintenance;
using osu.Game.Updater;
namespace osu.Game.Overlays.Settings.Sections.General namespace osu.Game.Overlays.Settings.Sections.General
{ {
public class UpdateSettings : SettingsSubsection public class UpdateSettings : SettingsSubsection
{ {
[Resolved(CanBeNull = true)]
private UpdateManager updateManager { get; set; }
protected override string Header => "Updates"; protected override string Header => "Updates";
private SettingsButton checkForUpdatesButton;
[BackgroundDependencyLoader(true)] [BackgroundDependencyLoader(true)]
private void load(Storage storage, OsuConfigManager config, OsuGame game) 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), 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) if (RuntimeInfo.IsDesktop)
{ {
Add(new SettingsButton Add(new SettingsButton

View File

@ -28,12 +28,9 @@ public class SimpleUpdateManager : UpdateManager
private void load(OsuGameBase game) private void load(OsuGameBase game)
{ {
version = game.Version; version = game.Version;
if (game.IsDeployedBuild)
Schedule(() => Task.Run(checkForUpdateAsync));
} }
private async void checkForUpdateAsync() protected override async Task PerformUpdateCheck()
{ {
try try
{ {

View File

@ -1,6 +1,7 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using System.Threading.Tasks;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
@ -16,6 +17,13 @@ namespace osu.Game.Updater
/// </summary> /// </summary>
public class UpdateManager : CompositeDrawable 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] [Resolved]
private OsuConfigManager config { get; set; } private OsuConfigManager config { get; set; }
@ -29,7 +37,10 @@ protected override void LoadComplete()
{ {
base.LoadComplete(); base.LoadComplete();
Schedule(() => Task.Run(CheckForUpdateAsync));
var version = game.Version; var version = game.Version;
var lastVersion = config.Get<string>(OsuSetting.Version); var lastVersion = config.Get<string>(OsuSetting.Version);
if (game.IsDeployedBuild && version != lastVersion) if (game.IsDeployedBuild && version != lastVersion)
@ -44,6 +55,28 @@ protected override void LoadComplete()
config.Set(OsuSetting.Version, version); 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 class UpdateCompleteNotification : SimpleNotification
{ {
private readonly string version; private readonly string version;