"use client"; import { useEffect, useState } from "react"; import { erkennePlattform, ladeWeggeklicktAm, sollHinweisZeigen, speichereWeggeklicktAm, type Plattform, } from "@/lib/pwa/install-hinweis"; type InstallPromptEvent = Event & { prompt: () => Promise }; type Zustand = { plattform: Plattform; standalone: boolean; weggeklicktAm: number | null; jetzt: number }; function TeilenIcon() { return ( ); } export function InstallHinweis() { const [zustand, setZustand] = useState(null); const [installiert, setInstalliert] = useState(false); const [installEvent, setInstallEvent] = useState(null); useEffect(() => { const nav = navigator as Navigator & { standalone?: boolean }; // eslint-disable-next-line react-hooks/set-state-in-effect -- Browser-Werte erst nach Mount lesen (kein Hydration-Mismatch) setZustand({ plattform: erkennePlattform(navigator.userAgent, navigator.maxTouchPoints), standalone: window.matchMedia("(display-mode: standalone)").matches || nav.standalone === true, weggeklicktAm: ladeWeggeklicktAm(window.localStorage), jetzt: Date.now(), }); const beiPrompt = (e: Event) => { e.preventDefault(); setInstallEvent(e as InstallPromptEvent); }; const beiInstalliert = () => { setInstalliert(true); speichereWeggeklicktAm(window.localStorage, Number.MAX_SAFE_INTEGER); }; window.addEventListener("beforeinstallprompt", beiPrompt); window.addEventListener("appinstalled", beiInstalliert); return () => { window.removeEventListener("beforeinstallprompt", beiPrompt); window.removeEventListener("appinstalled", beiInstalliert); }; }, []); if (!zustand) return null; if (!sollHinweisZeigen({ ...zustand, installiert })) return null; function schliessen() { const jetzt = Date.now(); speichereWeggeklicktAm(window.localStorage, jetzt); setZustand((z) => (z ? { ...z, weggeklicktAm: jetzt, jetzt } : z)); } async function installieren() { if (!installEvent) return; const event = installEvent; setInstallEvent(null); await event.prompt(); } const { plattform } = zustand; return (

App auf dem Startbildschirm installieren

{plattform === "ios-safari" && (

Tippe auf Teilen und dann „Zum Home-Bildschirm“.

)} {plattform === "ios-anderer-browser" && (

Öffne die Seite in Safari, tippe auf Teilen und dann „Zum Home-Bildschirm“.

)} {plattform === "android" && !installEvent &&

Im Browsermenü ⋮ „App installieren“ wählen.

} {plattform === "android" && installEvent && ( )}
); }