@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 @{ 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()} - "; } } } @(string.IsNullOrEmpty(title) ? "Dashboard - " : title)Moonlight
@{ //TODO: Add a way to disable the snow }
@if (!IsIpBanned) { if (UserProcessed) { if (uri.LocalPath != "/login" && uri.LocalPath != "/passwordreset" && uri.LocalPath != "/register") { if (IdentityService.User == null) { } else { if (IdentityService.User.Status == UserStatus.Banned) { } else if (IdentityService.User.Status == UserStatus.Disabled) { } else if (IdentityService.User.Status == UserStatus.PasswordPending) { } else if (IdentityService.User.Status == UserStatus.DataPending) { } else { @Body } } } else { if (uri.LocalPath == "/login") { } else if (uri.LocalPath == "/register") { } else if (uri.LocalPath == "/passwordreset") { } } } else { } } else { }
@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("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( $"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); } 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); } }); } }