App-level commands
Six namespaces that belong to the app rather than to a window: app for commands the backend registered, autostart for launch at login, logging for the file sink, i18n for the language catalogue, single-instance for the lock, deep-link for the URL the app was opened with.
app
| command | arguments | answer |
|---|---|---|
invoke | { name, args? } | whatever the named command answers |
info | none | { id, name, version, execPath, packaged } |
The namespace behind a two-argument call: window.crust.invoke("greet", { name: "Ada" }) is routed by the injected shim to app.invoke with { name: "greet", args: { name: "Ada" } }. It reaches the same app singleton the backend registered on, so a command added by main.ts after the bridge started stays reachable — the handler closes over the app rather than snapshotting its table. A payload without a non-empty string name throws, which reaches the page as handler-error. Ordinary answers and typed failures pass through unchanged, but not-implemented does not: a command that returns notImplemented(message, requires) and one that throws NotImplementedError are both raised as a not-implemented rejection carrying requires, so neither can be mistaken for data. A plain thrown error gains the handler-error code. info is the page's read of app.info() — the app id, name and version from config, the executable path, and whether the process is packaged rather than an interpreter running source; it arms the same app: page events as invoke.
autostart
| command | arguments | answer |
|---|---|---|
enable | { appPath, bundleId? } | { ok: true, enabled: true, path } |
disable | { bundleId? } | { ok: true, enabled: false, path } |
isEnabled | { bundleId? } | { ok: true, enabled, path } |
Launch at login, in the form the running OS actually reads. On macOS that is a LaunchAgent at ~/Library/LaunchAgents/<bundle-id>.plist with RunAtLoad; on Linux an XDG autostart entry at $XDG_CONFIG_HOME/autostart/<bundle-id>.desktop (default ~/.config/autostart). Both are written to a sibling temp file and renamed, so the OS never reads a half-written one, and path is the file the answer is about. enable falls back to the bundle id inside the app's Info.plist, and remembers it, so disable and isEnabled need no argument after one enable. isEnabled reads the mechanism back rather than repeating what enable asked for: the plist's existence on macOS, and on Linux the entry's Type, Hidden and X-GNOME-Autostart-enabled keys.
Windows is refused with unsupported-platform, naming the registry value it would need (HKCU\Software\Microsoft\Windows\CurrentVersion\Run): crust writes no Win32 registry entry, so answering enabled: true there would be a claim nothing backs.
Failure codes: bad-request (no appPath, no bundle id known, a bundle with no CFBundleIdentifier, or an id holding a path separator), not-found (nothing at appPath), handler-error (the write, the delete or the read-back failed), unsupported-platform (this OS has no login-item mechanism here).
logging
| command | arguments | answer |
|---|---|---|
setLevel | { level } | { level, changed } |
level | none | the level in force, as a string |
configure | { file?, level? } | { ok, file?, level?, error? } |
write | { level, message } | { written, line?, path?, rotated?, reason?, error? } |
tail | { limit?, level?, source?, since? } | { records } |
Levels are trace, debug, info, warn or error; info is the default. Every record is one JSON object per line in app.jsonl under the app's data directory, with framework and plugin warn and above also appended to errors.jsonl; the live file rotates into app.1.jsonl once it reaches logging.maxBytes. tail reads the live file and answers parsed records, filtering by that level and above, one source, and a since that is an ISO timestamp or epoch milliseconds; a line that is not JSON comes back as { raw } instead of breaking the read. write records an author line with event log.write and source plugin, and reports why nothing reached the file (below-level, bad-level or sink-error) when that is what happened. rotated is set when that write moved the live file aside, naming the archive it moved to.
setLevel answers changed: false for a name that is not a level, so a caller can tell "ignored" from "applied". configure repoints the live file and sets the level in one call; its file must be absolute and stay inside the app's data root (symlinks resolved), or it answers { ok: false, error }. Nothing here throws: a bad payload answers written: false with reason: "bad-level".
i18n
| command | arguments | answer |
|---|---|---|
locale | none | { ok: true, locale } |
setLocale | { locale } | { ok: true, locale } |
messages | { locale? } | { ok: true, locale, messages } |
translate | { key, vars? } | { ok: true, locale, key, text } |
load | { directory } | { ok: true, locale, available } |
The catalogue is plain data the app supplies: locale → key → text, with {name} placeholders. translate resolves key, then key_one/key_other from vars.count, then interpolates every {name} from vars. messages answers the whole table for one locale. setLocale is in-memory on purpose — macOS keeps the language list in System Settings, so an app cannot change it, and pretending otherwise would report a language the system does not use. The answer's locale is the one the lookup actually landed on.
Failure codes: bad-request (an empty locale or key); not-implemented with requires: "NSLocale" for locale, or requires: "createI18nPlugin({ messages })" for messages and translate when no catalogue is loaded.
single-instance
| command | arguments | answer |
|---|---|---|
acquire | { id } | { acquired, pid, path } |
release | { id } | { released, path, pid? } |
activate | { pid } | { activated, status, reason } |
The lock is a file named after the id holding the owner's pid, created with O_EXCL, so the winner is whoever the filesystem says won. acquired: false is an answer, not a throw: pid is the live holder to activate. A lock naming a dead pid is stale and is taken over, so a crash never locks the user out. release refuses to drop a lock a live foreign process holds and names that pid. activate is honest about the OS: activated is true only for status 0.
The runtime already holds the app's own lock at launch, so a page rarely needs acquire. A malformed id (empty, or containing a separator) or a pid outside 1–2147483647 throws, which reaches the page as handler-error. Without an adapter, activate answers not-implemented with requires: "NSRunningApplication".
deep-link
| command | arguments | answer |
|---|---|---|
scheme | none | the registered scheme, a string |
url | none | the URL held now, or null |
url is the launch URL until a later open replaces it, so a page that reads it at startup does not show a stale one. Every open also pushes the deep-link event with { url }. scheme answers not-implemented with requires: "CFBundleURLTypes" when the build registered no scheme — build.urlScheme is what writes it into Info.plist, and without it macOS never routes a URL to the app.