diff --git a/osu.Desktop/OsuGameDesktop.cs b/osu.Desktop/OsuGameDesktop.cs index 4bd51cdb09..677a22a2d5 100644 --- a/osu.Desktop/OsuGameDesktop.cs +++ b/osu.Desktop/OsuGameDesktop.cs @@ -110,7 +110,7 @@ public OsuGameDesktop(string[]? args = null) protected override UpdateManager CreateUpdateManager() { - return new NoActionUpdateManager(); + return new GitHubReleaseUpdateManager(); } public override bool RestartAppWhenExited() diff --git a/osu.Game/OsuGameBase.cs b/osu.Game/OsuGameBase.cs index 5c8871142b..31d4833146 100644 --- a/osu.Game/OsuGameBase.cs +++ b/osu.Game/OsuGameBase.cs @@ -118,7 +118,7 @@ public virtual EndpointConfiguration CreateEndpoints() => public bool IsDeployedBuild => AssemblyVersion.Major > 0; - internal const string BUILD_SUFFIX = @"TEST-Open"; + internal const string BUILD_SUFFIX = @"LGA"; public virtual string Version { diff --git a/osu.Game/Updater/GitHubReleaseUpdateManager.cs b/osu.Game/Updater/GitHubReleaseUpdateManager.cs new file mode 100644 index 0000000000..cda883fdb0 --- /dev/null +++ b/osu.Game/Updater/GitHubReleaseUpdateManager.cs @@ -0,0 +1,75 @@ +// Copyright (c) ppy Pty Ltd . 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 +{ + /// + /// 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. + /// + public partial class GitHubReleaseUpdateManager : UpdateManager + { + private string version = null!; + + [Resolved] + private GameHost host { get; set; } = null!; + + [BackgroundDependencyLoader] + private void load(OsuGameBase game) + { + version = game.Version; + } + + protected override async Task PerformUpdateCheck() + { + try + { + var releases = new OsuJsonWebRequest(@"https://api.github.com/repos/ILW8/osu-TEST-Open/releases/latest"); + + await releases.PerformAsync().ConfigureAwait(false); + + var latest = releases.ResponseObject; + + if (latest == null) + return false; + + // 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" + + "Click here to open the downloads page!", + Icon = FontAwesome.Solid.Download, + Activated = () => + { + host.OpenUrlExternally(latest.HtmlUrl); + return true; + } + }); + + return true; + } + } + catch + { + // we shouldn't crash on a web failure. or any failure for the matter. + return true; + } + + return false; + } + } +}