OpenProgram Docs

Desktop window lifecycle

One process, one main window. Torn-off windows are extra and short-lived.

app.whenReady() first launch activate Dock click, even during launch second-instance click while still starting ensureMainWindow one in-flight create Main window
  1. app.whenReady, activate, second-instancelaunch, Dock click, click while starting
  2. ensureMainWindowone in-flight create
  3. Main window

createWindow is async. Until its first BrowserWindow exists, getAllWindows() is empty, so unguarded events would each create a window with id main, leaving two identical windows.

EventAction
Ready, no live mainCreate one
Any of the three, create in flightJoin it
Live main existsRestore, show, focus
Main was destroyedCreate one
Second OS processQuit; the first handles the click
Torn-off windowNot a main: own id, no persisted bounds

Code

windows.get("main")
The live main
createMainWindowGate({ windows, createWindow })
Returns ensureMainWindow, the only entry that creates or reuses it
registerSingleMainWindow({ app, BrowserWindow, ensureMainWindow, recoverErroredWindows, onReady })
Takes the single-instance lock and wires the events. onReady (IPC, menu, theme) runs once, before the first ensureMainWindow().
createWindow({ detached: true })
The tear-off path

apps/desktop/main/windows/window-lifecycle.js, apps/desktop/main.js. Harness: apps/desktop/tests/windows/check-window-lifecycle.js.

Not windows

  • The LaunchAgent ai.openprogram.worker keeps the worker on port 18100. A slow worker may flash the error page and reload, in one window.
  • Worker start, ui.open_browser and packing the .app do not create the main BrowserWindow. With the desktop shell as UI, do not open the system browser to 127.0.0.1:18100.

Window state · Moving tabs between windows

Last updated · 2026-11-25