Skip to content

Commit 71816c0

Browse files
Resurrect SimpleUpdateManager as MobileUpdateNotifier
While removing the desktop specific logic from it
1 parent 4898cff commit 71816c0

File tree

3 files changed

+104
-2
lines changed

3 files changed

+104
-2
lines changed

osu.Android/OsuGameAndroid.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public override void SetHost(GameHost host)
8080
host.Window.CursorState |= CursorState.Hidden;
8181
}
8282

83-
protected override UpdateManager CreateUpdateManager() => new SimpleUpdateManager();
83+
protected override UpdateManager CreateUpdateManager() => new MobileUpdateNotifier();
8484

8585
protected override BatteryInfo CreateBatteryInfo() => new AndroidBatteryInfo();
8686

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
2+
// See the LICENCE file in the repository root for full licence text.
3+
4+
using System;
5+
using System.Diagnostics.CodeAnalysis;
6+
using System.Linq;
7+
using System.Threading.Tasks;
8+
using osu.Framework;
9+
using osu.Framework.Allocation;
10+
using osu.Framework.Graphics.Sprites;
11+
using osu.Framework.Platform;
12+
using osu.Game.Online.API;
13+
using osu.Game.Overlays.Notifications;
14+
15+
namespace osu.Game.Updater
16+
{
17+
/// <summary>
18+
/// An update manager that shows notifications if a newer release is detected for mobile platforms.
19+
/// Installation is left up to the user.
20+
/// </summary>
21+
public partial class MobileUpdateNotifier : UpdateManager
22+
{
23+
private string version = null!;
24+
25+
[Resolved]
26+
private GameHost host { get; set; } = null!;
27+
28+
[BackgroundDependencyLoader]
29+
private void load(OsuGameBase game)
30+
{
31+
version = game.Version;
32+
}
33+
34+
protected override async Task<bool> PerformUpdateCheck()
35+
{
36+
try
37+
{
38+
var releases = new OsuJsonWebRequest<GitHubRelease>("https://api.github.com/repos/ppy/osu/releases/latest");
39+
40+
await releases.PerformAsync().ConfigureAwait(false);
41+
42+
var latest = releases.ResponseObject;
43+
44+
// avoid any discrepancies due to build suffixes for now.
45+
// eventually we will want to support release streams and consider these.
46+
version = version.Split('-').First();
47+
string latestTagName = latest.TagName.Split('-').First();
48+
49+
if (latestTagName != version && tryGetBestUrl(latest, out string? url))
50+
{
51+
Notifications.Post(new SimpleNotification
52+
{
53+
Text = $"A newer release of osu! has been found ({version}{latestTagName}).\n\n"
54+
+ "Click here to download the new version, which can be installed over the top of your existing installation",
55+
Icon = FontAwesome.Solid.Download,
56+
Activated = () =>
57+
{
58+
host.OpenUrlExternally(url);
59+
return true;
60+
}
61+
});
62+
63+
return true;
64+
}
65+
}
66+
catch
67+
{
68+
// we shouldn't crash on a web failure. or any failure for the matter.
69+
return true;
70+
}
71+
72+
return false;
73+
}
74+
75+
private bool tryGetBestUrl(GitHubRelease release, [NotNullWhen(true)] out string? url)
76+
{
77+
url = null;
78+
GitHubAsset? bestAsset = null;
79+
80+
switch (RuntimeInfo.OS)
81+
{
82+
case RuntimeInfo.Platform.iOS:
83+
if (release.Assets?.Exists(f => f.Name.EndsWith(".ipa", StringComparison.Ordinal)) == true)
84+
// iOS releases are available via testflight. this link seems to work well enough for now.
85+
// see https://stackoverflow.com/a/32960501
86+
url = "itms-beta://beta.itunes.apple.com/v1/app/1447765923";
87+
88+
break;
89+
90+
case RuntimeInfo.Platform.Android:
91+
if (release.Assets?.Exists(f => f.Name.EndsWith(".apk", StringComparison.Ordinal)) == true)
92+
// on our testing device using the .apk URL causes the download to magically disappear.
93+
url = release.HtmlUrl;
94+
95+
break;
96+
}
97+
98+
url ??= bestAsset?.BrowserDownloadUrl;
99+
return url != null;
100+
}
101+
}
102+
}

osu.iOS/OsuGameIOS.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public partial class OsuGameIOS : OsuGame
1515
{
1616
public override Version AssemblyVersion => new Version(NSBundle.MainBundle.InfoDictionary["CFBundleVersion"].ToString());
1717

18-
protected override UpdateManager CreateUpdateManager() => new SimpleUpdateManager();
18+
protected override UpdateManager CreateUpdateManager() => new MobileUpdateNotifier();
1919

2020
protected override BatteryInfo CreateBatteryInfo() => new IOSBatteryInfo();
2121

0 commit comments

Comments
 (0)