Skip to content

Porting to the App Surface

DownDraft’s public surface was renamed from Game* to App* in a single breaking release (no compatibility aliases). This guide is the migration path: a rename map for the mechanical part, then a checklist for adopting the new desktop-app capabilities.

OldNew
GameModuleAppModule
GameContextAppContext
GameSimWorkerSimWorker
GameUiHandleUiHandle
GameSaveConfig / GameSaveSourceSaveConfig / SaveSource
startGamestartApp
bootstrapGame / BootstrapGameOptionsbootstrapApp / BootstrapAppOptions
createGameMcp / GameMcpOptionscreateAppMcp / AppMcpOptions
runNativeGameModule / RunNativeGameModuleOptionsrunNativeAppModule / RunNativeAppModuleOptions
startNativeGame / NativeGameOptionsdeleted — use runNativeAppModule or createNativeHost
app/src/main/game-module.tsapp/src/main/app-module.ts
native-game-module.tsnative-app-module.ts
src/game-module.ts (in projects)src/app-module.ts
OldNew
GameRendererAppRenderer
GameRendererLikeAppRendererLike
GameRendererConfigAppRendererConfig
GameLoop / GameLoopConfig / GameLoopStatsUpdateLoop / UpdateLoopConfig / UpdateLoopStats
GameWorldAppWorld
GameBridge (blitz-ui native)AppBridge
IGameDevToolsExtensionIAppDevToolsExtension
OldNew
BaseGameStoreState / GameStoreStateBaseAppStoreState / AppStoreState
createBaseGameStoreState / BaseGameStorecreateBaseAppStoreState / BaseAppStore
createGameSaveSystem / GameSaveSystem(Options)createSaveSystem / SaveSystem(Options)
HostAPI.saveGameState / loadGameState / deleteGameStatesaveState / loadState / deleteState
SimBridge.pauseGame / resumeGame / resetGamepauseSim / resumeSim / resetSim
hostServices.api.saveGame / loadGamesave / load
stores/game-store.ts, save/game-save-system.tsstores/app-store.ts, save/save-system.ts
OldNew
@downdraft/engine/libraries/gamepad@downdraft/engine/libraries/controller
GamepadLib / GamepadHub / GamepadSourceControllerLib / ControllerHub / ControllerSource
GamepadDevice* / GamepadSnapshotControllerDevice* / ControllerSnapshot
SabGamepadSource / SysfsGamepadEnricherSabControllerSource / SysfsControllerEnricher
GamepadDevicesChannel / Reader / HostMetaWriterControllerDevices*
SAB channel "gamepad-devices""controller-devices"
platform-native/src/gamepadplatform-native/src/controller
native-gamepad crate (downdraft_gamepad)native-controller (downdraft_controller)
__ddGamepad / DOWNDRAFT_NO_GAMEPAD__ddController / DOWNDRAFT_NO_CONTROLLER

The dd_pad_* FFI symbol names are unchanged.

