using decePubClient.Models; using Microsoft.JSInterop; namespace decePubClient.Services; public class AppStatusService(IJSRuntime jsRuntime) { readonly IJSInProcessRuntime JsSyncRuntime = (IJSInProcessRuntime)jsRuntime; public async ValueTask IsOnline(CancellationToken cancellationToken = default) => await jsRuntime.InvokeAsync("isOnline", cancellationToken); public bool IsServiceWorkerAvailable() => JsSyncRuntime.Invoke("isServiceWorkerAvailable"); public string Language() => JsSyncRuntime.Invoke("getLanguage"); public void Language(string language) => JsSyncRuntime.InvokeVoid("setLanguage", language); public long GetHeight(string classId) => JsSyncRuntime.Invoke("getHeight", classId); public void SetAppBadge(int counter) => JsSyncRuntime.InvokeVoid("setAppBadge", counter); public void ClearAppBadge() => JsSyncRuntime.InvokeVoid("clearAppBadge"); public async ValueTask ClearCache(CancellationToken cancellationToken = default) => await jsRuntime.InvokeVoidAsync("clearCache", cancellationToken); public async ValueTask ClearLocalStorage(CancellationToken cancellationToken = default) => await jsRuntime.InvokeVoidAsync("clearLocalStorage", cancellationToken); public void ReloadPage() { JsSyncRuntime.InvokeVoid("reloadPage"); } // wwwroot/js/theme.js public void ApplyTheme(PageSettings pageSettings) => JsSyncRuntime.InvokeVoid("neoTheme.apply", pageSettings); public bool IsDarkTheme() => JsSyncRuntime.Invoke("neoTheme.isDark"); public bool IsMobileMedia() => JsSyncRuntime.Invoke("isMobileMedia"); public bool CanShare() => JsSyncRuntime.Invoke("canShareStuff"); public async ValueTask ShareTextUrl(string title, string text, Uri uri, CancellationToken cancellationToken = default) => await jsRuntime.InvokeVoidAsync("shareTextUrl", cancellationToken, title, text, uri.ToString()); public async ValueTask ShareText(string title, string text, CancellationToken cancellationToken = default) => await jsRuntime.InvokeVoidAsync("shareText", cancellationToken, title, text); }