fix: attach PWA install click handler at render time, not conditionally
beforeinstallprompt fires asynchronously after renderLanding() runs, so the click handler was never attached when the prompt arrived late. Always attach the handler and check deferredInstallPrompt at click time.
This commit is contained in:
parent
48deaa3219
commit
fade4c3ae5
1 changed files with 9 additions and 9 deletions
|
|
@ -116,22 +116,22 @@ function renderLanding() {
|
|||
const btn = app.querySelector('[data-install-btn]');
|
||||
const hint = app.querySelector('[data-install-hint]');
|
||||
|
||||
if (deferredInstallPrompt) {
|
||||
wrap.hidden = false;
|
||||
// Show immediately if we already have the prompt or are on iOS
|
||||
if (deferredInstallPrompt || isIOS) wrap.hidden = false;
|
||||
|
||||
// Always attach handler — check state at click time (handles async beforeinstallprompt)
|
||||
btn.addEventListener('click', async () => {
|
||||
if (deferredInstallPrompt) {
|
||||
deferredInstallPrompt.prompt();
|
||||
const { outcome } = await deferredInstallPrompt.userChoice;
|
||||
if (outcome === 'accepted') {
|
||||
deferredInstallPrompt = null;
|
||||
wrap.hidden = true;
|
||||
}
|
||||
});
|
||||
} else if (isIOS) {
|
||||
wrap.hidden = false;
|
||||
btn.addEventListener('click', () => {
|
||||
hint.hidden = !hint.hidden;
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/* ---------- Render: route page ---------- */
|
||||
|
|
|
|||
Loading…
Reference in a new issue