OldNew
GameClient / GameInstance / GameClientOptionsAppClient / AppInstance / AppClientOptions
LaunchGameOptions / LaunchedGameLaunchAppOptions / LaunchedApp
launchGame / listGameInstances / discoverGameInstancelaunchApp / listAppInstances / discoverAppInstance
EngineContextFromGameOptionsEngineContextFromAppOptions
getGameInfo / formatGamesListgetAppInfo / formatAppsList
OldNew
--game / -g--app / -a
--games--apps
draft mcp --app <name>draft mcp --app-id <id> (the launch name took over --app)
scripts/link-games.mjsremoved — apps install @downdraft/* from npm (use bun link for unpublished engine changes)
draft new --template gamemoduledraft new --template appmodule
DD_GAME_DIRDD_APP_DIR
resolveGameDir / findGameDirUpward / isGameDir / readGameConfigresolveAppDir / findAppDirUpward / isAppDir / readAppConfig

Project dirs resolve apps/<name> → games/<name> → examples/<name>.

navigator.getGamepads, XRInputSource.gamepad, GamepadEvent, gilrs/winit type names, GameCube/GameActivity, game-domain data fields (gameOver, gameplay), and the MCP tool names (get_player_state, inject_input, …) kept their vocabulary — they’re web/platform names, not ours.

Renames get the project compiling; these adopt the new capabilities. Check apps/desktop-demo — the tracked reference app — for a working example of every row, driven end-to-end by tests/e2e/desktop-demo-smoke.spec.ts.

AppNeutral renameappId + downdraft.paths/settingsWindow model (AppWindow, close veto)setMenu + in-window fallbackTray (downdraft.tray)onSecondInstancedamageOnly renderDD_DIALOGS_MOCK in tests
anableps☐☐☐☐☐☐☐☐
salticus☐☐☐☐☐☐☐☐
cruiser☐☐☐☐☐☐☐☐
  • runNativeAppModule(module, { title, appId }) — appId (e.g. downdraft-myapp) is required for per-app storage, the singleton lock, and window-state persistence.
  • closePolicy: "lastWindow" (default) quits when the last window closes; "explicit" hides the window so tray-resident apps stay alive until downdraft.quit().
  • onCloseRequest: (win) => boolean | Promise<boolean> — return false to veto (unsaved-changes prompts). Lower level: window.setCloseIntercept(true) + a cancelable "closerequest" event.
  • AppWindow.primary() / list() / create(opts) — uniform runtime controls (setTitle, setSize, minimize, maximize, setAlwaysOnTop, setFullscreen, requestAttention, …) on the primary (handle 0) and secondary windows.

2. Menus, tray, dialogs, notifications, theme

Section titled “2. Menus, tray, dialogs, notifications, theme”
  • downdraft.setMenu(model) → "native" | "inwindow" | "unavailable". On "inwindow" (Linux/Android, or DD_MENU=inwindow) mount the kit menuBar({ model }) inside your html-ui doc — picks arrive through onMenuAction either way.
  • downdraft.tray?.create({ icon, tooltip, menu }) — Windows/macOS native, Linux via StatusNotifierItem/DBus (false when no SNI watcher). Tray picks arrive on onMenuAction as "tray:<id>" and stripped via tray.onAction. Pair with closePolicy:"explicit" for background apps.
  • downdraft.showOpenDialog / showSaveDialog / showMessageBox — real rfd dialogs; DD_DIALOGS_MOCK=1 resolves them synchronously in tests.
  • downdraft.notify({ title, body }) — desktop notifications where a backend exists.
  • downdraft.getTheme() / onThemeChanged(cb) — "light" | "dark" | "unknown".
  • With appId set, a second launch forwards {argv, cwd} to the primary over <configDir>/instance.sock (named pipe on Windows) instead of silently dying — handle file-open-on-relaunch via downdraft.onSecondInstance(({ argv, cwd }) => …). The primary raises/focuses itself by default (focusOnSecondInstance:false opts out). DOWNDRAFT_MULTI_INSTANCE=1 and deterministic mode bypass the lock.
  • downdraft.paths → { configDir, dataDir, cacheDir } (XDG split on Linux, %APPDATA%/%LOCALAPPDATA% on Windows, ~/Library on macOS).
  • downdraft.settings → typed KV persisted to <configDir>/settings.json: get<T>(key, fallback), set(key, value), watch(key, cb), flush().
  • new AppRenderer(canvas, { mode: "2d", damageOnly: true }) — skips surface acquire/submit/present on undamaged ticks and parks rAF on a keepalive (damageIdleFps, default 20Hz, 0 = full sleep). UI apps idle near zero CPU; renderer.requestFrame() and every input/damage source re-arm immediately.
  • For UI-only apps: renderer.setViewportCount(0) after construction — the html-ui panels are the whole picture.

draft test --app=<name> runs tests/e2e/<name>-smoke.spec.ts through the standard MCP harness (launchApp). The desktop-demo spec is the canonical example: menu backend, close veto, second-instance forwarding, idle pump counters, theme, settings, and DD_DIALOGS_MOCK dialogs — see tests/e2e/desktop-demo-smoke.spec.ts.