mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 10:33:30 +08:00
Show a notification if checking for updates via button and there are none available
This commit is contained in:
parent
798dc9bc25
commit
22b0105d62
@ -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)
|
||||
|
@ -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;
|
||||
}));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user