"use client"; import * as React from "react"; import { Download, Share, SquarePlus, X } from "lucide-react"; import { Button } from "@/components/ui/button"; import { useLocalStorage, useMounted, useStandalone } from "@/lib/client/hooks"; import { cn } from "@/lib/utils"; interface BeforeInstallPromptEvent extends Event { prompt: () => Promise; userChoice: Promise<{ outcome: "accepted" | "dismissed" }>; } function isIOS() { if (typeof navigator === "undefined") return false; const ua = navigator.userAgent; return /iPhone|iPad|iPod/.test(ua) || (ua.includes("Mac") && "ontouchend" in document); } /** * "Install PolyLLM" hint. Uses `beforeinstallprompt` where the browser supports it (Chromium, * Android) and shows the Share → Add to Home Screen tip on iOS Safari. Hidden when already * installed (standalone) or after the visitor dismisses it. Marketing only — Settings → Appearance * has its own hint. */ export function InstallHint({ className, compact }: { className?: string; compact?: boolean }) { const mounted = useMounted(); const standalone = useStandalone(); const [dismissed, setDismissed] = useLocalStorage("polyllm:install-hint-dismissed", false); const [deferred, setDeferred] = React.useState(null); const [installed, setInstalled] = React.useState(false); const [ios, setIos] = React.useState(false); React.useEffect(() => { // eslint-disable-next-line react-hooks/set-state-in-effect setIos(isIOS()); const onPrompt = (e: Event) => { e.preventDefault(); setDeferred(e as BeforeInstallPromptEvent); }; const onInstalled = () => setInstalled(true); window.addEventListener("beforeinstallprompt", onPrompt); window.addEventListener("appinstalled", onInstalled); return () => { window.removeEventListener("beforeinstallprompt", onPrompt); window.removeEventListener("appinstalled", onInstalled); }; }, []); if (!mounted || standalone || dismissed || installed) return null; if (!deferred && !ios) return null; const install = async () => { if (!deferred) return; await deferred.prompt(); const { outcome } = await deferred.userChoice; if (outcome === "accepted") setInstalled(true); setDeferred(null); }; return (
{deferred ? : }

Install PolyLLM

{deferred ? (

Add it to your home screen or dock: it opens full-screen, remembers your session and feels like a native app.

) : (

In Safari, tap Share, then Add to Home Screen. PolyLLM opens full-screen with its own icon.

)} {deferred ? ( ) : null}
); }