302 lines
13 KiB
Plaintext
302 lines
13 KiB
Plaintext
@using Moonlight.Shared.Components.ErrorBoundaries
|
|
@using Moonlight.Shared.Components.Auth
|
|
@using Moonlight.App.Database.Entities
|
|
@using Moonlight.App.Extensions
|
|
@using Moonlight.App.Models.Misc
|
|
@using Moonlight.App.Services
|
|
@using Moonlight.App.Services.Interop
|
|
@using Moonlight.App.Services.Sessions
|
|
@using Moonlight.App.Events
|
|
|
|
@layout ThemeInit
|
|
@implements IDisposable
|
|
@inherits LayoutComponentBase
|
|
|
|
@inject IJSRuntime JsRuntime
|
|
@inject IdentityService IdentityService
|
|
@inject SessionClientService SessionClientService
|
|
@inject NavigationManager NavigationManager
|
|
@inject EventSystem Event
|
|
@inject ToastService ToastService
|
|
@inject SmartTranslateService SmartTranslateService
|
|
@inject IpBanService IpBanService
|
|
@inject DynamicBackgroundService DynamicBackgroundService
|
|
@inject KeyListenerService KeyListenerService
|
|
@inject ConfigService ConfigService
|
|
|
|
@{
|
|
var uri = new Uri(NavigationManager.Uri);
|
|
var pathParts = uri.LocalPath.Split("/").Reverse();
|
|
|
|
var title = "";
|
|
|
|
foreach (var pathPart in pathParts)
|
|
{
|
|
if (!string.IsNullOrEmpty(pathPart))
|
|
{
|
|
if (pathPart == pathParts.Last())
|
|
title += $"{pathPart.FirstCharToUpper()} ";
|
|
else
|
|
title += $"{pathPart.FirstCharToUpper()} - ";
|
|
}
|
|
}
|
|
}
|
|
|
|
<GlobalErrorBoundary>
|
|
<PageTitle>@(string.IsNullOrEmpty(title) ? "Dashboard - " : title)Moonlight</PageTitle>
|
|
|
|
<div class="d-flex flex-column flex-root app-root" id="kt_app_root">
|
|
<div class="app-page flex-column flex-column-fluid" id="kt_app_page">
|
|
<canvas id="snow" class="snow-canvas"></canvas>
|
|
|
|
@{
|
|
//TODO: Add a way to disable the snow
|
|
}
|
|
|
|
<PageHeader></PageHeader>
|
|
<div class="app-wrapper flex-column flex-row-fluid" id="kt_app_wrapper">
|
|
<Sidebar></Sidebar>
|
|
<div class="app-main flex-column flex-row-fluid" id="kt_app_main">
|
|
<div class="d-flex flex-column flex-column-fluid">
|
|
<div id="kt_app_content" class="app-content flex-column-fluid" style="background-position: center; background-size: cover; background-repeat: no-repeat; background-attachment: fixed; background-image: linear-gradient(rgba(0, 0, 0, 0.55),rgba(0, 0, 0, 0.55)) ,url('@(DynamicBackgroundService.BackgroundImageUrl)');">
|
|
<div id="kt_app_content_container" class="app-container container-fluid">
|
|
<div class="mt-10">
|
|
<SoftErrorBoundary>
|
|
@if (!IsIpBanned)
|
|
{
|
|
if (UserProcessed)
|
|
{
|
|
if (uri.LocalPath != "/login" &&
|
|
uri.LocalPath != "/passwordreset" &&
|
|
uri.LocalPath != "/register")
|
|
{
|
|
if (IdentityService.User == null)
|
|
{
|
|
<Login></Login>
|
|
}
|
|
else
|
|
{
|
|
if (IdentityService.User.Status == UserStatus.Banned)
|
|
{
|
|
<BannedAlert></BannedAlert>
|
|
}
|
|
else if (IdentityService.User.Status == UserStatus.Disabled)
|
|
{
|
|
<DisabledAlert></DisabledAlert>
|
|
}
|
|
else if (IdentityService.User.Status == UserStatus.PasswordPending)
|
|
{
|
|
<PasswordChangeView></PasswordChangeView>
|
|
}
|
|
else if (IdentityService.User.Status == UserStatus.DataPending)
|
|
{
|
|
<UserDataSetView></UserDataSetView>
|
|
}
|
|
else
|
|
{
|
|
<RenderPermissionChecker>
|
|
@Body
|
|
</RenderPermissionChecker>
|
|
|
|
<RatingPopup/>
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (uri.LocalPath == "/login")
|
|
{
|
|
<Login></Login>
|
|
}
|
|
else if (uri.LocalPath == "/register")
|
|
{
|
|
<Register></Register>
|
|
}
|
|
else if (uri.LocalPath == "/passwordreset")
|
|
{
|
|
<PasswordReset></PasswordReset>
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
<div class="modal d-block">
|
|
<div class="modal-dialog modal-dialog-centered mw-900px">
|
|
<div class="modal-content">
|
|
<div class="pt-2 modal-body py-lg-10 px-lg-10">
|
|
<h2>@(SmartTranslateService.Translate("Authenticating"))...</h2>
|
|
<p class="mt-3 fw-normal fs-6">@(SmartTranslateService.Translate("Verifying token, loading user data"))</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
}
|
|
}
|
|
else
|
|
{
|
|
<div class="modal d-block">
|
|
<div class="modal-dialog modal-dialog-centered mw-900px">
|
|
<div class="modal-content">
|
|
<div class="pt-2 modal-body py-lg-10 px-lg-10">
|
|
<h2>@(SmartTranslateService.Translate("Your ip has been banned"))</h2>
|
|
<p class="mt-3 fw-normal fs-6">@(SmartTranslateService.Translate("Your ip address has been banned by an admin"))</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
}
|
|
</SoftErrorBoundary>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<Footer></Footer>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</GlobalErrorBoundary>
|
|
|
|
@code
|
|
{
|
|
private bool UserProcessed = false;
|
|
|
|
private bool IsIpBanned = false;
|
|
|
|
protected override void OnAfterRender(bool firstRender)
|
|
{
|
|
if (firstRender)
|
|
AddBodyAttribute("data-kt-app-page-loading", "on");
|
|
|
|
//Initialize classes and attributes for layout with dark sidebar
|
|
AddBodyAttribute("data-kt-app-reset-transition", "true");
|
|
|
|
AddBodyAttribute("data-kt-app-layout", "dark-sidebar");
|
|
AddBodyAttribute("data-kt-app-header-fixed", "true");
|
|
AddBodyAttribute("data-kt-app-sidebar-fixed", "true");
|
|
AddBodyAttribute("data-kt-app-sidebar-hoverable", "true");
|
|
AddBodyAttribute("data-kt-app-sidebar-push-header", "true");
|
|
AddBodyAttribute("data-kt-app-sidebar-push-toolbar", "true");
|
|
AddBodyAttribute("data-kt-app-sidebar-push-footer", "true");
|
|
AddBodyAttribute("data-kt-app-toolbar-enabled", "true");
|
|
|
|
AddBodyClass("app-default");
|
|
}
|
|
|
|
protected override async Task OnAfterRenderAsync(bool firstRender)
|
|
{
|
|
if (firstRender)
|
|
{
|
|
try
|
|
{
|
|
DynamicBackgroundService.OnBackgroundImageChanged += async (_, _) => { await InvokeAsync(StateHasChanged); };
|
|
|
|
IsIpBanned = await IpBanService.IsBanned();
|
|
|
|
if (IsIpBanned)
|
|
await InvokeAsync(StateHasChanged);
|
|
|
|
await Event.On<Object>("ipBan.update", this, async _ =>
|
|
{
|
|
IsIpBanned = await IpBanService.IsBanned();
|
|
NavigationManager.NavigateTo(NavigationManager.Uri, true);
|
|
});
|
|
|
|
await IdentityService.Load();
|
|
UserProcessed = true;
|
|
await InvokeAsync(StateHasChanged);
|
|
|
|
try
|
|
{
|
|
await JsRuntime.InvokeVoidAsync("document.body.removeAttribute", "data-kt-app-reset-transition");
|
|
await JsRuntime.InvokeVoidAsync("document.body.removeAttribute", "data-kt-app-page-loading");
|
|
await JsRuntime.InvokeVoidAsync("KTMenu.createInstances");
|
|
await JsRuntime.InvokeVoidAsync("KTDrawer.createInstances");
|
|
}
|
|
catch (Exception)
|
|
{
|
|
/* ignore errors to make sure that the session call is executed */
|
|
}
|
|
|
|
await SessionClientService.Start();
|
|
|
|
NavigationManager.LocationChanged += async (_, _) =>
|
|
{
|
|
if (!NavigationManager.Uri.Contains("/server/"))
|
|
await DynamicBackgroundService.Reset();
|
|
};
|
|
|
|
if (IdentityService.User != null)
|
|
{
|
|
await Event.On<SupportChatMessage>(
|
|
$"supportChat.{IdentityService.User.Id}.message",
|
|
this,
|
|
async message =>
|
|
{
|
|
if (!NavigationManager.Uri.EndsWith("/support") && message.Sender != IdentityService.User)
|
|
{
|
|
await ToastService.Info($"Support: {message.Content}");
|
|
}
|
|
});
|
|
}
|
|
|
|
await KeyListenerService.Initialize();
|
|
|
|
RunDelayedMenu(0);
|
|
RunDelayedMenu(1);
|
|
RunDelayedMenu(3);
|
|
RunDelayedMenu(5);
|
|
|
|
if (ConfigService.Get().Moonlight.EnableLatencyCheck)
|
|
{
|
|
await JsRuntime.InvokeVoidAsync("moonlight.loading.checkConnection",
|
|
ConfigService.Get().Moonlight.AppUrl,
|
|
ConfigService.Get().Moonlight.LatencyCheckThreshold);
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
// ignored
|
|
}
|
|
}
|
|
}
|
|
|
|
public async void Dispose()
|
|
{
|
|
await SessionClientService.Stop();
|
|
|
|
await KeyListenerService.DisposeAsync();
|
|
|
|
if (IdentityService.User != null)
|
|
{
|
|
await Event.Off($"supportChat.{IdentityService.User.Id}.message", this);
|
|
}
|
|
}
|
|
|
|
private void AddBodyAttribute(string attribute, string value)
|
|
{
|
|
JsRuntime.InvokeVoidAsync("document.body.setAttribute", attribute, value);
|
|
}
|
|
|
|
private void AddBodyClass(string className)
|
|
{
|
|
JsRuntime.InvokeVoidAsync("document.body.classList.add", className);
|
|
}
|
|
|
|
private void RunDelayedMenu(int seconds)
|
|
{
|
|
Task.Run(async () =>
|
|
{
|
|
try
|
|
{
|
|
await Task.Delay(TimeSpan.FromSeconds(seconds));
|
|
await JsRuntime.InvokeVoidAsync("KTMenu.initHandlers");
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
//Logger.Warn("Delayed menu error");
|
|
//Logger.Warn(e);
|
|
}
|
|
});
|
|
}
|
|
} |