five-on-it / apps/client/electron/main
apps/client/electron/main
Electron main process: one window that loads the renderer (the Vite dev server in development, the built dist/index.html otherwise). With FOI_SERVER_URL set it goes straight into the game on that server (joining someone else's game, the tests); otherwise it opens on the main menu, where the player picks Play online (the platform's game server, at the address the page knows: FOI_PLATFORM_URL here passes one as api, for testing) or Play local.
Playing local, the app hosts the game: the bundled server.mjs runs as a utility process on port 7777 (FOI_PORT), started only when the player hosts (the page asks through the bridge, bridge.ts: host, stop, status), on the level picked, so it loads that level alone. A server of this version already answering on the port (the dev server, another copy of the app) is used as it is; anything else there is refused. Friends on the network join at this machine's addresses and that port. The server runs until the app quits or the player stops hosting. Everything game-related happens in the renderer.
Crashes: with the player's consent, which the page tells it (shareConsent), the main process reports its own uncaught errors, a page that died (render-process-gone) and a hosted game server that did (child-process-gone) to the platform's /telemetry/crash, as the page reports its own (ui/telemetry.ts).
Steam (steam.ts), started before the app is ready: with the game's Steam app id (FOI_STEAM_APP_ID, baked in when the app is built, 0 in a run's environment for none) a packaged app launched outside Steam is started again by Steam and quits, the overlay is on, and the page asks for a ticket for the platform's API (the bridge's steam.ticket); without Steam the page asks for Steam's own sign-in page in a window of the app's instead (steam.openId, steam-openid.ts), whose one-time code it exchanges itself.