PlotDirector/docs/navigation/installable-application.md

8.0 KiB

Installable PlotDirector application

PlotDirector uses the existing MVC application, cookie authentication and shared shell in both browser tabs and installed windows. No separate frontend, account system or database migration is required.

Manifest and scope

PlotLine/wwwroot/site.webmanifest identifies the app as /Projects, launches /Projects, requests standalone display, and permits any orientation. Projects is an existing authenticated route: an expired session follows the normal Account/Login return-URL flow, including existing two-factor requirements. Logout remains the existing antiforgery-protected POST.

Scope is / because Projects, Books, Timeline, Account and the other MVC controllers occupy different root paths. Scope controls which navigations stay inside the app window; it is not a caching or authorisation boundary. External origins retain browser handling. No project-specific shortcuts or resume-page state are introduced.

The manifest is linked from authenticated application pages and Account pages so login remains part of the app identity. Public marketing pages do not advertise the manifest or load the PWA bootstrap. An already-registered worker can control same-origin public pages, but cannot intercept or cache them.

Icons

wwwroot/pwa/icon-192.png and icon-512.png are rendered directly from the existing favicon.svg book artwork. icon-maskable-512.png has an opaque navy background and extra padding keeping the book within the maskable safe circle. Existing public favicons are unchanged. Regenerate from the repository root with node tools/generate-pwa-icons.cjs after installing the browser-test dependencies/Chromium. Only the final PNGs and reproducible generator are committed.

Worker, caching and updates

wwwroot/service-worker.js is deliberately a lifecycle-only worker. It has no fetch handler, Cache Storage, offline fallback, local manuscript store, background sync or push subscription. Authenticated HTML, manuscript data, API responses, uploads and login/logout requests are never copied into a service-worker cache. Network and normal browser HTTP-cache semantics remain authoritative. There is no offline editing or offline promise: loss of connectivity can produce the browser's network error page.

wwwroot/js/application-pwa.js registers the worker from authenticated application pages only, at root scope with updateViaCache: 'none'. Program.cs gives the worker and manifest Cache-Control: no-cache, including when static-asset endpoints serve them. The browser checks registration on each full page load; the client also checks on return to a long-lived visible window after one hour. Updates are byte-compared by the browser. Change the worker's version comment when its responsibilities change.

The worker calls skipWaiting and clients.claim without forcing any page reload. This is safe because it does not intercept requests or impose an asset version on an existing document. Existing Razor asp-append-version content hashes select updated shell CSS/JS on the next navigation; there is no worker asset cache to invalidate or deployment identifier to synchronise. An already-open editor retains its current loaded code until normal navigation. Any future caching/fetch interception requires revisiting activation and an explicit user-safe update design.

Installation and themes

Chromium's native install UI remains available. The account menu's small “Install PlotDirector…” button appears only after a real beforeinstallprompt event and outside standalone mode. The event is consumed once; dismissal does not trigger repeated prompts. appinstalled and (display-mode: standalone) changes hide the command. When no native prompt is available, the account menu instead offers “App installation…” with browser-menu instructions. This help action does not imply that a native prompt is available; it keeps installation discoverable when browsers delay or suppress promotion. Both actions hide in standalone mode and after installation in the current document. Installation failure does not block authoring.

The same shell renders in standalone mode, with no added browser controls or fixed window dimensions. data-standalone records detection for future modest integration needs. iOS's navigator.standalone is also recognised.

The document's theme-color follows the existing --pd-chrome semantic token on initial load and every plotdirector:theme-changed event, including preference-save rollback. All four palettes therefore share one source of truth. The static manifest uses Warm Light defaults; the OS/browser may use those defaults for a launch splash before the authenticated document loads and may retain its own title-bar styling. No theme identifiers or account details are placed in public metadata.

Testing and troubleshooting

Run the normal .NET build and executable regression harness, then npm run test:pwa in PlotLine.Tests/Browser. The focused browser test checks manifest/icon dimensions, all four theme colours, an actual service-worker upgrade preserving unsaved input, empty Cache Storage, private data failing offline, and install-event handling.

On HTTPS dev, sign in using Chrome/Edge, inspect Application > Manifest and Service Workers, and install using the address-bar action or account menu. Launch the installed app; confirm standalone display, project navigation, ribbon, Quick Access, modal, four themes, logout and login. Resize the window. Verify manifest/worker responses revalidate and Application > Cache Storage has no PlotDirector data caches. Windows Start/taskbar integration should additionally be visually reviewed on Windows; Linux Chromium automation cannot prove platform-specific icon placement.

For stale visuals, navigate/reload after saving work and inspect the CSS/JS content-version query strings and HTTP response. Inspect worker registration/update errors and ensure nginx preserves no-cache metadata headers. DevTools can update or unregister this origin's worker for diagnosis; do not clear cookies/site data unnecessarily, since that signs the author out and can remove unrelated browser preferences. This worker never requires a manual cache purge after ordinary deployments.

Reference: Chromium installation debugging and DevTools PWA automation.

Future candidates include opt-in notifications, badging and context-free shortcuts. File handlers, share targets and especially offline editing need separate security, lifecycle and product designs.

Standalone sticky chrome

Only @media (display-mode: standalone) makes the single .pd-application-header sticky. The manifest does not request window-controls-overlay, so no extra display modes are inferred. Normal tabs retain document scrolling with a non-sticky header. The progress strip and workspace remain outside the sticky header.

The existing expanded/collapsed ribbon determines natural header height; its persisted account preference is unchanged. A ResizeObserver in the existing PWA bootstrap measures that height for root scroll-padding, including resize and category changes, so anchor/scrollIntoView destinations clear the chrome. There are no fixed-height workspace panels or empty ribbon placeholders.

The header uses Bootstrap's sticky layer (1020), below modal backdrops/modals (1050/1055). In standalone mode shell dialogs move to body before opening, retaining event handlers and editor styling through .pd-shell-dialog; dropdowns stay within the header above workspace content. No new theme or shadow is introduced.

Focused sticky verification: start dotnet run --project PlotLine.Tests -- --toolbar-browser-host, then run xvfb-run -a node PlotLine.Tests/Browser/sticky-shell.cjs from the repository root (omit xvfb-run on a desktop). The test installs the loopback fixture in a temporary Chromium profile and removes it afterwards. It adds long synthetic workspace content to exercise document scroll without live manuscript data.