update frontend
This commit is contained in:
parent
f2f902f24b
commit
a909b02e37
|
|
@ -2,46 +2,39 @@
|
|||
let deferredPrompt = null;
|
||||
|
||||
window.addEventListener('beforeinstallprompt', (e) => {
|
||||
// Empêche le prompt par défaut
|
||||
e.preventDefault();
|
||||
deferredPrompt = e;
|
||||
console.log('PWA install prompt ready');
|
||||
});
|
||||
|
||||
// Fonction pour déclencher l’install (tu peux l’appeler sur un bouton)
|
||||
export function promptInstall() {
|
||||
if (deferredPrompt) {
|
||||
deferredPrompt.prompt();
|
||||
deferredPrompt.userChoice.then((choiceResult) => {
|
||||
if (choiceResult.outcome === 'accepted') {
|
||||
console.log('PWA installed');
|
||||
} else {
|
||||
console.log('PWA dismissed');
|
||||
}
|
||||
deferredPrompt.userChoice.then((choice) => {
|
||||
console.log('Install outcome:', choice.outcome);
|
||||
deferredPrompt = null;
|
||||
});
|
||||
} else {
|
||||
console.log('No install prompt available');
|
||||
}
|
||||
}
|
||||
|
||||
// Ajoute un bouton "Installer l’app" dans ton UI (optionnel)
|
||||
export function addInstallButton() {
|
||||
// Exporte la fonction pour ajouter le bouton dans TopBar
|
||||
export function addPwaInstallButton(container) {
|
||||
const btn = document.createElement('button');
|
||||
btn.textContent = 'Installer SocioWire';
|
||||
btn.style.position = 'fixed';
|
||||
btn.style.bottom = '20px';
|
||||
btn.style.right = '20px';
|
||||
btn.style.padding = '10px 20px';
|
||||
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 = '8px';
|
||||
btn.style.borderRadius = '999px';
|
||||
btn.style.cursor = 'pointer';
|
||||
btn.style.zIndex = '9999';
|
||||
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;
|
||||
document.body.appendChild(btn);
|
||||
}
|
||||
|
||||
// Détection si déjà installé (cache)
|
||||
if (window.matchMedia('(display-mode: standalone)').matches || navigator.standalone) {
|
||||
console.log('App already installed');
|
||||
container.appendChild(btn);
|
||||
}
|
||||
Loading…
Reference in New Issue