Files
decePubClient/Services/AppStatusService.cs
T

61 lines
2.6 KiB
C#
Raw Normal View History

2026-10-06 23:31:07 +02:00
using Microsoft.AspNetCore.Components;
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
public class AppStatusService(IJSRuntime jsRuntime)
2022-02-14 01:51:37 +01:00
{
readonly IJSInProcessRuntime JsSyncRuntime = (IJSInProcessRuntime)jsRuntime;
2022-02-14 01:51:52 +01: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");
public async ValueTask ClearCache(CancellationToken cancellationToken = default) =>
await jsRuntime.InvokeVoidAsync("clearCache", cancellationToken);
2022-02-14 01:51:52 +01: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");
}
// wwwroot/js/theme.js
public void ApplyTheme(PageSettings pageSettings) => JsSyncRuntime.InvokeVoid("neoTheme.apply", pageSettings);
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:49:49 +02:00
// whether the navigation being decided came from the Back (or Forward) button
public bool TookBack() => JsSyncRuntime.Invoke<bool>("tookBack");
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");
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
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
}