Skip to content

Commit

Permalink
Merge pull request ppy#26930 from Susko3/suggest-update-only-if-avail…
Browse files Browse the repository at this point in the history
…able

Suggest to update only if the latest release is available for the current platform
  • Loading branch information
peppy authored Feb 10, 2024
2 parents 4a516cb + f92751a commit 32bfd87
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions osu.Game/Updater/SimpleUpdateManager.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// 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.

#nullable disable

using System;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
Expand All @@ -22,10 +21,10 @@ namespace osu.Game.Updater
/// </summary>
public partial class SimpleUpdateManager : UpdateManager
{
private string version;
private string version = null!;

[Resolved]
private GameHost host { get; set; }
private GameHost host { get; set; } = null!;

[BackgroundDependencyLoader]
private void load(OsuGameBase game)
Expand All @@ -48,7 +47,7 @@ protected override async Task<bool> PerformUpdateCheck()
version = version.Split('-').First();
string latestTagName = latest.TagName.Split('-').First();

if (latestTagName != version)
if (latestTagName != version && tryGetBestUrl(latest, out string? url))
{
Notifications.Post(new SimpleNotification
{
Expand All @@ -57,7 +56,7 @@ protected override async Task<bool> PerformUpdateCheck()
Icon = FontAwesome.Solid.Download,
Activated = () =>
{
host.OpenUrlExternally(getBestUrl(latest));
host.OpenUrlExternally(url);
return true;
}
});
Expand All @@ -74,9 +73,10 @@ protected override async Task<bool> PerformUpdateCheck()
return false;
}

private string getBestUrl(GitHubRelease release)
private bool tryGetBestUrl(GitHubRelease release, [NotNullWhen(true)] out string? url)
{
GitHubAsset bestAsset = null;
url = null;
GitHubAsset? bestAsset = null;

switch (RuntimeInfo.OS)
{
Expand All @@ -94,17 +94,23 @@ private string getBestUrl(GitHubRelease release)
break;

case RuntimeInfo.Platform.iOS:
// iOS releases are available via testflight. this link seems to work well enough for now.
// see https://stackoverflow.com/a/32960501
return "itms-beta://beta.itunes.apple.com/v1/app/1447765923";
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:
// on our testing device this causes the download to magically disappear.
//bestAsset = release.Assets?.Find(f => f.Name.EndsWith(".apk"));
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;
}

return bestAsset?.BrowserDownloadUrl ?? release.HtmlUrl;
url ??= bestAsset?.BrowserDownloadUrl;
return url != null;
}
}
}

0 comments on commit 32bfd87

Please sign in to comment.