'use client'; import { useState, useEffect } from 'react'; export default function InstallPrompt() { const [isIOS, setIsIOS] = useState(false); const [isStandalone, setIsStandalone] = useState(false); const [showPrompt, setShowPrompt] = useState(false); const [deferredPrompt, setDeferredPrompt] = useState(null); useEffect(() => { // Check if already in standalone mode const isStandaloneMode = window.matchMedia('(display-mode: standalone)').matches || (window.navigator as any).standalone; setIsStandalone(isStandaloneMode); // Check if iOS const userAgent = window.navigator.userAgent.toLowerCase(); const isIosDevice = /iphone|ipad|ipod/.test(userAgent); setIsIOS(isIosDevice); // Check if already dismissed const isDismissed = localStorage.getItem('installPromptDismissed'); if (!isStandaloneMode && !isDismissed) { if (isIosDevice) { // Show prompt for iOS immediately if not dismissed setShowPrompt(true); } else { // For Android/Desktop, wait for beforeinstallprompt const handleBeforeInstallPrompt = (e: Event) => { e.preventDefault(); setDeferredPrompt(e); setShowPrompt(true); }; window.addEventListener('beforeinstallprompt', handleBeforeInstallPrompt); return () => { window.removeEventListener('beforeinstallprompt', handleBeforeInstallPrompt); }; } } }, []); const handleInstallClick = async () => { if (deferredPrompt) { deferredPrompt.prompt(); const { outcome } = await deferredPrompt.userChoice; if (outcome === 'accepted') { setDeferredPrompt(null); setShowPrompt(false); } } }; const handleDismiss = () => { setShowPrompt(false); localStorage.setItem('installPromptDismissed', 'true'); }; if (!showPrompt) return null; return (

Install Hördle App

Install the app for a better experience and quick access!

{isIOS ? (
Tap share then "Add to Home Screen" +
) : ( )}
); }