With the default settings (follow the system, light grey) the nav's hue slider and dark toggle did nothing visible, and no UI could leave that mode. The slider also always wrote the light hue, even in dark mode. PageSettings gains SetDarkMode, SetGray and SetHue, and CascadingState gains UpdatePageSettings. They keep the flags consistent: - choosing light or dark leaves system theming; - picking a hue leaves grey; - grey follows the variant shown. theme.js reports which variant is showing (AppStatusService.IsDarkTheme), so the nav toggle and slider edit that one, including the OS's choice in system mode. Settings > General, which was empty, now edits every theme setting: - follow the system; - dark mode; - grey; - the light and dark hues. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LsXgEaXee4GCU1hwYgPJXw
138 lines
3.5 KiB
Plaintext
138 lines
3.5 KiB
Plaintext
<CascadingValue IsFixed=false Value=this>
|
|
@ChildContent
|
|
</CascadingValue>
|
|
|
|
@code {
|
|
[Parameter] public RenderFragment ChildContent { get; set; }
|
|
[Inject] IStorage DbStorage { get; set; }
|
|
[Inject] ILocalStorageService Storage { get; set; }
|
|
[Inject] IJSRuntime JS { get; set; }
|
|
// [Inject] DataService DataService { get; set; }
|
|
[Inject] public AppStatusService Status { get; set; }
|
|
[Inject] ILogger<CascadingState> Logger { get; set; }
|
|
|
|
public bool IsOnline { get; set; } = true;
|
|
Timer IsOnlineTimer { get; set; }
|
|
public PublicCacheData PublicCacheData { get; set; }
|
|
public User User { get; set; }
|
|
|
|
DotNetObjectReference<CascadingState> cascadingStateReference;
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
try
|
|
{
|
|
IsOnlineTimer = new Timer(async _ => await UpdateIsOnline(), new AutoResetEvent(false), 0, 10000);
|
|
cascadingStateReference = DotNetObjectReference.Create(this);
|
|
await JS.InvokeVoidAsync("cascadingStateInstanceReference", cascadingStateReference);
|
|
PublicCacheData = await Storage.GetItemAsync<PublicCacheData>(nameof(PublicCacheData));
|
|
if (PublicCacheData == null)
|
|
{
|
|
PublicCacheData = new();
|
|
await UpdatePublicCache(PublicCacheData);
|
|
}
|
|
else
|
|
Status.ApplyTheme(PublicCacheData.PageSettings);
|
|
|
|
User = new();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Logger.LogError(ex, $"{nameof(CascadingState)}.{nameof(OnInitializedAsync)}");
|
|
}
|
|
}
|
|
|
|
public async ValueTask UpdatePublicCache(PublicCacheData publicCacheData)
|
|
{
|
|
try
|
|
{
|
|
PublicCacheData = publicCacheData;
|
|
await Storage.SetItemAsync(nameof(PublicCacheData), PublicCacheData);
|
|
Status.ApplyTheme(PublicCacheData.PageSettings);
|
|
StateHasChanged();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine($"{nameof(CascadingState)}.{nameof(UpdatePublicCache)}");
|
|
Console.WriteLine(ex.ToString());
|
|
}
|
|
}
|
|
|
|
/// <summary>Changes the page settings, then saves and applies them like UpdatePublicCache.</summary>
|
|
public ValueTask UpdatePageSettings(Action<PageSettings> change)
|
|
{
|
|
change(PublicCacheData.PageSettings);
|
|
return UpdatePublicCache(PublicCacheData);
|
|
}
|
|
|
|
[JSInvokable]
|
|
public async Task LogFromJs(string message, string where)
|
|
{
|
|
try
|
|
{
|
|
await ProcessError(new(message), where);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Logger.LogError(ex, $"{nameof(CascadingState)}.{nameof(LogFromJs)}");
|
|
}
|
|
}
|
|
|
|
async Task UpdateIsOnline()
|
|
{
|
|
try
|
|
{
|
|
var latestOnlineState = await Status.IsOnline();
|
|
|
|
//var latestOnlineState = Random.Shared.Next() % 2 == 0;
|
|
if (latestOnlineState != IsOnline)
|
|
{
|
|
IsOnline = latestOnlineState;
|
|
StateHasChanged();
|
|
}
|
|
// else
|
|
// {
|
|
// var pingIsOnline = await DataService.Ping();
|
|
// if (pingIsOnline != IsOnline)
|
|
// {
|
|
// IsOnline = pingIsOnline;
|
|
// StateHasChanged();
|
|
// }
|
|
// }
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Logger.LogError(ex, $"{nameof(CascadingState)}.{nameof(UpdateIsOnline)}");
|
|
}
|
|
}
|
|
|
|
public async ValueTask ProcessError(Exception ex, string where)
|
|
{
|
|
try
|
|
{
|
|
await DbStorage.AddLog(ex, where);
|
|
Logger.LogError(ex, where);
|
|
await Task.Run(() => {
|
|
});
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
Logger.LogError(exception, $"{nameof(CascadingState)}.{nameof(ProcessError)}");
|
|
}
|
|
}
|
|
|
|
public async ValueTask ProcessWarning(string message, string where)
|
|
{
|
|
try
|
|
{
|
|
await DbStorage.AddLog(message, where);
|
|
Logger.LogWarning("{where} - {message}", where, message);
|
|
await Task.Run(() => {
|
|
});
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
Logger.LogError(exception, $"{nameof(CascadingState)}.{nameof(ProcessWarning)}");
|
|
}
|
|
}
|
|
} |