// file: crates/apps/game-reflex-poc-tauri/frontend/ts/main.ts // version: 2 import { closeMainWindow, getRuntimeLabel, notifyFrontendReady } from "./bridge"; import { startGame } from "./game"; import { initializeTracing, tracingError, tracingInfo } from "./logging"; async function main(): Promise { await initializeTracing(); const canvas = document.querySelector("#game"); const score = document.querySelector("#score"); const runtime = document.querySelector("#runtime"); if (canvas === null || score === null || runtime === null) { throw new Error("Reflex Tauri frontend DOM is incomplete"); } runtime.value = await getRuntimeLabel(); const game = await startGame(canvas, score); window.addEventListener("keydown", event => { if (event.key !== "Escape" || event.repeat) { return; } event.preventDefault(); const shouldExit = game.quit_requested_escape(); tracingInfo(`quit requested source=escape decision=${shouldExit ? "exit" : "continue"}`); if (shouldExit) { void closeMainWindow().catch(caughtError => tracingError("Tauri close command failed", caughtError)); } }); await notifyFrontendReady(); tracingInfo("Reflex Tauri frontend started"); } void main().catch(caughtError => { const message = caughtError instanceof Error ? caughtError.stack ?? caughtError.message : String(caughtError); tracingError(`Reflex Tauri frontend startup failed: ${message}`); });