feat(printer): badge print queue, Pi worker, captive-portal setup, admin printing view

- migration 20261018170000: pgmq badge_print/badge_print_dlq, print_stations,
  token-gated printer RPCs (claim/complete/fail/heartbeat), admin RPCs,
  welcome_checkin enqueue; badge_print_tests.sql (101 assertions)
- apps/printer: Python worker (Playwright render -> brother_ql via pyusb),
  comitup captive-portal (Wi-Fi + HTTPS endpoint + anon key + token),
  arm64 image build + idempotent Pi setup/install scripts, 77 pytest
- apps/admin: Printing view, station management/DLQ, global printer status
  pill, Print button on Registrations, standalone print renderer entry
  (print.html -> dist-print) with bundled fonts
- docs: printing.md + architecture/schema/rpcs/tests/admin-app updates,
  apps/printer/AGENT.md operating manual
- e2e: printing.spec.ts
This commit is contained in:
Lago committed 2026-10-18 22:25:38 +02:00
1 parent 04f3f55b78
commit c980effddc
55 files changed
+7406 -29

No files matched your search

+77
View File
@@ -0,0 +1,77 @@
import { flushSync } from 'react-dom';
import { createRoot, type Root } from 'react-dom/client';
import { BadgePagePreview, MM } from '../components/BadgeRender';
import type { BadgePrintPayload } from '../lib/types';
declare global {
interface Window {
/** Render one badge; resolves with its size in CSS pixels. */
renderBadge: (
payload: BadgePrintPayload,
options?: { checkinOrigin?: string },
) => Promise<{ width_px: number; height_px: number }>;
__badgeReady: boolean;
__badgeError: string | null;
}
}
const SCHEMA = 'convivo.badge-print/v1';
let root: Root | null = null;
function nextFrame(): Promise<void> {
return new Promise((resolve) => requestAnimationFrame(() => resolve()));
}
/** Wait until every image inside the badge is decoded (rejects on a broken src). */
async function waitForImages(host: HTMLElement): Promise<void> {
const images = Array.from(host.querySelectorAll('img'));
for (const img of images) {
try {
await img.decode();
} catch {
throw new Error(`image failed to load: ${img.src || img.getAttribute('src') || ''}`);
}
}
}
async function renderBadge(
payload: BadgePrintPayload,
options?: { checkinOrigin?: string },
): Promise<{ width_px: number; height_px: number }> {
window.__badgeReady = false;
window.__badgeError = null;
try {
if (!payload || payload.schema !== SCHEMA) {
throw new Error(`unsupported print payload schema: ${payload?.schema}`);
}
const host = document.getElementById('badge-root');
if (!host) throw new Error('badge-root element not found');
if (!root) root = createRoot(host);
flushSync(() => {
root?.render(
<BadgePagePreview
layout={payload.layout}
sample={{ ...payload.sample, checkin_origin: options?.checkinOrigin }}
pxPerMm={MM}
/>,
);
});
await document.fonts.ready;
await waitForImages(host);
await nextFrame();
await nextFrame();
const page = host.querySelector<HTMLElement>('.badge-page');
if (!page) throw new Error('badge page did not render');
const box = page.getBoundingClientRect();
window.__badgeReady = true;
return { width_px: box.width, height_px: box.height };
} catch (err) {
window.__badgeError = err instanceof Error ? err.message : String(err);
throw err;
}
}
window.renderBadge = renderBadge;
window.__badgeReady = false;
window.__badgeError = null;