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

Use IAPIProvider interface and correctly support scheduling from DummyAPIAccess

This commit is contained in:
Dean Herbert 2024-08-30 18:10:33 +09:00
parent 5836f497ac
commit 07611bd8f5
No known key found for this signature in database
4 changed files with 20 additions and 4 deletions

View File

@ -159,7 +159,7 @@ namespace osu.Game.Online.API
private void onTokenChanged(ValueChangedEvent<OAuthToken> e) => config.SetValue(OsuSetting.Token, config.Get<bool>(OsuSetting.SavePassword) ? authentication.TokenString : string.Empty);
internal new void Schedule(Action action) => base.Schedule(action);
void IAPIProvider.Schedule(Action action) => base.Schedule(action);
public string AccessToken => authentication.RequestAccessToken();

View File

@ -74,7 +74,7 @@ namespace osu.Game.Online.API
protected virtual string Uri => $@"{API.APIEndpointUrl}/api/v2/{Target}";
protected APIAccess API;
protected IAPIProvider API;
protected WebRequest WebRequest;
@ -109,7 +109,7 @@ namespace osu.Game.Online.API
/// <remarks>
/// This allows scheduling of operations back to the correct thread (which may be required before <see cref="Perform"/> is called).
/// </remarks>
public void AttachAPI(APIAccess apiAccess)
public void AttachAPI(IAPIProvider apiAccess)
{
if (API != null && API != apiAccess)
throw new InvalidOperationException("Attached API cannot be changed after initial set.");

View File

@ -82,6 +82,8 @@ namespace osu.Game.Online.API
public virtual void Queue(APIRequest request)
{
request.AttachAPI(this);
Schedule(() =>
{
if (HandleRequest?.Invoke(request) != true)
@ -98,10 +100,17 @@ namespace osu.Game.Online.API
});
}
public void Perform(APIRequest request) => HandleRequest?.Invoke(request);
void IAPIProvider.Schedule(Action action) => base.Schedule(action);
public void Perform(APIRequest request)
{
request.AttachAPI(this);
HandleRequest?.Invoke(request);
}
public Task PerformAsync(APIRequest request)
{
request.AttachAPI(this);
HandleRequest?.Invoke(request);
return Task.CompletedTask;
}
@ -155,6 +164,8 @@ namespace osu.Game.Online.API
state.Value = APIState.Connecting;
LastLoginError = null;
request.AttachAPI(this);
// if no handler installed / handler can't handle verification, just assume that the server would verify for simplicity.
if (HandleRequest?.Invoke(request) != true)
onSuccessfulLogin();

View File

@ -134,6 +134,11 @@ namespace osu.Game.Online.API
/// </summary>
void UpdateStatistics(UserStatistics newStatistics);
/// <summary>
/// Schedule a callback to run on the update thread.
/// </summary>
internal void Schedule(Action action);
/// <summary>
/// Constructs a new <see cref="IHubClientConnector"/>. May be null if not supported.
/// </summary>