From 3536c46917768200620a22acb664e3f6d7ef8547 Mon Sep 17 00:00:00 2001 From: Carlos Tello Date: Thu, 29 Oct 2026 21:55:50 -0300 Subject: [PATCH] feat(pwa): capture beforeinstallprompt and render direct in-app install button --- frontend/src/views/ControlPostView.tsx | 47 ++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/frontend/src/views/ControlPostView.tsx b/frontend/src/views/ControlPostView.tsx index 73d0317..570cffe 100644 --- a/frontend/src/views/ControlPostView.tsx +++ b/frontend/src/views/ControlPostView.tsx @@ -204,6 +204,33 @@ export const ControlPostView: React.FC = () => { const [isSubmitting, setIsSubmitting] = useState(false); const [clock, setClock] = useState(''); + // Capturador del evento de instalación PWA (Samsung Galaxy Tab / Android / Windows) + const [deferredInstallPrompt, setDeferredInstallPrompt] = useState(null); + + useEffect(() => { + const handleBeforeInstallPrompt = (e: Event) => { + e.preventDefault(); + setDeferredInstallPrompt(e); + console.log('PWA: beforeinstallprompt disponible para instalación'); + }; + + window.addEventListener('beforeinstallprompt', handleBeforeInstallPrompt); + + return () => { + window.removeEventListener('beforeinstallprompt', handleBeforeInstallPrompt); + }; + }, []); + + const handleInstallPWA = async () => { + if (!deferredInstallPrompt) return; + deferredInstallPrompt.prompt(); + const { outcome } = await deferredInstallPrompt.userChoice; + console.log(`PWA: resultado de instalación -> ${outcome}`); + if (outcome === 'accepted') { + setDeferredInstallPrompt(null); + } + }; + // Reloj digital en tiempo real @@ -1234,6 +1261,26 @@ export const ControlPostView: React.FC = () => { ● + {/* Botón de Instalación Directa PWA (Solo visible cuando Chrome/Android detecta elegibilidad) */} + {deferredInstallPrompt && ( + + )} + {/* Botón Selector Tema Claro / Oscuro */}