238 lines
No EOL
7.8 KiB
Text
238 lines
No EOL
7.8 KiB
Text
@using System.Management.Automation.Remoting
|
|
@using LANCommander.Launcher.Models
|
|
@using LANCommander.SDK
|
|
@using Photino.Blazor.CustomWindow.Components
|
|
@using ConnectionState = LANCommander.Launcher.Models.ConnectionState
|
|
@inherits LayoutComponentBase
|
|
@inject ImportService ImportService
|
|
@inject ProfileService ProfileService
|
|
@inject AuthenticationService AuthenticationService
|
|
@inject IMessageService MessageService
|
|
@inject NavigationManager NavigationManager
|
|
@inject ModalService ModalService
|
|
@inject LANCommander.SDK.Client LANCommander
|
|
@inject IJSRuntime JS
|
|
|
|
<CustomWindow HeaderHeight="37">
|
|
<HeaderExtraControlsLayout>
|
|
<Space Direction="SpaceDirection.Horizontal">
|
|
<AuthenticatedView>
|
|
<Authenticated>
|
|
<SpaceItem>
|
|
<Popover Placement="Placement.BottomRight" IsButton OnClick="Import" Trigger="new[] { Trigger.Hover }">
|
|
<ChildContent>
|
|
<Button Type="@ButtonType.Text" Icon="@IconType.Outline.Sync" Loading="@Importing"/>
|
|
</ChildContent>
|
|
<ContentTemplate>
|
|
<Progress Percent="@((ImportStatusIndex / (float)ImportStatusTotal) * 100)" Steps="@ImportStatusTotal"/>
|
|
</ContentTemplate>
|
|
</Popover>
|
|
</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>
|
|
<AuthenticatedView>
|
|
<Authenticated>
|
|
@Body
|
|
|
|
@if (Settings.Debug.EnableScriptDebugging)
|
|
{
|
|
<PowerShellConsole/>
|
|
}
|
|
|
|
<KeepAliveContainer />
|
|
</Authenticated>
|
|
<NotAuthenticated>
|
|
<AuthenticationForm />
|
|
</NotAuthenticated>
|
|
</AuthenticatedView>
|
|
|
|
<UpdateChecker />
|
|
<AntContainer />
|
|
</ErrorHandler>
|
|
</WindowContent>
|
|
</CustomWindow>
|
|
|
|
@code {
|
|
Models.Settings Settings = null;
|
|
|
|
public bool Importing;
|
|
public bool Connecting;
|
|
|
|
public ConnectionState ConnectionState = new();
|
|
|
|
public IMessageService Messages { get; set; }
|
|
|
|
public static MainLayout _MainLayout { get; set; }
|
|
|
|
string RandomQuip = "";
|
|
|
|
string[] CrashQuips = new[]
|
|
{
|
|
"You Died.",
|
|
"Snake? SNAAAAAAKE!",
|
|
"WASTED",
|
|
"Major fracture detected",
|
|
"The past is a gaping hole. You try to run from it, but the more you run, the deeper, the darker, the bigger it gets.",
|
|
"Your town center has been destroyed",
|
|
"Your forces are under attack!",
|
|
"You have lost the lead",
|
|
"Terrorists Win",
|
|
"War... War never changes.",
|
|
"You have died of dysentery",
|
|
"You have failed to restore the books. The Ages are lost.",
|
|
"Player was splattered by a demon",
|
|
"Sure, blame it on your ISP",
|
|
"Baba is no more",
|
|
"Guests are complaining they are lost",
|
|
"The darkness has overcome you",
|
|
"Subject: Gordon Freeman. Status: Terminated",
|
|
"Mission failed: You were spotted.",
|
|
"Critical damage! Eject, eject!",
|
|
"Your minions are unhappy. They are leaving.",
|
|
"The Empire has triumphed",
|
|
"Your quest has ended in failure",
|
|
"You have been eaten by a grue",
|
|
"You no mess with Lo Wang!",
|
|
"Sam was killed. Serious carnage ensues.",
|
|
"Damn, those alien bastards are gonna pay for shooting up my ride"
|
|
};
|
|
|
|
int ImportStatusIndex = 0;
|
|
int ImportStatusTotal = 0;
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
_MainLayout = this;
|
|
|
|
Settings = SettingService.GetSettings();
|
|
Messages = MessageService;
|
|
|
|
ImportService.OnImportComplete += OnImportComplete;
|
|
ImportService.OnImportUpdated += OnImportUpdated;
|
|
|
|
AuthenticationService.OnOfflineModeChanged += OnOfflineModeChanged;
|
|
|
|
var randIndex = new Random().Next(0, CrashQuips.Length - 1);
|
|
|
|
RandomQuip = CrashQuips[randIndex];
|
|
}
|
|
|
|
async Task OnImportComplete()
|
|
{
|
|
MessageService.Success("Import Complete", 3);
|
|
}
|
|
|
|
async Task OnImportUpdated(ImportStatusUpdate status)
|
|
{
|
|
MessageService.Info($"Importing {status.CurrentItem.Name}");
|
|
}
|
|
|
|
async void OnOfflineModeChanged(bool state)
|
|
{
|
|
_MainLayout.ConnectionState.OfflineModeEnabled = state;
|
|
_MainLayout.ConnectionState.IsConnected = LANCommander.IsConnected();
|
|
await InvokeAsync(_MainLayout.StateHasChanged);
|
|
}
|
|
|
|
async Task CopyError(Exception ex)
|
|
{
|
|
await JS.InvokeVoidAsync("navigator.clipboard.writeText", ex.Message + "\n" + ex.StackTrace);
|
|
|
|
MessageService.Info("Error copied to clipboard!");
|
|
}
|
|
|
|
async Task Connect()
|
|
{
|
|
Connecting = true;
|
|
|
|
Settings = SettingService.GetSettings();
|
|
|
|
var token = new SDK.Models.AuthToken
|
|
{
|
|
AccessToken = Settings.Authentication.AccessToken,
|
|
RefreshToken = Settings.Authentication.RefreshToken
|
|
};
|
|
|
|
if (await LANCommander.ValidateTokenAsync(token))
|
|
{
|
|
await AuthenticationService.Login();
|
|
|
|
MessageService.Success("Back Online!");
|
|
|
|
ConnectionState.IsConnected = true;
|
|
ConnectionState.OfflineModeEnabled = false;
|
|
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
else
|
|
{
|
|
if (await LANCommander.PingAsync())
|
|
{
|
|
await Logout();
|
|
}
|
|
else
|
|
{
|
|
await ModalService.ConfirmAsync(new ConfirmOptions()
|
|
{
|
|
Title = "Could Not Reconnect!",
|
|
Icon = @<Icon Type="@IconType.Outline.ExclamationCircle"></Icon>,
|
|
Content = "The LANCommander server could not be reached. Click stay offline and try later, or logout and enter your credentials.",
|
|
OkText = "Logout",
|
|
CancelText = "Stay Offline",
|
|
Centered = true,
|
|
OnOk = async (e) =>
|
|
{
|
|
await Logout();
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
Connecting = false;
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
|
|
async Task Logout()
|
|
{
|
|
await AuthenticationService.Logout();
|
|
|
|
ConnectionState.IsConnected = false;
|
|
ConnectionState.OfflineModeEnabled = false;
|
|
|
|
NavigationManager.NavigateTo("/Authenticate");
|
|
}
|
|
|
|
public static async void Import()
|
|
{
|
|
if (!_MainLayout.Importing)
|
|
{
|
|
await _MainLayout.JS.InvokeVoidAsync("window.external.sendMessage", "import");
|
|
|
|
_MainLayout.Importing = true;
|
|
_MainLayout.StateHasChanged();
|
|
_MainLayout.MessageService.Info("Import Started", 2.5);
|
|
}
|
|
}
|
|
|
|
[JSInvokable("ImportComplete")]
|
|
public static void ImportComplete()
|
|
{
|
|
_MainLayout.Importing = false;
|
|
_MainLayout.StateHasChanged();
|
|
_MainLayout.ImportService.ImportHasCompleted();
|
|
}
|
|
} |