1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 21:02:55 +08:00

Extract majority of token retrieval code out of LoadComponentAsync for legibility

This commit is contained in:
Dean Herbert 2021-03-25 13:48:41 +09:00
parent ff139c2056
commit 4269cb7124

View File

@ -32,6 +32,13 @@ namespace osu.Game.Screens.Play
}
protected override void LoadAsyncComplete()
{
if (!handleTokenRetrieval()) return;
base.LoadAsyncComplete();
}
private bool handleTokenRetrieval()
{
// Token request construction should happen post-load to allow derived classes to potentially prepare DI backings that are used to create the request.
var tcs = new TaskCompletionSource<bool>();
@ -39,7 +46,7 @@ namespace osu.Game.Screens.Play
if (!api.IsLoggedIn)
{
handleTokenFailure(new InvalidOperationException("API is not online."));
return;
return false;
}
var req = CreateTokenRequest();
@ -47,7 +54,7 @@ namespace osu.Game.Screens.Play
if (req == null)
{
handleTokenFailure(new InvalidOperationException("Request could not be constructed."));
return;
return false;
}
req.Success += r =>
@ -60,8 +67,7 @@ namespace osu.Game.Screens.Play
api.Queue(req);
tcs.Task.Wait();
base.LoadAsyncComplete();
return true;
void handleTokenFailure(Exception exception)
{