diff --git a/Selector.MAUI/App.xaml.cs b/Selector.MAUI/App.xaml.cs index 01e694c..ff7334e 100644 --- a/Selector.MAUI/App.xaml.cs +++ b/Selector.MAUI/App.xaml.cs @@ -1,12 +1,51 @@ -namespace Selector.MAUI; +using Microsoft.AspNetCore.SignalR.Client; +using Microsoft.Extensions.Logging; +using Selector.SignalR; + +namespace Selector.MAUI; public partial class App : Application { - public App() + private readonly NowHubClient nowClient; + private readonly ILogger logger; + + public App(NowHubClient nowClient, ILogger logger) { InitializeComponent(); MainPage = new MainPage(); - } + this.nowClient = nowClient; + this.logger = logger; + } + + protected override Window CreateWindow(IActivationState activationState) + { + Window window = base.CreateWindow(activationState); + + window.Resumed += async (s, e) => + { + try + { + logger.LogInformation("Window resumed, reconnecting hubs"); + + if (nowClient.State == HubConnectionState.Disconnected) + { + await nowClient.StartAsync(); + } + + await nowClient.OnConnected(); + + logger.LogInformation("Hubs reconnected"); + + } + catch(Exception ex) + { + logger.LogError(ex, "Error while reconnecting hubs"); + } + + }; + + return window; + } } diff --git a/Selector.MAUI/Services/SelectorNetClient.cs b/Selector.MAUI/Services/SelectorNetClient.cs index 4e5fa28..bf47068 100644 --- a/Selector.MAUI/Services/SelectorNetClient.cs +++ b/Selector.MAUI/Services/SelectorNetClient.cs @@ -1,5 +1,6 @@ using System; using System.Net; +using System.Net.Http.Headers; using System.Net.Http.Json; using Selector.SignalR; @@ -33,7 +34,8 @@ public class SelectorNetClient : ISelectorNetClient // _baseUrl = "https://selector.sarsoo.xyz"; //} - _baseUrl = "http://localhost:5000"; + //_baseUrl = "http://localhost:5000"; + _baseUrl = "https://selector.sarsoo.xyz"; } public async Task GetToken(string username, string password) @@ -54,7 +56,10 @@ public class SelectorNetClient : ISelectorNetClient { ArgumentNullException.ThrowIfNullOrEmpty(currentKey); - var result = await _client.PostAsync(_baseUrl + "/api/auth/token", new StringContent(string.Empty)); + var request = new HttpRequestMessage(HttpMethod.Post, _baseUrl + "/api/auth/token"); + request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", currentKey); + + var result = await _client.SendAsync(request); return FormTokenResponse(result); } diff --git a/Selector.MAUI/Shared/NavMenu.razor b/Selector.MAUI/Shared/NavMenu.razor index 4b2be8b..aa02e08 100644 --- a/Selector.MAUI/Shared/NavMenu.razor +++ b/Selector.MAUI/Shared/NavMenu.razor @@ -3,7 +3,7 @@