import { useEffect, useState } from 'react' import { deliveryMode } from '../config/server' // Shown only in plain-HTTP browser mode (http://), where the page can't // work offline after a reload and can't be installed as a real PWA. // // The APK is served by the venue's own server (scripts/build-apk.mjs bundles the // release APK into the web build), so the banner appears only when that file is // actually there. VITE_APP_DOWNLOAD_URL overrides the location if ever needed. const DOWNLOAD_URL = import.meta.env.VITE_APP_DOWNLOAD_URL || '/downloads/xenia-waiter.apk' const DISMISS_KEY = 'install-banner-dismissed-until' const DISMISS_DAYS = 7 function isDismissed() { try { return Number(localStorage.getItem(DISMISS_KEY) || 0) > Date.now() } catch { return false } } export default function InstallAppBanner() { const eligible = deliveryMode() === 'plain-web' && !isDismissed() const [available, setAvailable] = useState(false) const [hidden, setHidden] = useState(false) useEffect(() => { if (!eligible) return fetch(DOWNLOAD_URL, { method: 'HEAD' }) .then(r => setAvailable(r.ok && !(r.headers.get('content-type') || '').includes('text/html'))) .catch(() => {}) }, [eligible]) if (!eligible || !available || hidden) return null function dismiss() { try { localStorage.setItem(DISMISS_KEY, String(Date.now() + DISMISS_DAYS * 86_400_000)) } catch { // storage unavailable — banner just reappears next load } setHidden(true) } return (
Για γρηγορότερη και πιο σταθερή λειτουργία, εγκαταστήστε την εφαρμογή. Εγκατάσταση
) }