import { useEffect, useState } from 'react' import { markBundleReady, syncVenueBundle } from '../native/bundles' import { useTranslation } from '@xenia/i18n' const FIRST_SYNC_DELAY_MS = 3000 // let a TLS upgrade / rediscovery reload settle first const PERIODIC_SYNC_MS = 30 * 60_000 /** * Native app: keep running the active venue's own UI bundle (plan step 8). * Syncs on start, when the app returns to the foreground and every 30 minutes; * see src/native/bundles.js for when a new bundle is applied. Shows a banner * only if the venue's UI needs a newer APK than the one installed. */ export default function BundleSync() { const { t } = useTranslation('waiter') const [apkUpdate, setApkUpdate] = useState(null) // APK download URL when the shell is too old useEffect(() => { markBundleReady() let cancelled = false let resumeHandle = null async function sync() { const result = await syncVenueBundle() if (!cancelled) setApkUpdate(result.status === 'shell-too-old' ? result.apk : null) } const first = setTimeout(sync, FIRST_SYNC_DELAY_MS) const periodic = setInterval(sync, PERIODIC_SYNC_MS) import('@capacitor/app').then(({ App }) => App.addListener('resume', sync)).then(h => { if (cancelled) h.remove() else resumeHandle = h }) return () => { cancelled = true clearTimeout(first) clearInterval(periodic) resumeHandle?.remove() } }, []) if (!apkUpdate) return null return (