1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 18:07:23 +08:00

Show a notification if checking for updates via button and there are none available

This commit is contained in:
Dean Herbert 2020-10-06 13:00:02 +09:00
parent 798dc9bc25
commit 22b0105d62
4 changed files with 41 additions and 14 deletions

View File

@ -37,9 +37,9 @@ namespace osu.Desktop.Updater
Splat.Locator.CurrentMutable.Register(() => new SquirrelLogger(), typeof(Splat.ILogger));
}
protected override async Task PerformUpdateCheck() => await checkForUpdateAsync();
protected override async Task<bool> PerformUpdateCheck() => await checkForUpdateAsync();
private async Task checkForUpdateAsync(bool useDeltaPatching = true, UpdateProgressNotification notification = null)
private async Task<bool> checkForUpdateAsync(bool useDeltaPatching = true, UpdateProgressNotification notification = null)
{
// should we schedule a retry on completion of this check?
bool scheduleRecheck = true;
@ -51,7 +51,7 @@ namespace osu.Desktop.Updater
var info = await updateManager.CheckForUpdate(!useDeltaPatching);
if (info.ReleasesToApply.Count == 0)
// no updates available. bail and retry later.
return;
return false;
if (notification == null)
{
@ -103,6 +103,8 @@ namespace osu.Desktop.Updater
Scheduler.AddDelayed(async () => await checkForUpdateAsync(), 60000 * 30);
}
}
return true;
}
protected override void Dispose(bool isDisposing)

View File

@ -4,9 +4,11 @@
using System.Threading.Tasks;
using osu.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Platform;
using osu.Framework.Screens;
using osu.Game.Configuration;
using osu.Game.Overlays.Notifications;
using osu.Game.Overlays.Settings.Sections.Maintenance;
using osu.Game.Updater;
@ -21,6 +23,9 @@ namespace osu.Game.Overlays.Settings.Sections.General
private SettingsButton checkForUpdatesButton;
[Resolved]
private NotificationOverlay notifications { get; set; }
[BackgroundDependencyLoader(true)]
private void load(Storage storage, OsuConfigManager config, OsuGame game)
{
@ -30,7 +35,7 @@ namespace osu.Game.Overlays.Settings.Sections.General
Bindable = config.GetBindable<ReleaseStream>(OsuSetting.ReleaseStream),
});
if (updateManager?.CanCheckForUpdate == true)
//if (updateManager?.CanCheckForUpdate == true)
{
Add(checkForUpdatesButton = new SettingsButton
{
@ -38,7 +43,19 @@ namespace osu.Game.Overlays.Settings.Sections.General
Action = () =>
{
checkForUpdatesButton.Enabled.Value = false;
Task.Run(updateManager.CheckForUpdateAsync).ContinueWith(t => Schedule(() => checkForUpdatesButton.Enabled.Value = true));
Task.Run(updateManager.CheckForUpdateAsync).ContinueWith(t => Schedule(() =>
{
if (!t.Result)
{
notifications.Post(new SimpleNotification
{
Text = $"You are running the latest release ({game.Version})",
Icon = FontAwesome.Solid.CheckCircle,
});
}
checkForUpdatesButton.Enabled.Value = true;
}));
}
});
}

View File

@ -30,7 +30,7 @@ namespace osu.Game.Updater
version = game.Version;
}
protected override async Task PerformUpdateCheck()
protected override async Task<bool> PerformUpdateCheck()
{
try
{
@ -53,12 +53,17 @@ namespace osu.Game.Updater
return true;
}
});
return true;
}
}
catch
{
// we shouldn't crash on a web failure. or any failure for the matter.
return true;
}
return false;
}
private string getBestUrl(GitHubRelease release)

View File

@ -57,25 +57,28 @@ namespace osu.Game.Updater
private readonly object updateTaskLock = new object();
private Task updateCheckTask;
private Task<bool> updateCheckTask;
public async Task CheckForUpdateAsync()
public async Task<bool> CheckForUpdateAsync()
{
if (!CanCheckForUpdate)
return;
Task waitTask;
Task<bool> waitTask;
lock (updateTaskLock)
waitTask = (updateCheckTask ??= PerformUpdateCheck());
await waitTask;
bool hasUpdates = await waitTask;
lock (updateTaskLock)
updateCheckTask = null;
return hasUpdates;
}
protected virtual Task PerformUpdateCheck() => Task.CompletedTask;
/// <summary>
/// Performs an asynchronous check for application updates.
/// </summary>
/// <returns>Whether any update is waiting. May return true if an error occured (there is potentially an update available).</returns>
protected virtual Task<bool> PerformUpdateCheck() => Task.FromResult(false);
private class UpdateCompleteNotification : SimpleNotification
{