feat(waiter): native pairing, venue switcher, QR scanner, Android back handling

- First run in the native app shows only the pairing screen (VenuesPage):
  scan the manager's pairing QR or type the server address; the server must
  answer /api/system/identity as xenia-pos with a supported api_version, and
  a QR's ?pair=<site_id> must match - a code from another venue is refused
- /venues (native only): list of paired venues, switch (reloads into that
  venue's own token/IndexedDB), remove (data kept - may hold unsynced
  orders). Reachable from the login screen, the user menu and the offline page
- QrScannerModal: WebView camera via qr-scanner (no Google Play Services
  dependency, carries over to iOS); requests the camera once up front so the
  Android prompt appears a single time and "denied" gets its own message
- Hardware back: @capacitor/app listener - no-op on root screens (/, /tables,
  /login), otherwise history back. Path-based because Chrome's history
  intervention makes the WebView report canGoBack=false for the sentinel
  entry AndroidBackGuard pushes
- Before pairing no IndexedDB is opened, so nothing is created under the
  un-namespaced name
- InstallAppBanner now shows in plain-HTTP browser mode only when the venue
  server actually serves the APK (HEAD /downloads/xenia-waiter.apk)

Verified on an Android 15 emulator (API 35) with real taps via adb and state
via WebView DevTools: wrong address -> error; other venue's QR -> refused;
pairing -> venue-namespaced storage, live WebSocket; back on /tables keeps the
app open; restart keeps venue + session; second venue pairs logged-out and
switching back keeps venue 1's session; camera deny -> one prompt + message;
allow -> live preview. Signed release APK installed and paired. Web modes
(same-origin, plain-HTTP LAN IP, VITE_SERVER_URL) re-verified in Edge.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-09-28 13:31:23 +03:00
co-authored by Claude Opus 5.5
parent 0b0f5c60c3
commit a486e3ff63
10 changed files with 440 additions and 12 deletions
+13 -2
View File
@@ -25,7 +25,8 @@ import ConnectivityBar from './components/ConnectivityBar'
import AppShell from './components/AppShell'
import UpdatePrompt from './components/UpdatePrompt'
import InstallAppBanner from './components/InstallAppBanner'
import { deliveryMode } from './config/server'
import VenuesPage from './pages/VenuesPage'
import { deliveryMode, getActiveVenue } from './config/server'
// ─── Utility ─────────────────────────────────────────────────────────────────
@@ -288,6 +289,8 @@ function OfflineListener() {
const { status } = useConnectionStore()
useEffect(() => {
function handler() {
// The venue switcher must stay usable while the current venue is unreachable
if (window.location.pathname === '/venues') return
// If user is logged in, ConnectivityBar handles it — don't redirect to /offline
if (token && status !== 'online') return
// Not logged in and server is down → redirect to offline page
@@ -313,11 +316,13 @@ function ThemeApplier() {
// push a sentinel entry so there is always one history entry behind it. If the
// user backs into the sentinel we push it again — they can never back past /tables.
//
// Only active when running as an installed PWA (standalone display mode).
// Only active when running as an installed PWA (standalone display mode) or in
// the native app, where the hardware back button would otherwise close the app.
function AndroidBackGuard() {
useEffect(() => {
const isStandalone = window.matchMedia('(display-mode: standalone)').matches
|| window.navigator.standalone === true
|| deliveryMode() === 'native'
if (!isStandalone) return
function pushSentinel() {
@@ -402,6 +407,11 @@ function TableListRoute() {
const queryClient = new QueryClient()
export default function App() {
// Native app with no paired venue yet: nothing else can work, show pairing only
if (deliveryMode() === 'native' && !getActiveVenue()) {
return <VenuesPage firstRun />
}
return (
<QueryClientProvider client={queryClient}>
<BrowserRouter>
@@ -420,6 +430,7 @@ export default function App() {
<Routes>
<Route path="/login" element={<LoginGuard><LoginPage /></LoginGuard>} />
<Route path="/offline" element={<OfflinePage />} />
<Route path="/venues" element={deliveryMode() === 'native' ? <VenuesPage /> : <Navigate to="/" replace />} />
<Route element={<AppLayout />}>
<Route index element={<Navigate to="/tables?tab=tables" replace />} />
<Route path="/tables" element={<TableListRoute />} />