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