Standalone installable PWA with: - JWT login via /api/auth/login - Event list from /api/live/events - QR code camera scanning (html5-qrcode library) - Scan results with accepted/refused state and ticket details - Auto token refresh on expiry - Offline caching via service worker - Dark theme optimized for outdoor scanning - Vibration feedback on scan Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
28 lines
744 B
JavaScript
28 lines
744 B
JavaScript
const CACHE_NAME = 'scanner-v1';
|
|
const ASSETS = [
|
|
'/scanner',
|
|
'https://unpkg.com/html5-qrcode@2.3.8/html5-qrcode.min.js',
|
|
];
|
|
|
|
self.addEventListener('install', (e) => {
|
|
e.waitUntil(caches.open(CACHE_NAME).then(c => c.addAll(ASSETS)));
|
|
self.skipWaiting();
|
|
});
|
|
|
|
self.addEventListener('activate', (e) => {
|
|
e.waitUntil(
|
|
caches.keys().then(keys => Promise.all(
|
|
keys.filter(k => k !== CACHE_NAME).map(k => caches.delete(k))
|
|
))
|
|
);
|
|
self.clients.claim();
|
|
});
|
|
|
|
self.addEventListener('fetch', (e) => {
|
|
if (e.request.method !== 'GET') return;
|
|
if (e.request.url.includes('/api/')) return;
|
|
e.respondWith(
|
|
caches.match(e.request).then(cached => cached || fetch(e.request))
|
|
);
|
|
});
|