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
| command | args | answers |
|---|---|---|
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 } |
list | none | { 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 });
- Size is two positive integers, refused not clamped.
0and12.5areinvalid-size, because a silently resized window hides the bug. - The page follows the window. The webview is four edge pins on the content view with no size of its own, so a drag, a
setSizeor amaximizereaches the page. A fixed width/height pair on the webview is what made "apps can't be resized" look true: the window grew and the page stayed at its opening size. setSizeandgetSizespeak the window frame. The title bar is inside the height, so a page's own viewport is the frame less the bar — 32 pt measured on macOS.- The proof is the page's own viewport.
bun run e2e:windowresizes a real window900x640 → 1200x760 → 640x460and assertsinnerWidth/innerHeightafter each, in both directions, because a one-way constraint passes growing alone. - Position is two integers, and negative is real. A negative
xis a window on a display left of the main one, so only a non-integer isinvalid-position. ygrows upward, as AppKit's. A largeryis nearer the top of the screen.- A flag takes a real boolean.
"false"would read as on, so a string isinvalid-value;setAlwaysOnTopandsetFullscreenboth answer the state that follows. - The three toggles report the state, not "done".
minimizeanswersminimized: true,unminimizeanswersminimized: false, and each getter answers the window's own answer. - A getter answers
falserather than guessing. The adapter's optional member is compared with=== true, so a platform without it readsfalse. - A member the adapter lacks is
unknown-adapter, naming the member and the command, never a silent no-op.
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
- Liveness is visible, miniaturised, or the app hidden. A minimised window is still open.
-windowNumberkeeps its value after-close, so it is never the test. - A closed label leaves
list, answersunknown-windowfor every other command, andisOpenon it answersunknown-windowrather thanopen: false. - A closed label can be created again.
createreleases the stale native entry first, so reuse works; a live label is refused before anything is touched. - Closing the last window ends the app only when a
window-all-closedlistener exists — the check runs on a 250 ms poll and callsquit()after the listeners. With no listener the app keeps running with no window.
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.
| menu | items |
|---|---|
| app menu (the app's name) | Quit, ⌘Q |
| Edit | Undo ⌘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.