From e47daa2efb0781044528141c80ccd96b21641e37 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 21 Dec 2025 19:09:10 -0500 Subject: [PATCH] update frontend --- public/pwaInstall.js | 47 ++++++++++++++++++++++++++++++++++++++++++++ src/pwaInstall.js | 47 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 public/pwaInstall.js create mode 100644 src/pwaInstall.js diff --git a/public/pwaInstall.js b/public/pwaInstall.js new file mode 100644 index 0000000..600e819 --- /dev/null +++ b/public/pwaInstall.js @@ -0,0 +1,47 @@ +// src/pwaInstall.js +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 = null; + }); + } +} + +// Ajoute un bouton "Installer l’app" dans ton UI (optionnel) +export function addInstallButton() { + 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.style.background = '#0ea5e9'; + btn.style.color = 'white'; + btn.style.border = 'none'; + btn.style.borderRadius = '8px'; + btn.style.cursor = 'pointer'; + btn.style.zIndex = '9999'; + 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'); +} \ No newline at end of file diff --git a/src/pwaInstall.js b/src/pwaInstall.js new file mode 100644 index 0000000..600e819 --- /dev/null +++ b/src/pwaInstall.js @@ -0,0 +1,47 @@ +// src/pwaInstall.js +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 = null; + }); + } +} + +// Ajoute un bouton "Installer l’app" dans ton UI (optionnel) +export function addInstallButton() { + 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.style.background = '#0ea5e9'; + btn.style.color = 'white'; + btn.style.border = 'none'; + btn.style.borderRadius = '8px'; + btn.style.cursor = 'pointer'; + btn.style.zIndex = '9999'; + 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'); +} \ No newline at end of file