update frontend
This commit is contained in:
parent
eb018a0bee
commit
8508f0f98f
|
|
@ -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);
|
||||
|
|
@ -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 = '<i class="fa-solid fa-download"></i> 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);
|
||||
}
|
||||
Loading…
Reference in New Issue