179 lines
5.5 KiB
Plaintext
179 lines
5.5 KiB
Plaintext
@if (PublicCacheData != null)
|
|
{
|
|
if (PublicCacheData.ThemeIsDarkMode)
|
|
{
|
|
<Meta Content="@($"hsl({PublicCacheData.ThemeIndexColour},16%,12%)")" Name="theme-color"/>
|
|
<Meta Content="@($"hsl({PublicCacheData.ThemeIndexColour},16%,12%)")" Name="background-color"/>
|
|
}
|
|
else
|
|
{
|
|
<Meta Content="@($"hsl({PublicCacheData.ThemeIndexColour},84%,88%)")" Name="theme-color"/>
|
|
<Meta Content="@($"hsl({PublicCacheData.ThemeIndexColour},84%,88%)")" Name="background-color"/>
|
|
}
|
|
}
|
|
<style>
|
|
:root {
|
|
@if (PublicCacheData != null)
|
|
{@if (PublicCacheData.ThemeIsDarkMode)
|
|
{
|
|
@($@"--background: hsl({PublicCacheData.ThemeIndexColour},16%,12%);
|
|
--text-color: hsl({PublicCacheData.ThemeIndexColour},16%,73.6%);
|
|
--placeholder-text-color: hsla({PublicCacheData.ThemeIndexColour},84%,52.8%,.3);
|
|
--primary-color: hsl({PublicCacheData.ThemeIndexColour},16%,12%);
|
|
--primary-color-light: hsl({PublicCacheData.ThemeIndexColour},84%,100%);
|
|
--primary-color-dark: hsl({PublicCacheData.ThemeIndexColour},16%,33%);
|
|
--primary-gradiend-light: hsl({PublicCacheData.ThemeIndexColour},16%,16%);
|
|
--primary-gradiend-dark: hsl({PublicCacheData.ThemeIndexColour},16%,8%);
|
|
--primary-gradiend-lighter: hsl({PublicCacheData.ThemeIndexColour},16%,20%);
|
|
--primary-gradiend-darker: hsl({PublicCacheData.ThemeIndexColour},16%,4%);
|
|
--light-shadow: hsla({PublicCacheData.ThemeIndexColour},84%,66%,.1);
|
|
--dark-shadow: hsla({PublicCacheData.ThemeIndexColour},16%,1%,.5);")
|
|
}
|
|
else
|
|
{
|
|
@($@"--background: hsl({PublicCacheData.ThemeIndexColour},84%,88%);
|
|
--text-color: hsl({PublicCacheData.ThemeIndexColour},84%,26.4%);
|
|
--placeholder-text-color: hsla({PublicCacheData.ThemeIndexColour},84%,26.4%,.3);
|
|
--primary-color: hsl({PublicCacheData.ThemeIndexColour},84%,88%);
|
|
--primary-color-light: hsl({PublicCacheData.ThemeIndexColour},84%,100%);
|
|
--primary-color-dark: hsl({PublicCacheData.ThemeIndexColour},84%,66%);
|
|
--primary-gradiend-light: hsl({PublicCacheData.ThemeIndexColour},84%,92%);
|
|
--primary-gradiend-dark: hsl({PublicCacheData.ThemeIndexColour},84%,84%);
|
|
--primary-gradiend-lighter: hsl({PublicCacheData.ThemeIndexColour},84%,96%);
|
|
--primary-gradiend-darker: hsl({PublicCacheData.ThemeIndexColour},84%,80%);
|
|
--light-shadow: hsla({PublicCacheData.ThemeIndexColour},84%,100%,.5);
|
|
--dark-shadow: hsla({PublicCacheData.ThemeIndexColour},84%,66%,.5);")
|
|
}
|
|
}
|
|
}
|
|
</style>
|
|
|
|
<CascadingValue IsFixed=false Value=this>
|
|
@ChildContent
|
|
</CascadingValue>
|
|
|
|
@code {
|
|
[Parameter] public RenderFragment ChildContent { get; set; }
|
|
[Inject] public IStringLocalizer<AllStrings> Localizer { 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);
|
|
}
|
|
|
|
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);
|
|
StateHasChanged();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine($"{nameof(CascadingState)}.{nameof(UpdatePublicCache)}");
|
|
Console.WriteLine(ex.ToString());
|
|
}
|
|
}
|
|
|
|
[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)}");
|
|
}
|
|
}
|
|
} |