diff --git a/public/pwaInstall.js b/public/pwaInstall.js index 37d83fb..422e3a4 100644 --- a/public/pwaInstall.js +++ b/public/pwaInstall.js @@ -1,24 +1,26 @@ // src/pwaInstall.js let deferredPrompt = null; +let promptShown = false; -// Stocke l'événement natif quand Chrome le déclenche (après interactions) +// Stocke l'événement natif (se déclenche après interactions) window.addEventListener('beforeinstallprompt', (e) => { e.preventDefault(); deferredPrompt = e; - console.log('PWA: Install prompt ready - waiting for user click on button'); + console.log('PWA: Install prompt ready - button can trigger it now'); }); // Fonction appelée par le bouton "Install" export function promptInstall() { - if (deferredPrompt) { - console.log('PWA: Triggering native install prompt'); + if (deferredPrompt && !promptShown) { + console.log('PWA: Triggering native prompt'); deferredPrompt.prompt(); + promptShown = true; deferredPrompt.userChoice.then((choiceResult) => { console.log('PWA Install outcome:', choiceResult.outcome); deferredPrompt = null; }); } else { - console.log('PWA: No prompt ready yet - interact with the site (scroll, click)'); - alert('PWA not ready yet. Try scrolling, clicking filters or markers, then click Install again.'); + console.log('PWA: No prompt ready - scroll/click more on the site'); + alert('PWA not ready yet. Try scrolling the map, clicking filters or markers, then click Install again.'); } } \ No newline at end of file