Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion osu.Desktop/OsuGameDesktop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public OsuGameDesktop(string[]? args = null)

protected override UpdateManager CreateUpdateManager()
{
return new NoActionUpdateManager();
return new GitHubReleaseUpdateManager();
}

public override bool RestartAppWhenExited()
Expand Down
2 changes: 1 addition & 1 deletion osu.Game/OsuGameBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
75 changes: 75 additions & 0 deletions osu.Game/Updater/GitHubReleaseUpdateManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// 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.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
{
/// <summary>
/// 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.
/// </summary>
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<bool> PerformUpdateCheck()
{
try
{
var releases = new OsuJsonWebRequest<GitHubRelease>(@"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;
}
}
}