2024-08-04 17:53:19 -05:00
|
|
|
@using LANCommander.Launcher.Models
|
2024-06-05 01:21:31 -05:00
|
|
|
@using Photino.Blazor.CustomWindow.Components
|
|
|
|
|
@inherits LayoutComponentBase
|
|
|
|
|
@inject ImportService ImportService
|
|
|
|
|
@inject ProfileService ProfileService
|
|
|
|
|
@inject IMessageService MessageService
|
|
|
|
|
@inject NavigationManager NavigationManager
|
2024-06-05 23:37:16 -05:00
|
|
|
@inject ModalService ModalService
|
2024-07-15 17:26:24 -05:00
|
|
|
@inject LANCommander.SDK.Client LANCommander
|
2024-06-11 02:05:15 -05:00
|
|
|
@inject IJSRuntime JS
|
2024-06-05 01:21:31 -05:00
|
|
|
|
2024-06-07 00:01:38 -05:00
|
|
|
<CustomWindow HeaderHeight="37">
|
2024-06-05 01:21:31 -05:00
|
|
|
<HeaderExtraControlsLayout>
|
|
|
|
|
<Space Direction="@DirectionVHType.Horizontal">
|
|
|
|
|
@if (Settings != null && Settings.Profile != null && ProfileService.IsAuthenticated())
|
|
|
|
|
{
|
2024-07-15 17:26:24 -05:00
|
|
|
@if (!Settings.Authentication.OfflineMode)
|
|
|
|
|
{
|
|
|
|
|
<SpaceItem>
|
|
|
|
|
<Button Type="@ButtonType.Text" Icon="@IconType.Outline.Sync" OnClick="Import" Loading="@Importing" />
|
|
|
|
|
</SpaceItem>
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
<SpaceItem>
|
|
|
|
|
<Button Type="@ButtonType.Text" Icon="@IconType.Outline.CloudSync" OnClick="Connect" Loading="@Connecting" Danger />
|
|
|
|
|
</SpaceItem>
|
|
|
|
|
}
|
2024-06-08 03:05:32 -05:00
|
|
|
|
2024-06-05 01:21:31 -05:00
|
|
|
<SpaceItem>
|
2024-10-06 17:11:35 -05:00
|
|
|
<ProfileButton />
|
2024-06-05 01:21:31 -05:00
|
|
|
</SpaceItem>
|
|
|
|
|
}
|
|
|
|
|
</Space>
|
|
|
|
|
</HeaderExtraControlsLayout>
|
|
|
|
|
<WindowContent>
|
2024-06-07 23:49:11 -05:00
|
|
|
@Body
|
2024-06-05 01:21:31 -05:00
|
|
|
|
2024-08-14 13:24:50 -05:00
|
|
|
@if (Settings.Debug.EnableScriptDebugging)
|
|
|
|
|
{
|
|
|
|
|
<PowerShellConsole />
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-05 01:21:31 -05:00
|
|
|
<AntContainer />
|
|
|
|
|
<RedirectToLogin />
|
2024-07-25 19:21:52 -05:00
|
|
|
<UpdateChecker />
|
2024-06-05 01:21:31 -05:00
|
|
|
</WindowContent>
|
|
|
|
|
</CustomWindow>
|
|
|
|
|
|
|
|
|
|
@code {
|
2024-07-07 20:28:03 -05:00
|
|
|
Models.Settings Settings = null;
|
2024-06-05 01:21:31 -05:00
|
|
|
|
2024-06-11 02:05:15 -05:00
|
|
|
public bool Importing = false;
|
2024-07-15 17:26:24 -05:00
|
|
|
public bool Connecting = false;
|
2024-06-11 02:05:15 -05:00
|
|
|
public IMessageService Messages { get; set; }
|
|
|
|
|
|
|
|
|
|
public static MainLayout _MainLayout { get; set; }
|
2024-06-05 01:21:31 -05:00
|
|
|
|
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
|
|
|
{
|
2024-06-11 02:05:15 -05:00
|
|
|
_MainLayout = this;
|
|
|
|
|
|
2024-06-05 01:21:31 -05:00
|
|
|
Settings = SettingService.GetSettings();
|
2024-06-11 02:05:15 -05:00
|
|
|
Messages = MessageService;
|
|
|
|
|
|
2024-07-13 12:55:42 -05:00
|
|
|
ImportService.OnImportComplete += OnImportComplete;
|
2024-07-15 17:26:24 -05:00
|
|
|
|
2024-07-16 00:23:59 -05:00
|
|
|
if (!(await LANCommander.ValidateTokenAsync()) && !Settings.Authentication.OfflineMode)
|
2024-07-15 17:26:24 -05:00
|
|
|
NavigationManager.NavigateTo("/Authenticate");
|
2024-07-13 12:55:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async Task OnImportComplete()
|
|
|
|
|
{
|
|
|
|
|
MessageService.Success("Import Complete", 3);
|
2024-06-05 01:21:31 -05:00
|
|
|
}
|
|
|
|
|
|
2024-07-15 17:26:24 -05:00
|
|
|
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))
|
|
|
|
|
{
|
|
|
|
|
ProfileService.SetOfflineMode(false);
|
|
|
|
|
MessageService.Success("Back Online!");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (await LANCommander.PingAsync())
|
|
|
|
|
{
|
|
|
|
|
ProfileService.SetOfflineMode(false);
|
|
|
|
|
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 fix your credentials.",
|
|
|
|
|
OkText = "Logout",
|
|
|
|
|
CancelText = "Stay Offline",
|
|
|
|
|
Centered = true,
|
|
|
|
|
OnOk = async (e) =>
|
|
|
|
|
{
|
|
|
|
|
await Logout();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Connecting = false;
|
|
|
|
|
await InvokeAsync(StateHasChanged);
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-06 17:11:35 -05:00
|
|
|
async Task Logout()
|
|
|
|
|
{
|
|
|
|
|
await ProfileService.Logout();
|
|
|
|
|
|
|
|
|
|
NavigationManager.NavigateTo("/Authenticate");
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-24 17:26:00 -05:00
|
|
|
public static async void Import()
|
2024-06-05 01:21:31 -05:00
|
|
|
{
|
2024-06-24 17:26:00 -05:00
|
|
|
if (!_MainLayout.Importing)
|
2024-06-05 01:21:31 -05:00
|
|
|
{
|
2024-10-15 02:01:30 -05:00
|
|
|
await _MainLayout.JS.InvokeVoidAsync("window.external.sendMessage", "import");
|
2024-06-05 01:21:31 -05:00
|
|
|
|
2024-06-24 17:26:00 -05:00
|
|
|
_MainLayout.Importing = true;
|
|
|
|
|
_MainLayout.StateHasChanged();
|
|
|
|
|
_MainLayout.MessageService.Info("Import Started", 2.5);
|
2024-06-11 02:05:15 -05:00
|
|
|
}
|
|
|
|
|
}
|
2024-06-05 01:21:31 -05:00
|
|
|
|
2024-06-11 02:05:15 -05:00
|
|
|
[JSInvokable("ImportComplete")]
|
|
|
|
|
public static void ImportComplete()
|
|
|
|
|
{
|
|
|
|
|
_MainLayout.Importing = false;
|
|
|
|
|
_MainLayout.StateHasChanged();
|
2024-06-14 14:35:45 -07:00
|
|
|
_MainLayout.ImportService.ImportHasCompleted();
|
2024-06-05 01:21:31 -05:00
|
|
|
}
|
|
|
|
|
}
|