2025-01-05 21:09:57 -06:00
|
|
|
@using LANCommander.Launcher.Models
|
|
|
|
|
@using LANCommander.SDK.Models
|
|
|
|
|
@using ListItem = AntDesign.ListItem
|
|
|
|
|
@inject NavigationManager NavigationManager
|
2025-01-15 02:28:11 -06:00
|
|
|
@inject SDK.Client Client
|
|
|
|
|
@inject AuthenticationService AuthenticationService
|
Add localization support to launcher
Adds localization across the launcher and includes English, German, Spanish, French, Italian, Japanese, Korean, Dutch, Portuguese, Ukranian, and Chinese. These localizations were generated by Claude 3.5 and need to be reviewed by a human for accuracy.
2025-08-18 21:29:38 -05:00
|
|
|
@inject LocalizationService LocalizationService
|
2025-01-05 21:09:57 -06:00
|
|
|
|
|
|
|
|
<PageHeader>
|
|
|
|
|
<TitleTemplate>
|
Add localization support to launcher
Adds localization across the launcher and includes English, German, Spanish, French, Italian, Japanese, Korean, Dutch, Portuguese, Ukranian, and Chinese. These localizations were generated by Claude 3.5 and need to be reviewed by a human for accuracy.
2025-08-18 21:29:38 -05:00
|
|
|
@LocalizationService.GetString("Connect")
|
2025-01-05 21:09:57 -06:00
|
|
|
</TitleTemplate>
|
|
|
|
|
</PageHeader>
|
|
|
|
|
|
2025-02-21 22:50:32 -06:00
|
|
|
<Form Model="Model" OnFinish="() => SelectServer(ServerAddress)">
|
2025-06-10 01:49:32 +02:00
|
|
|
|
|
|
|
|
@if (OfflineModeAvailable)
|
|
|
|
|
{
|
Add localization support to launcher
Adds localization across the launcher and includes English, German, Spanish, French, Italian, Japanese, Korean, Dutch, Portuguese, Ukranian, and Chinese. These localizations were generated by Claude 3.5 and need to be reviewed by a human for accuracy.
2025-08-18 21:29:38 -05:00
|
|
|
<Alert Message="@LocalizationService.GetString("ServerOfflineMessage")" Type="AlertType.Warning" ShowIcon="true" Style="margin-bottom: 16px;" />
|
2025-06-10 01:49:32 +02:00
|
|
|
}
|
|
|
|
|
|
2025-01-05 21:09:57 -06:00
|
|
|
<FormItem>
|
|
|
|
|
<Flex Gap="FlexGap.Small">
|
Add localization support to launcher
Adds localization across the launcher and includes English, German, Spanish, French, Italian, Japanese, Korean, Dutch, Portuguese, Ukranian, and Chinese. These localizations were generated by Claude 3.5 and need to be reviewed by a human for accuracy.
2025-08-18 21:29:38 -05:00
|
|
|
<Input @bind-Value="ServerAddress" Placeholder="@LocalizationService.GetString("ServerAddressPlaceholder")" AutoFocus Disabled="Connecting" />
|
|
|
|
|
<Button Type="ButtonType.Primary" HtmlType="submit" Disabled="Connecting" Loading="Connecting">@LocalizationService.GetString("Connect")</Button>
|
2025-06-10 01:49:32 +02:00
|
|
|
|
|
|
|
|
@if (OfflineModeAvailable)
|
|
|
|
|
{
|
Add localization support to launcher
Adds localization across the launcher and includes English, German, Spanish, French, Italian, Japanese, Korean, Dutch, Portuguese, Ukranian, and Chinese. These localizations were generated by Claude 3.5 and need to be reviewed by a human for accuracy.
2025-08-18 21:29:38 -05:00
|
|
|
<Button OnClick="() => OfflineMode()">@LocalizationService.GetString("Offline")</Button>
|
2025-06-10 01:49:32 +02:00
|
|
|
}
|
2025-01-05 21:09:57 -06:00
|
|
|
</Flex>
|
|
|
|
|
</FormItem>
|
|
|
|
|
</Form>
|
|
|
|
|
|
Add localization support to launcher
Adds localization across the launcher and includes English, German, Spanish, French, Italian, Japanese, Korean, Dutch, Portuguese, Ukranian, and Chinese. These localizations were generated by Claude 3.5 and need to be reviewed by a human for accuracy.
2025-08-18 21:29:38 -05:00
|
|
|
<Divider Text="@LocalizationService.GetString("Discovered")" Orientation="DividerOrientation.Center" />
|
2025-01-05 21:09:57 -06:00
|
|
|
|
|
|
|
|
<AntList DataSource="DiscoveredServers">
|
|
|
|
|
<ChildContent>
|
|
|
|
|
<ListItem OnClick="() => SelectServer(context.Address.ToString())">
|
|
|
|
|
<ListItemMeta Title="@context.Name" Description="@context.Address.ToString()"/>
|
|
|
|
|
</ListItem>
|
|
|
|
|
</ChildContent>
|
|
|
|
|
|
|
|
|
|
<LoadMore>
|
|
|
|
|
<Flex Justify="FlexJustify.Center" Class="load-more">
|
|
|
|
|
@if (BeaconActive)
|
|
|
|
|
{
|
2025-06-10 01:57:22 +02:00
|
|
|
<Dropdown Trigger="@(new [] { Trigger.Hover })">
|
|
|
|
|
<Overlay>
|
|
|
|
|
<Menu>
|
Add localization support to launcher
Adds localization across the launcher and includes English, German, Spanish, French, Italian, Japanese, Korean, Dutch, Portuguese, Ukranian, and Chinese. These localizations were generated by Claude 3.5 and need to be reviewed by a human for accuracy.
2025-08-18 21:29:38 -05:00
|
|
|
<MenuItem Key="Cancel" OnClick="CancelBeacon">@LocalizationService.GetString("Cancel")</MenuItem>
|
2025-06-10 01:57:22 +02:00
|
|
|
</Menu>
|
|
|
|
|
</Overlay>
|
|
|
|
|
<ChildContent>
|
Add localization support to launcher
Adds localization across the launcher and includes English, German, Spanish, French, Italian, Japanese, Korean, Dutch, Portuguese, Ukranian, and Chinese. These localizations were generated by Claude 3.5 and need to be reviewed by a human for accuracy.
2025-08-18 21:29:38 -05:00
|
|
|
<Button Type="ButtonType.Primary" Loading="true" Disabled>@LocalizationService.GetString("Scanning")</Button>
|
2025-06-10 01:57:22 +02:00
|
|
|
</ChildContent>
|
|
|
|
|
</Dropdown>
|
2025-01-05 21:09:57 -06:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
Add localization support to launcher
Adds localization across the launcher and includes English, German, Spanish, French, Italian, Japanese, Korean, Dutch, Portuguese, Ukranian, and Chinese. These localizations were generated by Claude 3.5 and need to be reviewed by a human for accuracy.
2025-08-18 21:29:38 -05:00
|
|
|
<Button Type="ButtonType.Primary" OnClick="() => ActivateBeacon()">@LocalizationService.GetString("Rescan")</Button>
|
2025-01-05 21:09:57 -06:00
|
|
|
}
|
|
|
|
|
</Flex>
|
|
|
|
|
</LoadMore>
|
|
|
|
|
</AntList>
|
|
|
|
|
|
|
|
|
|
@code {
|
2025-01-20 12:10:30 -06:00
|
|
|
[Parameter] public EventCallback<string> OnSelected { get; set; }
|
2025-03-11 01:11:20 -05:00
|
|
|
[Parameter] public bool Connecting { get; set; } = false;
|
2025-06-10 01:57:22 +02:00
|
|
|
bool IsInitializing = false;
|
|
|
|
|
|
2025-01-05 21:09:57 -06:00
|
|
|
bool BeaconActive = false;
|
2025-01-15 02:28:11 -06:00
|
|
|
bool OfflineModeAvailable = false;
|
2025-01-20 12:10:30 -06:00
|
|
|
|
|
|
|
|
string ServerAddress = String.Empty;
|
2025-06-10 01:57:22 +02:00
|
|
|
|
2025-01-05 21:09:57 -06:00
|
|
|
AuthRequest Model = new();
|
|
|
|
|
List<DiscoveredServer> DiscoveredServers = new();
|
2025-06-10 01:57:22 +02:00
|
|
|
private CancellationTokenSource DiscoveryToken = new CancellationTokenSource();
|
|
|
|
|
|
2025-01-05 21:09:57 -06:00
|
|
|
Models.Settings Settings = SettingService.GetSettings();
|
|
|
|
|
|
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
|
|
|
{
|
2025-06-10 01:57:22 +02:00
|
|
|
IsInitializing = true;
|
2025-06-10 02:06:01 +02:00
|
|
|
|
|
|
|
|
if (Client.IsConfigured())
|
|
|
|
|
{
|
|
|
|
|
ServerAddress = Client.GetServerAddress() ?? string.Empty;
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-10 01:57:22 +02:00
|
|
|
Connecting = true;
|
2025-01-15 02:28:11 -06:00
|
|
|
OfflineModeAvailable = await AuthenticationService.OfflineModeAvailableAsync();
|
2025-06-10 01:57:22 +02:00
|
|
|
|
2025-04-23 21:23:33 -05:00
|
|
|
Client.Beacon.OnBeaconResponse += OnBeaconResponse;
|
2025-06-10 01:49:32 +02:00
|
|
|
|
|
|
|
|
if (!OfflineModeAvailable)
|
|
|
|
|
{
|
|
|
|
|
ActivateBeacon();
|
|
|
|
|
}
|
2025-06-10 01:57:22 +02:00
|
|
|
|
|
|
|
|
Connecting = false;
|
|
|
|
|
IsInitializing = false;
|
2025-01-05 21:09:57 -06:00
|
|
|
}
|
|
|
|
|
|
2025-04-23 21:23:33 -05:00
|
|
|
private void OnBeaconResponse(object sender, BeaconResponseArgs e)
|
|
|
|
|
{
|
|
|
|
|
var discoveredServer = new DiscoveredServer(e.Message, e.EndPoint);
|
2025-06-10 01:57:22 +02:00
|
|
|
|
2025-04-23 21:23:33 -05:00
|
|
|
if (DiscoveredServers.All(s => s.Address != discoveredServer.Address))
|
|
|
|
|
DiscoveredServers.Add(discoveredServer);
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-05 21:09:57 -06:00
|
|
|
async Task SelectServer(string serverAddress)
|
|
|
|
|
{
|
2025-04-23 21:23:33 -05:00
|
|
|
await Client.Beacon.StopProbeAsync();
|
2025-01-05 21:09:57 -06:00
|
|
|
|
|
|
|
|
BeaconActive = false;
|
|
|
|
|
|
2025-01-20 12:10:30 -06:00
|
|
|
if (OnSelected.HasDelegate)
|
|
|
|
|
await OnSelected.InvokeAsync(serverAddress);
|
2025-01-15 02:28:11 -06:00
|
|
|
}
|
2025-06-10 01:49:32 +02:00
|
|
|
|
|
|
|
|
void OfflineMode()
|
|
|
|
|
{
|
|
|
|
|
AuthenticationService.LoginOffline();
|
|
|
|
|
NavigationManager.NavigateTo("/", forceLoad: true);
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-10 01:57:22 +02:00
|
|
|
void CancelBeacon()
|
|
|
|
|
{
|
|
|
|
|
DiscoveryToken?.Cancel();
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-05 21:09:57 -06:00
|
|
|
async Task ActivateBeacon()
|
|
|
|
|
{
|
2025-06-10 01:57:22 +02:00
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
BeaconActive = true;
|
|
|
|
|
await InvokeAsync(StateHasChanged);
|
2025-01-05 21:09:57 -06:00
|
|
|
|
2025-06-10 01:57:22 +02:00
|
|
|
// give the UI a chance to render:
|
|
|
|
|
await Task.Yield();
|
2025-01-05 21:09:57 -06:00
|
|
|
|
2025-06-10 01:57:22 +02:00
|
|
|
if ((DiscoveryToken?.TryReset() ?? false) == false)
|
|
|
|
|
{
|
|
|
|
|
DiscoveryToken = new();
|
|
|
|
|
}
|
2025-04-23 21:23:33 -05:00
|
|
|
|
2025-06-10 01:57:22 +02:00
|
|
|
await Client.Beacon.StartProbeAsync(cancellationToken: DiscoveryToken.Token);
|
|
|
|
|
await Task.Delay(10000, DiscoveryToken.Token);
|
|
|
|
|
await Client.Beacon.StopProbeAsync();
|
|
|
|
|
}
|
|
|
|
|
catch (OperationCanceledException)
|
|
|
|
|
{
|
2025-06-10 23:15:31 +02:00
|
|
|
// ignore, handled in finally
|
2025-06-10 01:57:22 +02:00
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
2025-06-10 23:15:31 +02:00
|
|
|
Client.Beacon.CleanupProbe();
|
2025-06-10 01:57:22 +02:00
|
|
|
BeaconActive = false;
|
|
|
|
|
await InvokeAsync(StateHasChanged);
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-01-05 21:09:57 -06:00
|
|
|
|
2025-06-10 01:57:22 +02:00
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
DiscoveryToken?.Cancel();
|
|
|
|
|
DiscoveryToken?.Dispose();
|
2025-01-05 21:09:57 -06:00
|
|
|
}
|
|
|
|
|
}
|