// Script pour gérer l'installation de l'application PWA let deferredPrompt; const installButton = document.getElementById('install-button'); const installContainer = document.getElementById('install-container'); // Cacher le bouton d'installation par défaut if (installContainer) { installContainer.style.display = 'none'; } // Écouter l'événement 'beforeinstallprompt' window.addEventListener('beforeinstallprompt', (e) => { // Empêcher le mini-infobar de Chrome de s'afficher sur mobile e.preventDefault(); // Stocker l'événement pour l'utiliser plus tard deferredPrompt = e; // Afficher le bouton d'installation if (installContainer) { installContainer.style.display = 'flex'; } // Ajouter l'écouteur d'événement pour le bouton d'installation if (installButton) { installButton.addEventListener('click', () => { // Cacher le bouton d'installation installContainer.style.display = 'none'; // Afficher l'invite d'installation deferredPrompt.prompt(); // Attendre que l'utilisateur réponde à l'invite deferredPrompt.userChoice.then((choiceResult) => { if (choiceResult.outcome === 'accepted') { console.log('L\'utilisateur a accepté l\'installation'); } else { console.log('L\'utilisateur a refusé l\'installation'); } // Effacer la référence à l'événement deferredPrompt = null; }); }); } }); // Écouter l'événement 'appinstalled' window.addEventListener('appinstalled', (e) => { // Cacher le bouton d'installation if (installContainer) { installContainer.style.display = 'none'; } console.log('Application installée'); });