diff --git a/ColorControl.UI/Blazor.cs b/ColorControl.UI/Blazor.cs index 582849a..537736c 100644 --- a/ColorControl.UI/Blazor.cs +++ b/ColorControl.UI/Blazor.cs @@ -1,5 +1,5 @@ using ColorControl.Shared.Contracts; -using ColorControl.Shared.Services; +using ColorControl.UI.Services; namespace ColorControl.UI; @@ -15,6 +15,9 @@ public static void Start(Config? config = null) builder.Services.AddSingleton(new AppState { SelectedTheme = (config?.UseDarkMode ?? true) ? "dark" : "light" }); builder.Services.AddTransient(); + builder.Services.AddTransient(); + builder.Services.AddHttpContextAccessor(); + builder.Services.AddSingleton(); builder.WebHost.ConfigureKestrel(o => o.ListenAnyIP(config?.UiPort > 0 ? config.UiPort : 5000)); var app = builder.Build(); diff --git a/ColorControl.UI/ColorControl.UI.csproj b/ColorControl.UI/ColorControl.UI.csproj index d9c99b4..33cdc83 100644 --- a/ColorControl.UI/ColorControl.UI.csproj +++ b/ColorControl.UI/ColorControl.UI.csproj @@ -13,9 +13,13 @@ + + + true + true @@ -25,6 +29,9 @@ true + + true + true @@ -52,6 +59,15 @@ true + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + diff --git a/ColorControl.UI/Components/App.razor b/ColorControl.UI/Components/App.razor index 86bbe4f..a0ff549 100644 --- a/ColorControl.UI/Components/App.razor +++ b/ColorControl.UI/Components/App.razor @@ -1,8 +1,15 @@ -@using ColorControl.Shared.Contracts -@using ColorControl.Shared.Services +@using ColorControl.Shared.Common +@using ColorControl.Shared.Contracts +@using ColorControl.UI.Services +@using ColorControl.UI.Components.Pages.Generic +@using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage + @inject AppState AppState -@inject RpcUiClientService ClientService; -@inject NavigationManager _navigationManager; +@inject RpcUiClientService _rpcClientService +@inject NavigationManager _navigationManager +@inject NotificationService _notificationService +@inject ProtectedSessionStorage _sessionStorage + @implements IDisposable @attribute [StreamRendering] @@ -15,28 +22,33 @@ + + + @code { + private Config? Config; + protected override async Task OnInitializedAsync() { - var config = await ClientService.CallAsync("OptionsService", "GetConfig"); + Config ??= await _rpcClientService.CallAsync("OptionsService", "GetConfig"); - var newTheme = config.UseDarkMode ? "dark" : "light"; + var newTheme = Config?.UseDarkMode == true ? "dark" : "light"; if (newTheme != AppState.SelectedTheme) { - AppState.SelectedTheme = config.UseDarkMode ? "dark" : "light"; + AppState.SelectedTheme = Config?.UseDarkMode == true ? "dark" : "light"; _navigationManager.Refresh(); } diff --git a/ColorControl.UI/Components/Layout/NavMenu.razor b/ColorControl.UI/Components/Layout/NavMenu.razor index 514ac68..dbcb094 100644 --- a/ColorControl.UI/Components/Layout/NavMenu.razor +++ b/ColorControl.UI/Components/Layout/NavMenu.razor @@ -1,5 +1,6 @@ @using ColorControl.Shared.Contracts -@using ColorControl.Shared.Services; +@using ColorControl.UI.Services; +@using ColorControl.UI.Services @rendermode InteractiveServer @@ -28,28 +29,34 @@ @foreach (var module in modules.Where(m => m.IsActive)) { } } + + diff --git a/ColorControl.UI/Components/Layout/TopMenu.razor b/ColorControl.UI/Components/Layout/TopMenu.razor index 32eaf88..193e9af 100644 --- a/ColorControl.UI/Components/Layout/TopMenu.razor +++ b/ColorControl.UI/Components/Layout/TopMenu.razor @@ -1,5 +1,5 @@ @using ColorControl.Shared.Contracts -@using ColorControl.Shared.Services +@using ColorControl.UI.Services @inherits LayoutComponentBase @inject AppState AppState diff --git a/ColorControl.UI/Components/Pages/AMD/AmdPresetPage.razor b/ColorControl.UI/Components/Pages/AMD/AmdPresetPage.razor index 770c4dd..f4b1e14 100644 --- a/ColorControl.UI/Components/Pages/AMD/AmdPresetPage.razor +++ b/ColorControl.UI/Components/Pages/AMD/AmdPresetPage.razor @@ -1,15 +1,15 @@ @using ColorControl.Shared.Contracts @using ColorControl.Shared.Contracts.AMD -@using ColorControl.Shared.Services; @using ColorControl.UI.Components.Pages.Generic @using ColorControl.Shared.Common; +@using ColorControl.UI.Services @rendermode InteractiveServer @inject RpcUiClientService _rpcClientService