Skip to content

A desktop app ​

Ship your game as an installed app (Electron), or as a page that opens with no network. A game played in the page asks only for its own files, so both come down to keeping those files and giving the page a window. A game on a server still needs its server.

Quick start ​

sh
npm create @v12-engine quest -- --desktop
cd quest
npm run app       # the app on the dev server, changes show at once
npm run package   # the app to hand out, into out/

The app starts full screen with no frame, saves and settings are files, closing the window saves the game, and the start menu has Exit. Electron is fetched the first time you run app or package (100–260 MB); the app is about 270 MB. On macOS, Xcode's command line tools (xcode-select --install) compile the small addon that hides the Dock and menu bar.

Common tasks ​

Ship the typefaces with the game ​

ts
import '@v12-engine/client/styles.css'
import '@v12-engine/client/fonts.css'

A bundler copies the font files into the build, so no font service is asked.

Make the page work offline ​

Copy the example's three files: apps/example/scripts/offline.ts (a Vite plugin writing sw.js), apps/example/scripts/offline.worker.js (the worker) and apps/example/src/offline.ts (keepOffline).

ts
import { defineConfig } from 'vite'
import { offline } from './scripts/offline.ts'

export default defineConfig({
	plugins: [offline({ leaveOut: (path) => path.startsWith('models/huge/') })]
})
ts
import { keepOffline } from './offline'

keepOffline({
	onReady: () => app.overlays.toast('Kept on this device: the game now opens with no network'),
	onUpdate: (apply) => app.overlays.toast('A new version is ready', { seconds: 20, action: { label: 'Load it', run: apply } })
})

Try it with npm run build -w example && npm run preview; there is no worker under npm run dev.

Keep saves and settings as files ​

ts
import { desktop } from './desktop'

const shell = desktop()
const scenes = appScenes({ game, saves: {}, menu: { buttons: [exitButton(shell)] } })
const app = startApp({
	target: '#game',
	game,
	scenes,
	start: sceneAsked(scenes, 'home'),
	groundWorker,
	navigationWorker,
	...shell.options
})
shell.started(app)

desktop() (src/desktop.ts) gives fileStores in the shell and nothing in a browser:

ts
const settings = fileStore<SettingsRecord>('settings')
return {
	options: {
		stores: { saves: fileStore<SavedGame>('saves'), settings },
		onGame(client) {
			playing = client
			return () => (playing = undefined)
		}
	}
}

Add Windowed and Quit to the game ​

ts
export const campaignGame = createGame(campaign).view(desktopView(campaignView))

desktopView(view) adds a Windowed setting, pause menu lines (saves folder, error log folder, Quit), and leaves out the HUD's full screen button.

Use another shell ​

Give startApp({ fullscreenHost }) any (on?: boolean) => Promise<boolean>: the menus' and HUD's full screen buttons follow it.

Reference ​

Commands (in apps/desktop, a project of this layer) ​

ToRun
see the page in a browsernpm run dev
run it as an app while developingnpm run app
open the shell on a running dev servernpm run app:editor (--port <n>, --page <address>)
the repository's dev sandbox in the shellnpm run dev:app at the root
measure without the browser's GPU guards--unsafe-gpu after either (npm run app -- --unsafe-gpu), never shipped
make the app for this systemnpm run package, into out/
open the packaged app and press Exitnode measure/packaged-check.mjs (--play: play a mission first)
macOS and Windows builds in a draft releasepush a tag desktop-v1.2.3 (.github/workflows/desktop-release.yml)

A game made without --desktop takes the layer by copying packages/create/layers/desktop (electron/, src/shell.ts, src/desktop.ts, the main, scripts and packages of its package.json, two lines of .gitignore).

src/shell.ts ​

Everything the page asks of the shell: inShell(), gameFullscreen(on), setWindowed(on), canQuit(), quit(), openFolder(folder), fileStore(folder), the error log, the autosave, checkForUpdate(). Each does nothing in a browser tab, so npm run dev alone works. It reaches the main process only through window.v12Shell (from electron/preload.cjs); the page has nothing of Node or Electron (contextIsolation, sandbox).

electron/ ​

FileWhat
config.mjsthe app's NAME, IDENTIFIER and updater address (UPDATES)
main.mjsthe main process's start
app.mjsthe window, full screen, the page's scheme and policy
preload.cjsthe bridge
files.mjssaves and settings as files, the error log
serve.mjsthe built page from the app's scheme, with its content security policy
updates.mjsElectron's autoUpdater on static files
presentation.mthe macOS addon that hides the Dock and menu bar
dev.mjs, package.mjs, tools.mjsnpm run app, npm run package
icons/icon.icns (macOS), icon.png (Windows, Linux)

