feat(pwa): capture beforeinstallprompt and render direct in-app install button
This commit is contained in:
@@ -204,6 +204,33 @@ export const ControlPostView: React.FC = () => {
|
||||
const [isSubmitting, setIsSubmitting] = useState<boolean>(false);
|
||||
const [clock, setClock] = useState<string>('');
|
||||
|
||||
// Capturador del evento de instalación PWA (Samsung Galaxy Tab / Android / Windows)
|
||||
const [deferredInstallPrompt, setDeferredInstallPrompt] = useState<any>(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 = () => {
|
||||
<span style={{ color: wsConnected ? '#10B981' : '#F59E0B' }}>●</span>
|
||||
</button>
|
||||
|
||||
{/* Botón de Instalación Directa PWA (Solo visible cuando Chrome/Android detecta elegibilidad) */}
|
||||
{deferredInstallPrompt && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleInstallPWA}
|
||||
className="desktop-btn-action desktop-btn-green"
|
||||
style={{
|
||||
padding: '0.25rem 0.65rem',
|
||||
fontSize: '0.8rem',
|
||||
fontWeight: 800,
|
||||
borderRadius: '6px',
|
||||
boxShadow: '0 0 10px rgba(16, 185, 129, 0.45)',
|
||||
animation: 'pulse 2s infinite',
|
||||
}}
|
||||
title="Instalar OnEverControl como Aplicación en esta Tablet"
|
||||
>
|
||||
📲 Instalar App
|
||||
</button>
|
||||
)}
|
||||
|
||||
{/* Botón Selector Tema Claro / Oscuro */}
|
||||
<button
|
||||
type="button"
|
||||
|
||||
Reference in New Issue
Block a user