mirror of
https://github.com/osukey/osukey.git
synced 2025-07-03 01:09:57 +09:00
Add update manager which performs no update action
This is to be used in cases where updates are handled by an external means. See https://github.com/flathub/flathub/pull/2619#issuecomment-969731305 for initial usage.
This commit is contained in:
67
osu.Game/Updater/NoActionUpdateManager.cs
Normal file
67
osu.Game/Updater/NoActionUpdateManager.cs
Normal file
@ -0,0 +1,67 @@
|
||||
// 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.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Framework.Platform;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Game.Overlays.Notifications;
|
||||
|
||||
namespace osu.Game.Updater
|
||||
{
|
||||
/// <summary>
|
||||
/// An update manager that shows notifications if a newer release is detected.
|
||||
/// This is a case where updates are handled externally by a package manager or other means, so no action is performed on clicking the notification.
|
||||
/// </summary>
|
||||
public class NoActionUpdateManager : UpdateManager
|
||||
{
|
||||
private string version;
|
||||
|
||||
[Resolved]
|
||||
private GameHost host { get; set; }
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuGameBase game)
|
||||
{
|
||||
version = game.Version;
|
||||
}
|
||||
|
||||
protected override async Task<bool> PerformUpdateCheck()
|
||||
{
|
||||
try
|
||||
{
|
||||
var releases = new OsuJsonWebRequest<GitHubRelease>("https://api.github.com/repos/ppy/osu/releases/latest");
|
||||
|
||||
await releases.PerformAsync().ConfigureAwait(false);
|
||||
|
||||
var latest = releases.ResponseObject;
|
||||
|
||||
// avoid any discrepancies due to build suffixes for now.
|
||||
// eventually we will want to support release streams and consider these.
|
||||
version = version.Split('-').First();
|
||||
string latestTagName = latest.TagName.Split('-').First();
|
||||
|
||||
if (latestTagName != version)
|
||||
{
|
||||
Notifications.Post(new SimpleNotification
|
||||
{
|
||||
Text = $"A newer release of osu! has been found ({version} → {latestTagName}).\n\n"
|
||||
+ "Check with your package manager / provider to bring osu! up-to-date!",
|
||||
Icon = FontAwesome.Solid.Upload,
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// we shouldn't crash on a web failure. or any failure for the matter.
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user