From 8ac01000ec36b0d1a5c00a602f7bdcc5df1cde10 Mon Sep 17 00:00:00 2001 From: Nick Beckley Date: Wed, 28 Oct 2026 20:46:25 +0000 Subject: [PATCH] Keep app installation discoverable when browser prompts are unavailable --- PlotLine.Tests/Browser/application-pwa.cjs | 7 ++++++- .../Views/Shared/_ApplicationShell.cshtml | 19 +++++++++++++++++++ PlotLine/wwwroot/js/application-pwa.js | 18 ++++++++++++++++-- docs/navigation/installable-application.md | 2 +- 4 files changed, 42 insertions(+), 4 deletions(-) diff --git a/PlotLine.Tests/Browser/application-pwa.cjs b/PlotLine.Tests/Browser/application-pwa.cjs index ac10ea59..4f59b994 100644 --- a/PlotLine.Tests/Browser/application-pwa.cjs +++ b/PlotLine.Tests/Browser/application-pwa.cjs @@ -9,7 +9,7 @@ const server = http.createServer((req, res) => { res.setHeader('Cache-Control', 'no-cache'); if (req.url === '/fixture') { res.setHeader('Content-Type', 'text/html'); - res.end(``); + res.end(``); } else if (req.url === '/service-worker.js') { res.setHeader('Content-Type', 'application/javascript'); res.end(fs.readFileSync(path.join(root, 'service-worker.js'), 'utf8') + `\n// test deployment ${workerRevision}`); @@ -60,6 +60,8 @@ const server = http.createServer((req, res) => { await context.setOffline(true); assert.equal(await page.evaluate(() => fetch('/private-data', { cache: 'no-store' }).then(() => false, () => true)), true); await context.setOffline(false); + assert.equal(await page.locator('[data-pwa-install-item]').isVisible(), true); + assert.equal(await page.locator('[data-pwa-install]').textContent(), 'App installation…'); // Browser supplies this event only when installable; exercise one-shot UI handling. await page.evaluate(() => { const event = new Event('beforeinstallprompt', { cancelable: true }); @@ -70,6 +72,9 @@ const server = http.createServer((req, res) => { assert.equal(await page.locator('[data-pwa-install-item]').isVisible(), true); await page.click('[data-pwa-install]'); assert.equal(await page.evaluate(() => window.prompted), true); + assert.equal(await page.locator('[data-pwa-install-item]').isVisible(), true); + assert.equal(await page.locator('[data-pwa-install]').textContent(), 'App installation…'); + await page.evaluate(() => window.dispatchEvent(new Event('appinstalled'))); assert.equal(await page.locator('[data-pwa-install-item]').isVisible(), false); console.log('PASS PWA: manifest/icons, four theme metadata values, real worker activation/update without lost edits, no Cache Storage, private data unavailable offline, install action.'); } finally { await browser.close(); await new Promise(resolve => server.close(resolve)); } diff --git a/PlotLine/Views/Shared/_ApplicationShell.cshtml b/PlotLine/Views/Shared/_ApplicationShell.cshtml index 4cd4ae0d..4a9618b8 100644 --- a/PlotLine/Views/Shared/_ApplicationShell.cshtml +++ b/PlotLine/Views/Shared/_ApplicationShell.cshtml @@ -146,3 +146,22 @@ + + diff --git a/PlotLine/wwwroot/js/application-pwa.js b/PlotLine/wwwroot/js/application-pwa.js index 7d96a4a4..ecba40f3 100644 --- a/PlotLine/wwwroot/js/application-pwa.js +++ b/PlotLine/wwwroot/js/application-pwa.js @@ -5,10 +5,16 @@ const status = document.querySelector('[data-pwa-status]'); const standalone = window.matchMedia('(display-mode: standalone)'); let installPrompt = null; + let installedThisSession = false; function updateMode() { const installed = standalone.matches || navigator.standalone === true; root.dataset.standalone = String(installed); - if (installItem) installItem.hidden = installed || !installPrompt; + if (installItem) installItem.hidden = installed || installedThisSession; + if (installButton) { + installButton.textContent = installPrompt ? 'Install PlotDirector…' : 'App installation…'; + if (installPrompt) installButton.removeAttribute('aria-haspopup'); + else installButton.setAttribute('aria-haspopup', 'dialog'); + } } function updateTheme() { // The shell's tokens remain the only palette; theme changes include save rollback. @@ -24,12 +30,20 @@ updateMode(); }); window.addEventListener('appinstalled', () => { + installedThisSession = true; installPrompt = null; updateMode(); if (status) status.textContent = 'PlotDirector installed'; }); installButton?.addEventListener('click', async () => { - if (!installPrompt) return; + if (!installPrompt) { + const help = document.getElementById('pwaInstallationHelp'); + if (help && window.bootstrap) { + help.addEventListener('hidden.bs.modal', () => document.getElementById('accountMenuButton')?.focus(), { once: true }); + bootstrap.Modal.getOrCreateInstance(help).show(); + } + return; + } const prompt = installPrompt; installPrompt = null; updateMode(); diff --git a/docs/navigation/installable-application.md b/docs/navigation/installable-application.md index d2672c5c..bf051408 100644 --- a/docs/navigation/installable-application.md +++ b/docs/navigation/installable-application.md @@ -24,7 +24,7 @@ The worker calls `skipWaiting` and `clients.claim` without forcing any page relo ## 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. Unsupported browsers get no inactive installation control. Installation failure does not block authoring. +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.