Selector/Selector.MAUI/App.xaml.cs

52 lines
1.2 KiB
C#
Raw Normal View History

using Microsoft.AspNetCore.SignalR.Client;
using Microsoft.Extensions.Logging;
using Selector.SignalR;
namespace Selector.MAUI;
2023-01-21 16:55:51 +00:00
public partial class App : Application
{
private readonly NowHubClient nowClient;
private readonly ILogger<App> logger;
public App(NowHubClient nowClient, ILogger<App> logger)
2023-01-21 16:55:51 +00:00
{
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;
}
2023-01-21 16:55:51 +00:00
}