feat(waiter): native app runs each venue's own UI bundle (self-hosted updater)

@capgo/capacitor-updater (MPL-2.0) in manual mode: autoUpdate off,
stats/update/channel URLs empty (nothing contacts Capgo), appReadyTimeout
15s (auto rollback), resetWhenUpdate (APK update → built-in bundle, venue
bundle re-fetched), autoDeletePrevious off (we keep one per venue).

src/native/bundles.js syncVenueBundle():
- manifest fetched over the pinned TLS link; zip downloaded natively over
  the LAN HTTP port with the MANDATORY sha256 check - a tampered zip never runs
- applied at once only when nobody is mid-service (after pairing / venue
  switch, or no one logged in); otherwise staged with next() → applied at the
  next background/restart; never a mid-service reload
- APK too old for the bundle (min_shell_build) → skipped + update banner
  linking to the venue's /downloads/xenia-waiter.apk
- a rolled-back version is blocklisted (attempt tracking + grace window) -
  without it the app re-applied the still-advertised broken bundle in a loop
- server without bundles (404) → built-in UI; bundles no venue needs deleted
BundleSync: notifyAppReady on start; sync at start, on resume, every 30 min.
saveVenue merges fields (bundleVersion); switchVenue flags immediate apply.

E2E (emulator vs two isolated venue stacks): fresh pairing applies the venue
bundle and it stays healthy; logged-in update staged, applied after
background, session kept; tampered zip refused; shell-too-old banner;
broken bundle rolled back automatically and not retried (80s + resume);
two venues each run their own bundle, round trips served from cache with 0
downloads, stale bundles cleaned; no *.capgo.app traffic. Step 5/7-era
rediscovery + cold-start suites and web modes still pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-09-28 18:24:48 +03:00
co-authored by Claude Opus 5.5
parent a1e415ac05
commit fe264f0a23
9 changed files with 320 additions and 4 deletions
+65
View File
@@ -0,0 +1,65 @@
import { useEffect, useState } from 'react'
import { markBundleReady, syncVenueBundle } from '../native/bundles'
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 [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 (
<div style={{
position: 'fixed', bottom: 80, left: 12, right: 12, zIndex: 9998,
background: 'var(--bg2)', border: '1px solid var(--accent)', borderRadius: 16,
padding: '12px 14px', display: 'flex', alignItems: 'center', gap: 12,
boxShadow: '0 8px 32px rgba(0,0,0,0.4)',
}}>
<span style={{ flex: 1, fontSize: 13, color: 'var(--text)', lineHeight: 1.35 }}>
Ο server του καταστήματος χρειάζεται νεότερη έκδοση της εφαρμογής.
</span>
<a
href={apkUpdate}
target="_blank"
rel="noreferrer"
style={{
background: 'var(--accent)', color: '#0f172a', borderRadius: 10, padding: '8px 14px',
fontSize: 14, fontWeight: 700, textDecoration: 'none', whiteSpace: 'nowrap',
}}
>
Ενημέρωση
</a>
</div>
)
}