diff --git a/src/main.jsx b/src/main.jsx index 21aa9dd..c26efe4 100644 --- a/src/main.jsx +++ b/src/main.jsx @@ -18,7 +18,7 @@ import "./styles/maps.css"; // ✅ pour la barre de recherche (taille + couleurs import { AuthProvider } from "./auth/AuthContext.jsx"; -// Import pour PWA install prompt (si tu as créé pwaInstall.js) +// Import pour PWA install prompt import { promptInstall } from './pwaInstall'; ReactDOM.createRoot(document.getElementById("root")).render( @@ -42,7 +42,7 @@ if ('serviceWorker' in navigator) { }); } -// Force le prompt d’installation après 5 secondes (optionnel) +// Force le prompt d’installation après 5 secondes (une seule fois) setTimeout(() => { promptInstall(); }, 5000); \ No newline at end of file diff --git a/src/pwaInstall.js b/src/pwaInstall.js index 0bb984d..2dc1c07 100644 --- a/src/pwaInstall.js +++ b/src/pwaInstall.js @@ -1,40 +1,34 @@ // src/pwaInstall.js let deferredPrompt = null; +let promptShown = false; // Flag pour n'afficher qu'une fois window.addEventListener('beforeinstallprompt', (e) => { e.preventDefault(); deferredPrompt = e; console.log('PWA install prompt ready'); + + // Affiche le prompt automatiquement après 5 secondes (une seule fois) + setTimeout(() => { + if (!promptShown && deferredPrompt) { + deferredPrompt.prompt(); + promptShown = true; + deferredPrompt.userChoice.then((choice) => { + console.log('Install outcome:', choice.outcome); + deferredPrompt = null; + }); + } + }, 5000); // 5000 ms = 5 secondes }); export function promptInstall() { - if (deferredPrompt) { + if (deferredPrompt && !promptShown) { deferredPrompt.prompt(); + promptShown = true; deferredPrompt.userChoice.then((choice) => { console.log('Install outcome:', choice.outcome); deferredPrompt = null; }); } else { - console.log('No install prompt available'); + console.log('No install prompt available or already shown'); } -} - -// Exporte la fonction pour ajouter le bouton dans TopBar -export function addPwaInstallButton(container) { - const btn = document.createElement('button'); - btn.innerHTML = ' Installer'; - btn.style.marginLeft = '8px'; - btn.style.padding = '5px 10px'; - btn.style.fontSize = '12px'; - btn.style.background = '#0ea5e9'; - btn.style.color = 'white'; - btn.style.border = 'none'; - btn.style.borderRadius = '999px'; - btn.style.cursor = 'pointer'; - btn.style.display = 'flex'; - btn.style.alignItems = 'center'; - btn.style.gap = '6px'; - btn.style.boxShadow = '0 2px 8px rgba(0,0,0,0.3)'; - btn.onclick = promptInstall; - container.appendChild(btn); } \ No newline at end of file