Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for displaying "system title" on main menu #26172

Merged
merged 12 commits into from
Dec 28, 2023
Prev Previous commit
Next Next commit
Retrieve system title from online source
  • Loading branch information
bdach committed Dec 27, 2023

Verified

This commit was signed with the committer’s verified signature.
peppy Dean Herbert
commit a3f720bc627f27d6bcc9fe36c011190010930b0d
15 changes: 15 additions & 0 deletions osu.Game/Online/API/Requests/GetSystemTitleRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// 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 osu.Game.Online.API.Requests.Responses;

namespace osu.Game.Online.API.Requests
{
public class GetSystemTitleRequest : OsuJsonWebRequest<APISystemTitle>
{
public GetSystemTitleRequest()
: base(@"https://assets.ppy.sh/lazer-status.json")
Copy link
Collaborator Author

@bdach bdach Dec 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Astute readers will inevitably point out that this (a) doesn't exist yet, (b) is not an API call.

I agreed upon doing this in this way with @peppy beforehand. Can be tested via e.g. python3 -m http.server or something (and changing URL, and probably also allowing insecure requests).

{
}
}
}
2 changes: 1 addition & 1 deletion osu.Game/Online/API/Requests/Responses/APISystemTitle.cs
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@

namespace osu.Game.Online.API.Requests.Responses
{
public class APISystemTitle
public record APISystemTitle
{
[JsonProperty(@"image")]
public string Image { get; set; } = string.Empty;
23 changes: 23 additions & 0 deletions osu.Game/Screens/Menu/SystemTitle.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// 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.Threading;
using System.Threading.Tasks;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
@@ -10,6 +12,7 @@
using osu.Framework.Graphics.Textures;
using osu.Framework.Input.Events;
using osu.Framework.Platform;
using osu.Game.Online.API.Requests;
using osu.Game.Online.API.Requests.Responses;

namespace osu.Game.Screens.Menu
@@ -57,6 +60,26 @@ protected override void LoadComplete()
base.LoadComplete();

Current.BindValueChanged(_ => loadNewImage(), true);

checkForUpdates();
Scheduler.AddDelayed(checkForUpdates, TimeSpan.FromMinutes(15).TotalMilliseconds, true);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this polling is necessary. Probably can be removed if just a once-off call at startup is deemed acceptable.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refreshing is best. It will already only attempt a refresh when returning to the main menu, which should be pretty fine. I'd almost say to just check each time we return, but I guess a bit of delay is worth having.

}

private void checkForUpdates()
{
var request = new GetSystemTitleRequest();
Task.Run(() => request.Perform())
.ContinueWith(r =>
{
if (r.IsCompletedSuccessfully)
Schedule(() => Current.Value = request.ResponseObject);

// if the request failed, "observe" the exception.
// it isn't very important why this failed, as it's only for display.
// the inner error will be logged by framework mechanisms anyway.
if (r.IsFaulted)
_ = r.Exception;
});
}

private void loadNewImage()