On a phone the Back button left the page under an open menu, sheet or dialog. An open overlay now says so (new IDOverlayHost, cascaded by MainLayout; OverlayService keeps them newest last): DModal and DDropdown through the cascade, so the D components stay free of app services, and the nav menu, PhoneSheet and the full-screen globe through the service. MainLayout's location-changing handler lets Back close the newest overlay instead of leaving the page; a link followed or the app's own navigation (signing out after its question, say) closes them all and goes on. Blazor can't tell Back from the app's navigation, so a capture-phase popstate listener in main.js marks Back (AppStatusService.TookBack). No history entries are pushed. Phone flow: Back closes the menu, a card's More sheet, the composer and the full-screen globe one after another without leaving the feed, and with nothing open goes back. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LsXgEaXee4GCU1hwYgPJXw
61 lines
2.6 KiB
C#
61 lines
2.6 KiB
C#
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<bool> IsOnline(CancellationToken cancellationToken = default) =>
|
|
await jsRuntime.InvokeAsync<bool>("isOnline", cancellationToken);
|
|
|
|
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);
|
|
|
|
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<bool>("neoTheme.isDark");
|
|
|
|
public bool IsMobileMedia() => JsSyncRuntime.Invoke<bool>("isMobileMedia");
|
|
|
|
// whether the navigation being decided came from the Back (or Forward) button
|
|
public bool TookBack() => JsSyncRuntime.Invoke<bool>("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<bool>("canHover");
|
|
|
|
// a sideways-scrolling strip of tabs shows its selected tab
|
|
public void RevealActive(ElementReference strip) => JsSyncRuntime.InvokeVoid("revealActive", strip);
|
|
|
|
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());
|
|
|
|
public async ValueTask ShareText(string title, string text, CancellationToken cancellationToken = default) =>
|
|
await jsRuntime.InvokeVoidAsync("shareText", cancellationToken, title, text);
|
|
} |