2025-01-20 12:10:30 -06:00
|
|
|
@using ConnectionState = LANCommander.Launcher.Models.ConnectionState
|
|
|
|
|
@inject AuthenticationService AuthenticationService
|
|
|
|
|
@inject NavigationManager NavigationManager
|
2025-06-10 01:37:15 +02:00
|
|
|
@inject KeepAliveService KeepAliveService
|
2025-01-20 12:10:30 -06:00
|
|
|
|
|
|
|
|
<CascadingValue Value="ConnectionState">
|
|
|
|
|
@if (ConnectionState.IsConnected || ConnectionState.OfflineModeEnabled)
|
|
|
|
|
{
|
|
|
|
|
@Authenticated
|
|
|
|
|
}
|
2025-06-15 18:09:58 +02:00
|
|
|
else if (!IsValidating)
|
2025-01-20 12:10:30 -06:00
|
|
|
{
|
|
|
|
|
@NotAuthenticated
|
|
|
|
|
}
|
|
|
|
|
</CascadingValue>
|
|
|
|
|
|
|
|
|
|
@code {
|
|
|
|
|
[Parameter] public RenderFragment Authenticated { get; set; }
|
|
|
|
|
[Parameter] public RenderFragment NotAuthenticated { get; set; }
|
2025-06-12 04:04:04 +02:00
|
|
|
[Parameter] public bool NoAutoValidate { get; set; }
|
2025-01-20 12:10:30 -06:00
|
|
|
|
2025-06-10 01:37:15 +02:00
|
|
|
private ConnectionState ConnectionState = default!;
|
2025-06-15 18:09:58 +02:00
|
|
|
private bool IsValidating = false;
|
2025-01-20 12:10:30 -06:00
|
|
|
|
|
|
|
|
protected override async Task OnInitializedAsync()
|
2025-01-25 02:51:52 -06:00
|
|
|
{
|
2025-06-10 01:37:15 +02:00
|
|
|
ConnectionState = KeepAliveService.GetConnectionState();
|
|
|
|
|
|
2025-01-25 02:51:52 -06:00
|
|
|
AuthenticationService.OnLogin += async (sender, args) =>
|
|
|
|
|
{
|
|
|
|
|
await Validate();
|
|
|
|
|
};
|
2025-04-24 01:03:27 +02:00
|
|
|
AuthenticationService.OnRegister += async (sender, args) =>
|
|
|
|
|
{
|
|
|
|
|
await Validate();
|
|
|
|
|
};
|
|
|
|
|
|
2025-06-12 04:04:04 +02:00
|
|
|
if (!NoAutoValidate)
|
|
|
|
|
await Validate();
|
2025-01-25 02:51:52 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task Validate()
|
2025-01-20 12:10:30 -06:00
|
|
|
{
|
2025-06-15 18:09:58 +02:00
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
IsValidating = true;
|
|
|
|
|
ConnectionState.IsConnected = await AuthenticationService.ValidateConnectionAsync();
|
|
|
|
|
ConnectionState.OfflineModeEnabled = AuthenticationService.OfflineModeEnabled();
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
IsValidating = false;
|
|
|
|
|
}
|
2025-01-25 02:51:52 -06:00
|
|
|
|
|
|
|
|
await InvokeAsync(StateHasChanged);
|
2025-01-20 12:10:30 -06:00
|
|
|
}
|
|
|
|
|
}
|