231 lines
No EOL
9 KiB
Text
231 lines
No EOL
9 KiB
Text
@using LANCommander.Launcher.Models
|
|
@using LANCommander.SDK.Services
|
|
@using Photino.Blazor.CustomWindow.Components
|
|
@inherits LayoutComponentBase
|
|
@inject ImportService ImportService
|
|
@inject ProfileService ProfileService
|
|
@inject AuthenticationService AuthenticationService
|
|
@inject IMessageService MessageService
|
|
@inject NavigationManager NavigationManager
|
|
@inject ModalService ModalService
|
|
@inject LANCommander.SDK.Client Client
|
|
@inject IJSRuntime JS
|
|
@inject ImportManagerService ImportManagerService
|
|
@inject LocalizationService LocalizationService
|
|
@inject IConnectionClient ConnectionClient
|
|
|
|
<CustomWindow HeaderHeight="37">
|
|
<HeaderExtraControlsLayout>
|
|
<Space Direction="SpaceDirection.Horizontal">
|
|
<AuthenticatedView NoAutoValidate="true">
|
|
<Authenticated>
|
|
<SpaceItem>
|
|
@if (ImportStatus.IsActive)
|
|
{
|
|
<Popover Placement="Placement.BottomRight" IsButton Trigger="new[] { Trigger.Hover }">
|
|
<ChildContent>
|
|
<Button Type="@ButtonType.Text" Icon="@IconType.Outline.Sync" Loading="true"/>
|
|
</ChildContent>
|
|
<ContentTemplate>
|
|
<ImportProgressDisplay
|
|
Index="@ImportStatus.Index"
|
|
Total="@ImportStatus.Total"
|
|
CurrentItem="@(_importProgress?.CurrentItem)"
|
|
/>
|
|
</ContentTemplate>
|
|
</Popover>
|
|
}
|
|
else
|
|
{
|
|
if (ConnectionClient.IsOfflineMode())
|
|
{
|
|
<Tooltip Title="@LocalizationService.GetString("ReconnectToServer")" MouseEnterDelay="0.5">
|
|
<Button Type="@ButtonType.Text" Icon="@IconType.Outline.CloudSync" OnClick="Connect" Loading="@Connecting" Danger/>
|
|
</Tooltip>
|
|
}
|
|
else if (ConnectionClient.IsConnected())
|
|
{
|
|
<Tooltip Title="@LocalizationService.GetString("ReimportLibrary")" MouseEnterDelay="0.5">
|
|
<Button Type="@ButtonType.Text" Icon="@IconType.Outline.Sync" OnClick="@ImportHandler.Import"/>
|
|
</Tooltip>
|
|
}
|
|
}
|
|
</SpaceItem>
|
|
|
|
<SpaceItem>
|
|
<ProfileButton/>
|
|
</SpaceItem>
|
|
</Authenticated>
|
|
|
|
<NotAuthenticated>
|
|
<SpaceItem>
|
|
<Button Type="@ButtonType.Text" Icon="@IconType.Outline.CloudSync" OnClick="Connect" Loading="@Connecting" Danger/>
|
|
</SpaceItem>
|
|
</NotAuthenticated>
|
|
</AuthenticatedView>
|
|
</Space>
|
|
</HeaderExtraControlsLayout>
|
|
<WindowContent>
|
|
<ErrorHandler Title="@LocalizationService.GetString("LauncherCrashed")">
|
|
<Body>
|
|
@Body
|
|
|
|
<ImportHandler @ref="ImportHandler" Progress="OnImportProcess"/>
|
|
<UpdateChecker/>
|
|
<AntContainer/>
|
|
<KeepAliveContainer/>
|
|
</Body>
|
|
|
|
<Extra>
|
|
<Button Type="ButtonType.Primary" OnClick="@(() => NavigationManager.NavigateTo("/", true))">@LocalizationService.GetString("ViewLibrary")</Button>
|
|
</Extra>
|
|
</ErrorHandler>
|
|
</WindowContent>
|
|
</CustomWindow>
|
|
|
|
@code {
|
|
public bool Importing;
|
|
public bool Connecting;
|
|
|
|
public IMessageService Messages { get; set; }
|
|
|
|
ImportHandler ImportHandler;
|
|
ImportHandler.ImportProgressEventArgs ImportStatus = new();
|
|
private ImportProgress _importProgress => ImportService.Progress;
|
|
|
|
string RandomQuip = "";
|
|
|
|
string[] _crashQuips;
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
ConnectionClient.OnOfflineModeEnabled += OnOfflineModeChanged;
|
|
ConnectionClient.OnConnect += OnConnect;
|
|
|
|
if (await Client.Authentication.ValidateTokenAsync())
|
|
{
|
|
await AuthenticationService.Login();
|
|
|
|
await ImportManagerService.RequestImport();
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
|
|
_crashQuips = new[]
|
|
{
|
|
LocalizationService.GetString("CrashQuip_YouDied"),
|
|
LocalizationService.GetString("CrashQuip_Snake"),
|
|
LocalizationService.GetString("CrashQuip_Wasted"),
|
|
LocalizationService.GetString("CrashQuip_MajorFracture"),
|
|
LocalizationService.GetString("CrashQuip_PastIsGapingHole"),
|
|
LocalizationService.GetString("CrashQuip_TownCenterDestroyed"),
|
|
LocalizationService.GetString("CrashQuip_ForcesUnderAttack"),
|
|
LocalizationService.GetString("CrashQuip_LostLead"),
|
|
LocalizationService.GetString("CrashQuip_TerroristsWin"),
|
|
LocalizationService.GetString("CrashQuip_WarNeverChanges"),
|
|
LocalizationService.GetString("CrashQuip_DiedOfDysentery"),
|
|
LocalizationService.GetString("CrashQuip_FailedToRestoreBooks"),
|
|
LocalizationService.GetString("CrashQuip_PlayerSplattered"),
|
|
LocalizationService.GetString("CrashQuip_BlameISP"),
|
|
LocalizationService.GetString("CrashQuip_BabaNoMore"),
|
|
LocalizationService.GetString("CrashQuip_GuestsLost"),
|
|
LocalizationService.GetString("CrashQuip_DarknessOvercome"),
|
|
LocalizationService.GetString("CrashQuip_GordonFreemanTerminated"),
|
|
LocalizationService.GetString("CrashQuip_MissionFailedSpotted"),
|
|
LocalizationService.GetString("CrashQuip_CriticalDamageEject"),
|
|
LocalizationService.GetString("CrashQuip_MinionsUnhappy"),
|
|
LocalizationService.GetString("CrashQuip_EmpireTriumphed"),
|
|
LocalizationService.GetString("CrashQuip_QuestEndedFailure"),
|
|
LocalizationService.GetString("CrashQuip_EatenByGrue"),
|
|
LocalizationService.GetString("CrashQuip_NoMessWithLoWang"),
|
|
LocalizationService.GetString("CrashQuip_SamKilled"),
|
|
LocalizationService.GetString("CrashQuip_AlienBastardsPay")
|
|
};
|
|
|
|
var randIndex = new Random().Next(0, _crashQuips.Length - 1);
|
|
RandomQuip = _crashQuips[randIndex];
|
|
}
|
|
|
|
private async void OnConnect(object? sender, EventArgs e)
|
|
{
|
|
await ImportManagerService.RequestImport();
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
if (ConnectionClient != null)
|
|
ConnectionClient.OnOfflineModeEnabled -= OnOfflineModeChanged;
|
|
}
|
|
|
|
void OnOfflineModeChanged(object? sender, EventArgs eventArgs)
|
|
{
|
|
StateHasChanged();
|
|
}
|
|
|
|
async void OnImportProcess(ImportHandler.ImportProgressEventArgs importProgress)
|
|
{
|
|
ImportStatus = importProgress;
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
|
|
async Task CopyError(Exception ex)
|
|
{
|
|
await JS.InvokeVoidAsync("navigator.clipboard.writeText", ex.Message + "\n" + ex.StackTrace);
|
|
|
|
MessageService.Info(LocalizationService.GetString("ErrorCopiedToClipboard"));
|
|
}
|
|
|
|
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 = @<Icon Type="@IconType.Outline.ExclamationCircle"></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");
|
|
}
|
|
|
|
}
|
|
|
|
<style>
|
|
.import-progress {
|
|
width: 300px; /* Fixed width */
|
|
}
|
|
|
|
.import-progress .downloader-current-upper-status {
|
|
white-space: nowrap;
|
|
overflow: hidden;
|
|
text-overflow: ellipsis;
|
|
max-width: 100%;
|
|
}
|
|
</style> |