mirror of
https://github.com/ppy/osu.git
synced 2024-11-15 01:23:44 +08:00
Resurrect SimpleUpdateManager as MobileUpdateNotifier
While removing the desktop specific logic from it
This commit is contained in:
parent
4898cff7a4
commit
71816c09dc
@ -80,7 +80,7 @@ namespace osu.Android
|
|||||||
host.Window.CursorState |= CursorState.Hidden;
|
host.Window.CursorState |= CursorState.Hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override UpdateManager CreateUpdateManager() => new SimpleUpdateManager();
|
protected override UpdateManager CreateUpdateManager() => new MobileUpdateNotifier();
|
||||||
|
|
||||||
protected override BatteryInfo CreateBatteryInfo() => new AndroidBatteryInfo();
|
protected override BatteryInfo CreateBatteryInfo() => new AndroidBatteryInfo();
|
||||||
|
|
||||||
|
102
osu.Game/Updater/MobileUpdateNotifier.cs
Normal file
102
osu.Game/Updater/MobileUpdateNotifier.cs
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
// 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;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using osu.Framework;
|
||||||
|
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 for mobile platforms.
|
||||||
|
/// Installation is left up to the user.
|
||||||
|
/// </summary>
|
||||||
|
public partial class MobileUpdateNotifier : 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<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 && tryGetBestUrl(latest, out string? url))
|
||||||
|
{
|
||||||
|
Notifications.Post(new SimpleNotification
|
||||||
|
{
|
||||||
|
Text = $"A newer release of osu! has been found ({version} → {latestTagName}).\n\n"
|
||||||
|
+ "Click here to download the new version, which can be installed over the top of your existing installation",
|
||||||
|
Icon = FontAwesome.Solid.Download,
|
||||||
|
Activated = () =>
|
||||||
|
{
|
||||||
|
host.OpenUrlExternally(url);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
// we shouldn't crash on a web failure. or any failure for the matter.
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool tryGetBestUrl(GitHubRelease release, [NotNullWhen(true)] out string? url)
|
||||||
|
{
|
||||||
|
url = null;
|
||||||
|
GitHubAsset? bestAsset = null;
|
||||||
|
|
||||||
|
switch (RuntimeInfo.OS)
|
||||||
|
{
|
||||||
|
case RuntimeInfo.Platform.iOS:
|
||||||
|
if (release.Assets?.Exists(f => f.Name.EndsWith(".ipa", StringComparison.Ordinal)) == true)
|
||||||
|
// iOS releases are available via testflight. this link seems to work well enough for now.
|
||||||
|
// see https://stackoverflow.com/a/32960501
|
||||||
|
url = "itms-beta://beta.itunes.apple.com/v1/app/1447765923";
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case RuntimeInfo.Platform.Android:
|
||||||
|
if (release.Assets?.Exists(f => f.Name.EndsWith(".apk", StringComparison.Ordinal)) == true)
|
||||||
|
// on our testing device using the .apk URL causes the download to magically disappear.
|
||||||
|
url = release.HtmlUrl;
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
url ??= bestAsset?.BrowserDownloadUrl;
|
||||||
|
return url != null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -15,7 +15,7 @@ namespace osu.iOS
|
|||||||
{
|
{
|
||||||
public override Version AssemblyVersion => new Version(NSBundle.MainBundle.InfoDictionary["CFBundleVersion"].ToString());
|
public override Version AssemblyVersion => new Version(NSBundle.MainBundle.InfoDictionary["CFBundleVersion"].ToString());
|
||||||
|
|
||||||
protected override UpdateManager CreateUpdateManager() => new SimpleUpdateManager();
|
protected override UpdateManager CreateUpdateManager() => new MobileUpdateNotifier();
|
||||||
|
|
||||||
protected override BatteryInfo CreateBatteryInfo() => new IOSBatteryInfo();
|
protected override BatteryInfo CreateBatteryInfo() => new IOSBatteryInfo();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user