1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-18 11:02:57 +08:00

Ensure API state is Connecting immediately on startup when credentials are present

Currently, there's a period where the API is `Offline` even though it is
about to connect (as soon as the `run` thread starts up).

This can cause any `Queue`d requests to fail if they arrive too early.

To avoid this, let's ensure the `Connecting` state is set as early as
possible.
This commit is contained in:
Dean Herbert 2025-01-14 18:18:53 +09:00
parent f6073d4ac0
commit 55ae0403d8
No known key found for this signature in database

View File

@ -111,8 +111,14 @@ namespace osu.Game.Online.API
config.BindWith(OsuSetting.UserOnlineStatus, configStatus);
// Early call to ensure the local user / "logged in" state is correct immediately.
setPlaceholderLocalUser();
if (HasLogin)
{
// Early call to ensure the local user / "logged in" state is correct immediately.
prepareForConnect();
// This is required so that Queue() requests during startup sequence don't fail due to "not logged in".
state.Value = APIState.Connecting;
}
localUser.BindValueChanged(u =>
{
@ -251,7 +257,7 @@ namespace osu.Game.Online.API
/// <returns>Whether the connection attempt was successful.</returns>
private void attemptConnect()
{
Scheduler.Add(setPlaceholderLocalUser, false);
Scheduler.Add(prepareForConnect, false);
// save the username at this point, if the user requested for it to be.
config.SetValue(OsuSetting.Username, config.Get<bool>(OsuSetting.SaveUsername) ? ProvidedUsername : string.Empty);
@ -367,7 +373,7 @@ namespace osu.Game.Online.API
/// This is useful for storing local scores and showing a placeholder username after starting the game,
/// until a valid connection has been established.
/// </summary>
private void setPlaceholderLocalUser()
private void prepareForConnect()
{
if (!localUser.IsDefault)
return;