diff --git a/osu.Desktop.VisualTests/Tests/TestCaseChatDisplay.cs b/osu.Desktop.VisualTests/Tests/TestCaseChatDisplay.cs index cb412f8c97..83627a519a 100644 --- a/osu.Desktop.VisualTests/Tests/TestCaseChatDisplay.cs +++ b/osu.Desktop.VisualTests/Tests/TestCaseChatDisplay.cs @@ -45,7 +45,7 @@ namespace osu.Desktop.VisualTests.Tests { base.Reset(); - if (api.State != APIAccess.APIState.Online) + if (api.State != APIState.Online) api.OnStateChange += delegate { initializeChannels(); }; else initializeChannels(); @@ -65,7 +65,7 @@ namespace osu.Desktop.VisualTests.Tests { careChannels = new List(); - if (api.State != APIAccess.APIState.Online) + if (api.State != APIState.Online) return; Add(flow = new FlowContainer diff --git a/osu.Game/Online/API/APIAccess.cs b/osu.Game/Online/API/APIAccess.cs index a7b2239355..578386c4f8 100644 --- a/osu.Game/Online/API/APIAccess.cs +++ b/osu.Game/Online/API/APIAccess.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Concurrent; +using System.Collections.Generic; using System.Net; using System.Threading; using osu.Framework; @@ -65,6 +66,18 @@ namespace osu.Game.Online.API thread.Start(); } + private List components = new List(); + + public void Register(IOnlineComponent component) + { + components.Add(component); + } + + public void Unregister(IOnlineComponent component) + { + components.Remove(component); + } + public string AccessToken => authentication.RequestAccessToken(); /// @@ -221,6 +234,7 @@ namespace osu.Game.Online.API log.Add($@"We just went {newState}!"); Scheduler.Add(delegate { + components.ForEach(c => c.APIStateChanged(this, newState)); OnStateChange?.Invoke(oldState, newState); }); } @@ -237,29 +251,6 @@ namespace osu.Game.Online.API public delegate void StateChangeDelegate(APIState oldState, APIState newState); - public enum APIState - { - /// - /// We cannot login (not enough credentials). - /// - Offline, - - /// - /// We are having connectivity issues. - /// - Failing, - - /// - /// We are in the process of (re-)connecting. - /// - Connecting, - - /// - /// We are online. - /// - Online - } - private void flushQueue(bool failOldRequests = true) { var oldQueue = queue; @@ -286,4 +277,27 @@ namespace osu.Game.Online.API Scheduler.Update(); } } + + public enum APIState + { + /// + /// We cannot login (not enough credentials). + /// + Offline, + + /// + /// We are having connectivity issues. + /// + Failing, + + /// + /// We are in the process of (re-)connecting. + /// + Connecting, + + /// + /// We are online. + /// + Online + } } diff --git a/osu.Game/Online/API/IOnlineComponent.cs b/osu.Game/Online/API/IOnlineComponent.cs new file mode 100644 index 0000000000..0208384921 --- /dev/null +++ b/osu.Game/Online/API/IOnlineComponent.cs @@ -0,0 +1,16 @@ +//Copyright (c) 2007-2016 ppy Pty Ltd . +//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace osu.Game.Online.API +{ + public interface IOnlineComponent + { + void APIStateChanged(APIAccess api, APIState state); + } +} diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index f4d0749080..2c28be06b1 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -69,6 +69,7 @@ +