sw-fe/public/pwaInstall.js

24 lines
864 B
JavaScript

// src/pwaInstall.js
let deferredPrompt = null;
// Stocke l'événement natif quand Chrome le 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');
});
// Fonction appelée par le bouton "Install"
export function promptInstall() {
if (deferredPrompt) {
console.log('PWA: Triggering native install prompt');
deferredPrompt.prompt();
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.');
}
}