Files on disk ​

fileStore writes one JSON file per record, saves/<id>.json, in the app's data folder (~/Library/Application Support/<identifier> on macOS, %APPDATA%\<identifier> on Windows), whole and renamed over the old one, so a cut-short write leaves the old record. Ids that aren't plain file names are encoded after a ~. Campaign progress and replays stay in the page's storage, which Electron keeps in the app's folder. The error log is errors.log (and errors.old.log) in the system's logs folder. The window's size and place are kept in window.json.

Closing the window (its X, Cmd+Q, Quit) saves the game as "Autosave" first (autosaveOnClose); the main process waits up to 6 s.

Full screen on macOS ​

The window is a plain one over the screen (setSimpleFullScreen) and the app's presentation options hide the Dock and menu bar (HideDock | HideMenuBar, through the addon). Esc is the game's; Cmd+Tab and Cmd+Q work; the green button makes no Space. Without the addon the bars auto-hide at the edges. Kiosk mode isn't used: it disables Force Quit. On Windows and Linux it is the window's own full screen.

What the shell allows ​

The main process answers only the app's own page, by a channel per thing (v12:fullscreen, v12:records, v12:log, v12:open-folder, v12:update-check…). Records go only to saves and settings. The page is served from app://game/ and can't navigate away or open windows. Its content security policy (contentPolicy in electron/serve.mjs) is default-src 'self', plus blob:, data:, 'wasm-unsafe-eval' and inline styles; a game that talks to a server adds it to connect-src (contentPolicy(connect)). apps/example/tests/desktop.test.ts checks the shell, bridge and main process agree.

Updates ​

Electron's autoUpdater (Squirrel) on a folder of static files at UPDATES: the page checks (checkForUpdate), Squirrel downloads, and a toast offers "Install and restart" (which saves first). Off unless built with VITE_DESKTOP_UPDATES=on.

<UPDATES>/darwin/arm64/RELEASES.json   the zipped apps (npm run package -- --zip) and a JSON feed naming the newest
<UPDATES>/darwin/x64/RELEASES.json
<UPDATES>/win32/x64/RELEASES           Squirrel.Windows' list, beside its installer's .nupkg files
json
{
	"currentRelease": "0.2.0",
	"releases": [
		{
			"version": "0.2.0",
			"updateTo": {
				"version": "0.2.0",
				"pub_date": "2026-11-01T12:00:00Z",
				"notes": "What is new",
				"name": "0.2.0",
				"url": "https://…/The Long Road-0.2.0-darwin-arm64.zip"
			}
		}
	]
}

Yours to provide: a Developer ID certificate and notarization on macOS (an ad hoc signed app never updates), a Squirrel.Windows installer from Electron Forge's maker-squirrel, an HTTPS address. Linux has no autoUpdater.

Before handing it out ​

  • Set NAME and IDENTIFIER (the identifier names the saves folder: don't change it after a release), the version in package.json, and the icons.
  • npm run package makes the app for the system it runs on (Electron's manual packaging). Installers, cross builds and signing are Electron Forge's.
  • Sign for each system: Developer ID and notarization on macOS (the addon is one more binary to sign), a code signing certificate on Windows.

The offline page ​

  • The first visit keeps every file of the build (the example: about 920 files, 60 MB). If one can't be kept, the worker isn't installed.
  • After that every build file is answered from what was kept. Anything else (a game server, the editor's files) goes to the network.
  • A new build asks only for changed files, then waits until old pages close; apply loads it now.
  • Saves, replays and settings live in the browser's storage, which works offline anyway; navigator.storage.persist() asks the browser not to clear it.

Why Electron ​

Measured on one Mac with a 120 Hz screen: Electron drew 120 fps where Tauri's WKWebView capped at 60, and with 1,200 fighters about twice the frames (81 vs 43). It costs about 110 MiB more zipped.

In the example ​

  • packages/create/layers/desktop: the layer and its tests.
  • apps/desktop: the campaign starter as a desktop app, with measure/.
  • .github/workflows/ci.yml's desktop-app packages it on macOS on every push and presses Exit.
  • apps/example: the offline page (vite.config.ts, src/main.ts).