@using LANCommander.Launcher.Models
@using Photino.Blazor.CustomWindow.Components
@namespace LANCommander.Launcher.UI
@inherits LayoutComponentBase
@inject ImportService ImportService
@inject ProfileService ProfileService
@inject AuthenticationService AuthenticationService
@inject AuthenticationClient AuthenticationClient
@inject IMessageService MessageService
@inject NavigationManager NavigationManager
@inject ModalService ModalService
@inject IJSRuntime JS
@inject ImportManagerService ImportManagerService
@inject LocalizationService LocalizationService
@inject IConnectionClient ConnectionClient
@if (ImportStatus.IsActive)
{
}
else
{
if (ConnectionClient.IsOfflineMode())
{
}
else if (ConnectionClient.IsConnected())
{
}
}
@Body
@code {
public bool Importing;
public bool Connecting;
public IMessageService Messages { get; set; }
ImportHandler ImportHandler;
ImportHandler.ImportProgressEventArgs ImportStatus = new();
private ImportProgress _importProgress => ImportService.Progress;
protected override async Task OnInitializedAsync()
{
ConnectionClient.OnOfflineModeEnabled += OnOfflineModeChanged;
ConnectionClient.OnConnect += OnConnect;
if (await AuthenticationClient.ValidateTokenAsync())
{
await AuthenticationService.Login();
await ImportManagerService.RequestImport();
await InvokeAsync(StateHasChanged);
}
}
private async void OnConnect(object? sender, EventArgs e)
{
await ImportManagerService.RequestImport();
}
public void Dispose()
{
if (ConnectionClient != null)
ConnectionClient.OnOfflineModeEnabled -= OnOfflineModeChanged;
}
async void OnOfflineModeChanged(object? sender, EventArgs eventArgs)
{
await InvokeAsync(StateHasChanged);
}
async void OnImportProcess(ImportHandler.ImportProgressEventArgs importProgress)
{
ImportStatus = importProgress;
await InvokeAsync(StateHasChanged);
}
async Task Connect()
{
Connecting = true;
if (await ConnectionClient.ConnectAsync())
{
await ProfileService.DownloadProfileInfoAsync();
MessageService.Success(LocalizationService.GetString("BackOnline"));
await InvokeAsync(StateHasChanged);
}
else
{
await ModalService.ConfirmAsync(new ConfirmOptions()
{
Title = LocalizationService.GetString("CouldNotReconnect"),
Icon = @,
Content = LocalizationService.GetString("CouldNotReconnectMessage"),
OkText = LocalizationService.GetString("Logout"),
CancelText = LocalizationService.GetString("StayOffline"),
Centered = true,
OnOk = async (e) =>
{
await Logout();
}
});
}
Connecting = false;
await InvokeAsync(StateHasChanged);
}
async Task Logout()
{
await ConnectionClient.DisconnectAsync();
await AuthenticationService.Logout();
NavigationManager.NavigateTo("/Authenticate");
}
}