2026-10-06 23:31:07 +02:00
|
|
|
using Microsoft.AspNetCore.Components;
|
2026-10-03 11:29:31 +02:00
|
|
|
using decePubClient.Models;
|
|
|
|
|
|
|
|
|
|
using Microsoft.JSInterop;
|
2022-02-14 01:51:52 +01:00
|
|
|
|
|
|
|
|
namespace decePubClient.Services;
|
2022-02-14 01:51:37 +01:00
|
|
|
|
2026-10-03 15:26:21 +02:00
|
|
|
public class AppStatusService(IJSRuntime jsRuntime)
|
2022-02-14 01:51:37 +01:00
|
|
|
{
|
2026-10-03 15:26:21 +02:00
|
|
|
readonly IJSInProcessRuntime JsSyncRuntime = (IJSInProcessRuntime)jsRuntime;
|
2022-02-14 01:51:52 +01:00
|
|
|
|
2026-10-03 15:26:21 +02:00
|
|
|
public async ValueTask<bool> IsOnline(CancellationToken cancellationToken = default) =>
|
|
|
|
|
await jsRuntime.InvokeAsync<bool>("isOnline", cancellationToken);
|
2022-02-14 01:51:52 +01:00
|
|
|
|
|
|
|
|
public bool IsServiceWorkerAvailable() => JsSyncRuntime.Invoke<bool>("isServiceWorkerAvailable");
|
|
|
|
|
|
|
|
|
|
public string Language() => JsSyncRuntime.Invoke<string>("getLanguage");
|
|
|
|
|
|
|
|
|
|
public void Language(string language) => JsSyncRuntime.InvokeVoid("setLanguage", language);
|
|
|
|
|
|
|
|
|
|
public long GetHeight(string classId) => JsSyncRuntime.Invoke<long>("getHeight", classId);
|
|
|
|
|
|
|
|
|
|
public void SetAppBadge(int counter) => JsSyncRuntime.InvokeVoid("setAppBadge", counter);
|
|
|
|
|
|
|
|
|
|
public void ClearAppBadge() => JsSyncRuntime.InvokeVoid("clearAppBadge");
|
|
|
|
|
|
2026-10-03 15:26:21 +02:00
|
|
|
public async ValueTask ClearCache(CancellationToken cancellationToken = default) =>
|
|
|
|
|
await jsRuntime.InvokeVoidAsync("clearCache", cancellationToken);
|
2022-02-14 01:51:52 +01:00
|
|
|
|
2026-10-03 15:26:21 +02:00
|
|
|
public async ValueTask ClearLocalStorage(CancellationToken cancellationToken = default) =>
|
|
|
|
|
await jsRuntime.InvokeVoidAsync("clearLocalStorage", cancellationToken);
|
2022-02-14 01:51:52 +01:00
|
|
|
|
|
|
|
|
public void ReloadPage()
|
|
|
|
|
{
|
|
|
|
|
JsSyncRuntime.InvokeVoid("reloadPage");
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-03 11:29:31 +02:00
|
|
|
// wwwroot/js/theme.js
|
|
|
|
|
public void ApplyTheme(PageSettings pageSettings) => JsSyncRuntime.InvokeVoid("neoTheme.apply", pageSettings);
|
|
|
|
|
|
2026-10-03 12:43:07 +02:00
|
|
|
public bool IsDarkTheme() => JsSyncRuntime.Invoke<bool>("neoTheme.isDark");
|
|
|
|
|
|
2022-02-14 01:51:52 +01:00
|
|
|
public bool IsMobileMedia() => JsSyncRuntime.Invoke<bool>("isMobileMedia");
|
|
|
|
|
|
2026-10-06 23:36:03 +02:00
|
|
|
// whether the pointer can hover (a mouse); a touch screen can't, so what shows on hover there opens on a tap
|
|
|
|
|
public bool CanHover() => JsSyncRuntime.Invoke<bool>("canHover");
|
|
|
|
|
|
2026-10-06 23:31:07 +02:00
|
|
|
// a sideways-scrolling strip of tabs shows its selected tab
|
|
|
|
|
public void RevealActive(ElementReference strip) => JsSyncRuntime.InvokeVoid("revealActive", strip);
|
|
|
|
|
|
2022-02-14 01:51:52 +01:00
|
|
|
public bool CanShare() => JsSyncRuntime.Invoke<bool>("canShareStuff");
|
|
|
|
|
|
2026-10-03 15:26:21 +02:00
|
|
|
public async ValueTask ShareTextUrl(string title, string text, Uri uri, CancellationToken cancellationToken = default) =>
|
|
|
|
|
await jsRuntime.InvokeVoidAsync("shareTextUrl", cancellationToken, title, text, uri.ToString());
|
2022-02-14 01:51:52 +01:00
|
|
|
|
2026-10-03 15:26:21 +02:00
|
|
|
public async ValueTask ShareText(string title, string text, CancellationToken cancellationToken = default) =>
|
|
|
|
|
await jsRuntime.InvokeVoidAsync("shareText", cancellationToken, title, text);
|
2022-02-14 01:51:37 +01:00
|
|
|
}
|