Make APIAccess a component

This commit is contained in:
Dean Herbert
2018-03-14 10:42:58 +09:00
parent 83cd2fd317
commit 07642546bb
5 changed files with 14 additions and 41 deletions

View File

@ -8,15 +8,15 @@ using System.Diagnostics;
using System.Net; using System.Net;
using System.Threading; using System.Threading;
using osu.Framework.Configuration; using osu.Framework.Configuration;
using osu.Framework.Graphics;
using osu.Framework.Logging; using osu.Framework.Logging;
using osu.Framework.Threading;
using osu.Game.Configuration; using osu.Game.Configuration;
using osu.Game.Online.API.Requests; using osu.Game.Online.API.Requests;
using osu.Game.Users; using osu.Game.Users;
namespace osu.Game.Online.API namespace osu.Game.Online.API
{ {
public class APIAccess : IAPIProvider, IDisposable public class APIAccess : Component, IAPIProvider
{ {
private readonly OsuConfigManager config; private readonly OsuConfigManager config;
private readonly OAuth authentication; private readonly OAuth authentication;
@ -27,8 +27,6 @@ namespace osu.Game.Online.API
private ConcurrentQueue<APIRequest> queue = new ConcurrentQueue<APIRequest>(); private ConcurrentQueue<APIRequest> queue = new ConcurrentQueue<APIRequest>();
public readonly Scheduler Scheduler = new Scheduler();
/// <summary> /// <summary>
/// The username/email provided by the user when initiating a login. /// The username/email provided by the user when initiating a login.
/// </summary> /// </summary>
@ -306,27 +304,13 @@ namespace osu.Game.Online.API
Id = 1, Id = 1,
}; };
public void Update() protected override void Dispose(bool isDisposing)
{ {
Scheduler.Update(); base.Dispose(isDisposing);
}
private void dispose()
{
config.Set(OsuSetting.Token, config.Get<bool>(OsuSetting.SavePassword) ? Token : string.Empty); config.Set(OsuSetting.Token, config.Get<bool>(OsuSetting.SavePassword) ? Token : string.Empty);
config.Save(); config.Save();
} }
public void Dispose()
{
dispose();
GC.SuppressFinalize(this);
}
~APIAccess()
{
dispose();
}
} }
public enum APIState public enum APIState

View File

@ -14,7 +14,7 @@ namespace osu.Game.Online.API
return request; return request;
} }
private void request_Progress(long current, long total) => API.Scheduler.Add(delegate { Progress?.Invoke(current, total); }); private void request_Progress(long current, long total) => Progress?.Invoke(current, total);
protected APIDownloadRequest() protected APIDownloadRequest()
{ {

View File

@ -1,13 +1,12 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>. // Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework;
using osu.Framework.Configuration; using osu.Framework.Configuration;
using osu.Game.Users; using osu.Game.Users;
namespace osu.Game.Online.API namespace osu.Game.Online.API
{ {
public interface IAPIProvider : IUpdateable public interface IAPIProvider
{ {
/// <summary> /// <summary>
/// The local user. /// The local user.

View File

@ -56,8 +56,6 @@ namespace osu.Game
protected override string MainResourceFile => @"osu.Game.Resources.dll"; protected override string MainResourceFile => @"osu.Game.Resources.dll";
public APIAccess API;
private Container content; private Container content;
protected override Container<Drawable> Content => content; protected override Container<Drawable> Content => content;
@ -108,12 +106,14 @@ namespace osu.Game
dependencies.Cache(SkinManager = new SkinManager(Host.Storage, contextFactory, Host, Audio)); dependencies.Cache(SkinManager = new SkinManager(Host.Storage, contextFactory, Host, Audio));
dependencies.Cache(API = new APIAccess(LocalConfig)); var api = new APIAccess(LocalConfig);
dependencies.CacheAs<IAPIProvider>(API);
dependencies.Cache(api);
dependencies.CacheAs<IAPIProvider>(api);
dependencies.Cache(RulesetStore = new RulesetStore(contextFactory)); dependencies.Cache(RulesetStore = new RulesetStore(contextFactory));
dependencies.Cache(FileStore = new FileStore(contextFactory, Host.Storage)); dependencies.Cache(FileStore = new FileStore(contextFactory, Host.Storage));
dependencies.Cache(BeatmapManager = new BeatmapManager(Host.Storage, contextFactory, RulesetStore, API, Host)); dependencies.Cache(BeatmapManager = new BeatmapManager(Host.Storage, contextFactory, RulesetStore, api, Host));
dependencies.Cache(ScoreStore = new ScoreStore(Host.Storage, contextFactory, Host, BeatmapManager, RulesetStore)); dependencies.Cache(ScoreStore = new ScoreStore(Host.Storage, contextFactory, Host, BeatmapManager, RulesetStore));
dependencies.Cache(KeyBindingStore = new KeyBindingStore(contextFactory, RulesetStore)); dependencies.Cache(KeyBindingStore = new KeyBindingStore(contextFactory, RulesetStore));
dependencies.Cache(SettingsStore = new SettingsStore(contextFactory)); dependencies.Cache(SettingsStore = new SettingsStore(contextFactory));
@ -180,6 +180,8 @@ namespace osu.Game
}; };
FileStore.Cleanup(); FileStore.Cleanup();
AddInternal(api);
} }
private void runMigrations() private void runMigrations()
@ -237,18 +239,6 @@ namespace osu.Game
base.SetHost(host); base.SetHost(host);
} }
protected override void Update()
{
base.Update();
API.Update();
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
API.Dispose();
}
private readonly List<ICanAcceptFiles> fileImporters = new List<ICanAcceptFiles>(); private readonly List<ICanAcceptFiles> fileImporters = new List<ICanAcceptFiles>();
public void Import(params string[] paths) public void Import(params string[] paths)

View File

@ -186,7 +186,7 @@ namespace osu.Game.Overlays.Direct
progressBar.FadeOut(500); progressBar.FadeOut(500);
}; };
request.DownloadProgressed += progress => progressBar.Current.Value = progress; request.DownloadProgressed += progress => Schedule(() => progressBar.Current.Value = progress);
request.Success += data => request.Success += data =>
{ {