using Microsoft.AspNetCore.Components; 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 string Language() => JsSyncRuntime.Invoke("getLanguage"); public void SetAppBadge(int counter) => JsSyncRuntime.InvokeVoid("setAppBadge", counter); public void ClearAppBadge() => JsSyncRuntime.InvokeVoid("clearAppBadge"); // 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"); // whether the navigation being decided came from the Back (or Forward) button public bool TookBack() => JsSyncRuntime.Invoke("tookBack"); // 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("canHover"); // read once: a card asks it for each gifv it shows bool? reducedMotion; public bool PrefersReducedMotion() => reducedMotion ??= JsSyncRuntime.Invoke("prefersReducedMotion"); // puts the text on the clipboard; false when the browser refused it, which main.js reports through logFromJs public async ValueTask CopyText(string text, CancellationToken cancellationToken = default) => await jsRuntime.InvokeAsync("copyText", cancellationToken, text); // a sideways-scrolling strip of tabs shows its selected tab public void RevealActive(ElementReference strip) => JsSyncRuntime.InvokeVoid("revealActive", strip); }