Windows

A window is an NSWindow with a WKWebView in it. You describe windows in config, or create them from the page.

From config

windows: [
	{ label: "main", url: "/", width: 900, height: 640, title: "Example" },
],

Created in array order at app.run(), before the ready event fires. label is required and is the handle every command and platform.window(label) resolves. Defaults: url "/", width 1100, height 760, no title.

With dev.url set, every window loads that URL verbatim and windows[].url is ignored.

From the page

await window.crust.invoke("window", "create", {
	label: "second",
	title: "Second",
	width: 800,
	height: 600,
});
// { ok: true, label: "second", created: true }

{ label, title?, width?, height?, url? }. An absent url means the app's own document; a relative path resolves against the document of an open window. Every bridge-served document — relative or absolute on the bridge's own origin — carries ?window=<label> with the label from the command and a seed token, so the document token is bound to that window's grants; a page-supplied window or token is replaced, not trusted. An absolute URL on a foreign origin is loaded as given without a token, and a bridge-origin URL whose path begins // is refused as invalid-url because the navigation would leave the origin. A width or height that is not a positive integer is refused, not clamped.

Commands

commandargsanswers
create{ label, title?, width?, height?, url? }{ ok: true, label, created: true }
close{ label }{ ok: true, label, closed: true }
focus{ label }{ ok: true, label, focused: true }
setTitle{ label, title }{ ok: true, label, title }
listnone{ ok: true, labels }
isOpen{ label }{ ok: true, label, open }
setSize{ label, width, height }{ ok: true, label, width, height }
getSize{ label }{ ok: true, label, width, height }
setPosition{ label, x, y }{ ok: true, label, x, y }
getPosition{ label }{ ok: true, label, x, y }
setAlwaysOnTop{ label, value }{ ok: true, label, alwaysOnTop }
isAlwaysOnTop{ label }{ ok: true, label, alwaysOnTop }
setFullscreen{ label, value }{ ok: true, label, fullscreen }
isFullscreen{ label }{ ok: true, label, fullscreen }
minimize{ label }{ ok: true, label, minimized: true }
unminimize{ label }{ ok: true, label, minimized: false }
isMinimized{ label }{ ok: true, label, minimized }
maximize{ label }{ ok: true, label, maximized: true }
isMaximized{ label }{ ok: true, label, maximized }

Success is { ok: true, … } with HTTP 200. Failure resolves with { ok: false, code, message, label? } in the body and a non-200 status mapped from code through the same table CrustError uses (invalid-label, invalid-title, invalid-size, invalid-position, invalid-value, invalid-url and duplicate-label → 400, unknown-window → 404, unknown-adapter → 501, handler-error → 500), where code is one of unknown-window, invalid-label, invalid-title, invalid-size, invalid-position, invalid-value, invalid-url, duplicate-label, unknown-adapter, handler-error. Branch on result.ok, not on a rejected promise.

Both create and setTitle refuse a title that is not a string with invalid-title, never invalid-label. A page that branches on invalid-label to repair its label will not loop on a title bug.

Size and position

await window.crust.invoke("window", "setSize", { label: "main", width: 900, height: 640 });
await window.crust.invoke("window", "setPosition", { label: "main", x: 120, y: 80 });

A label that is already open is duplicate-label: the platform map is keyed by label, and a second window would replace the first.

What "closed" means

Menu bar and shortcuts

crust installs a real NSApp.mainMenu at startup, because AppKit carries the standard shortcuts on menu items — without one, ⌘Q, ⌘C and ⌘V do nothing at all.

menuitems
app menu (the app's name)Quit, ⌘Q
EditUndo ⌘Z, Redo ⇧⌘Z, Cut ⌘X, Copy ⌘C, Paste ⌘V, Select All ⌘A

Every item targets nil, so the action goes to whatever has focus — the webview's text field included. Verified by hand in a built app: copy, paste and quit all fire, 2026-11-14. The menu bar only appears while the app is active; an unbundled crust dev process cannot activate, so click its window first.

Events

app.on("ready", () => console.log("windows open"));
app.on("window-all-closed", () => console.log("closed; quitting"));

Two events exist, and only these two. A ready listener that throws rejects app.run().

A relative URL

create with a relative url resolves it against the document of an open window. With no open window that loaded a real http(s) document there is no base, so the command answers handler-error rather than guessing an origin. An absent url needs no base: it loads the app's own document, which is the reopen case a page wants.