From 3fe89293affaec4a0aae564e767341bcff2d0bca Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 16 Nov 2021 12:11:11 +0900 Subject: [PATCH] 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. --- osu.Desktop/OsuGameDesktop.cs | 5 ++ osu.Game/Updater/GitHubAsset.cs | 16 ++++++ osu.Game/Updater/GitHubRelease.cs | 20 +++++++ osu.Game/Updater/NoActionUpdateManager.cs | 67 +++++++++++++++++++++++ osu.Game/Updater/SimpleUpdateManager.cs | 23 -------- 5 files changed, 108 insertions(+), 23 deletions(-) create mode 100644 osu.Game/Updater/GitHubAsset.cs create mode 100644 osu.Game/Updater/GitHubRelease.cs create mode 100644 osu.Game/Updater/NoActionUpdateManager.cs diff --git a/osu.Desktop/OsuGameDesktop.cs b/osu.Desktop/OsuGameDesktop.cs index 19e1252a4d..645ea66654 100644 --- a/osu.Desktop/OsuGameDesktop.cs +++ b/osu.Desktop/OsuGameDesktop.cs @@ -93,6 +93,11 @@ namespace osu.Desktop protected override UpdateManager CreateUpdateManager() { + string packageManaged = Environment.GetEnvironmentVariable("OSU_EXTERNAL_UPDATE_PROVIDER"); + + if (!string.IsNullOrEmpty(packageManaged)) + return new NoActionUpdateManager(); + switch (RuntimeInfo.OS) { case RuntimeInfo.Platform.Windows: diff --git a/osu.Game/Updater/GitHubAsset.cs b/osu.Game/Updater/GitHubAsset.cs new file mode 100644 index 0000000000..4783161859 --- /dev/null +++ b/osu.Game/Updater/GitHubAsset.cs @@ -0,0 +1,16 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using Newtonsoft.Json; + +namespace osu.Game.Updater +{ + public class GitHubAsset + { + [JsonProperty("name")] + public string Name { get; set; } + + [JsonProperty("browser_download_url")] + public string BrowserDownloadUrl { get; set; } + } +} diff --git a/osu.Game/Updater/GitHubRelease.cs b/osu.Game/Updater/GitHubRelease.cs new file mode 100644 index 0000000000..363b2b628f --- /dev/null +++ b/osu.Game/Updater/GitHubRelease.cs @@ -0,0 +1,20 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System.Collections.Generic; +using Newtonsoft.Json; + +namespace osu.Game.Updater +{ + public class GitHubRelease + { + [JsonProperty("html_url")] + public string HtmlUrl { get; set; } + + [JsonProperty("tag_name")] + public string TagName { get; set; } + + [JsonProperty("assets")] + public List Assets { get; set; } + } +} diff --git a/osu.Game/Updater/NoActionUpdateManager.cs b/osu.Game/Updater/NoActionUpdateManager.cs new file mode 100644 index 0000000000..641263ed0f --- /dev/null +++ b/osu.Game/Updater/NoActionUpdateManager.cs @@ -0,0 +1,67 @@ +// 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 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 PerformUpdateCheck() + { + try + { + var releases = new OsuJsonWebRequest("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; + } + } +} diff --git a/osu.Game/Updater/SimpleUpdateManager.cs b/osu.Game/Updater/SimpleUpdateManager.cs index 5e466cc57f..61ca68a1ab 100644 --- a/osu.Game/Updater/SimpleUpdateManager.cs +++ b/osu.Game/Updater/SimpleUpdateManager.cs @@ -2,10 +2,8 @@ // See the LICENCE file in the repository root for full licence text. using System; -using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -using Newtonsoft.Json; using osu.Framework; using osu.Framework.Allocation; using osu.Framework.Graphics.Sprites; @@ -104,26 +102,5 @@ namespace osu.Game.Updater return bestAsset?.BrowserDownloadUrl ?? release.HtmlUrl; } - - public class GitHubRelease - { - [JsonProperty("html_url")] - public string HtmlUrl { get; set; } - - [JsonProperty("tag_name")] - public string TagName { get; set; } - - [JsonProperty("assets")] - public List Assets { get; set; } - } - - public class GitHubAsset - { - [JsonProperty("name")] - public string Name { get; set; } - - [JsonProperty("browser_download_url")] - public string BrowserDownloadUrl { get; set; } - } } }