Skip to content

Main Process API

Electrobun exposes the same native core to six main-process runtimes: Cottontail (the default), Bun, Zig, Rust, Go, and Odin. The TypeScript SDK (electrobun/main) serves Cottontail and Bun; each native language has its own SDK that loads ElectrobunCore directly. Pick your runtime once — code snippets across these docs follow your selection.

Cottontail and Bun share the TypeScript SDK today, but they are separate runtime choices (build.mainProcess: "cottontail" vs "bun") and will diverge over time — treat the tabs as distinct even where the code currently matches. See Main Process Runtimes for choosing, and the per-runtime Hello World walkthroughs for complete setup.

Your first window

// src/bun/index.ts — Cottontail executes TypeScript directly.
import { BrowserWindow, ApplicationMenu, Utils } from "electrobun/main";
const win = new BrowserWindow({
title: "My app",
url: "views://mainview/index.html",
});
ApplicationMenu.setApplicationMenu([
{ label: "File", submenu: [{ role: "quit" }] },
]);
Utils.showNotification({ title: "Application started" });
void win;

The TypeScript SDK (Cottontail and Bun)

Named imports are recommended:

import { BrowserWindow, ApplicationMenu, Utils } from "electrobun/main";

A default namespace export is also available (import Electrobun from "electrobun/main"). The package root, electrobun, currently resolves to the same main-process SDK; use electrobun/view inside browser bundles. The former electrobun/bun namespace remains a deprecated alias for electrobun/main so imports can migrate incrementally.

Runtime coverage

The TypeScript SDK has the broadest high-level surface. The native SDKs mirror the core contract procedurally (ids + callbacks instead of classes). What exists where:

API areaCottontailBunZigRustGoOdin
Windows & webviews
WGPU views (native GPU surfaces)
Application & context menus✓ typed✓ typedJSONJSONJSONJSON
Tray (create/show/title)✓ + events✓ + events✓ ¹✓ ¹✓ + clicks✓ ¹
Dialogs, message box, notifications
Clipboard, displays, shell open/reveal/trash
Sessions & cookies
Global shortcuts
Paths
Typed RPC (createRPC)raw bridge ²raw bridge ²raw bridge ²raw bridge ²
Updater
Warren UI (main/ui)
three.js / Babylon WebGPU adapters

¹ Zig, Rust, and Odin create and manage tray items, but their wrappers do not yet surface tray click events; Go’s TrayOptions.Handler does receive them. Tray menus remain TypeScript-only everywhere. ² Native SDKs exchange raw JSON messages with Electroview in the webview (the request/response envelope is implemented by hand; the templates show the full pattern). The webview-side SDK is identical for every runtime.

Pages for TypeScript-only features say so at the top; everything else shows a tab per supported runtime.