Skip to content

Utils

Import utilities as the Utils namespace from the main-process SDK:

import { Utils } from "electrobun/main";

In the native SDKs (Zig, Rust, Go, Odin), the same operations are exposed directly on Core. The tabs below show the native calls where they exist.

Files and external applications

import { Utils } from "electrobun/main";
const openedUrl = Utils.openExternal("https://example.com");
const openedPath = Utils.openPath("/absolute/path/to/report.pdf");
Utils.showItemInFolder("/absolute/path/to/report.pdf");
Utils.moveToTrash("/absolute/path/to/old-report.pdf");
void openedUrl;
void openedPath;
  • openExternal(url) opens HTTP, HTTPS, mail, and custom-scheme URLs with the system handler and returns whether the request succeeded.
  • openPath(path) opens a file or directory with its default application and returns whether the request succeeded.
  • showItemInFolder(path) reveals a file in Finder, Explorer, or the Linux file manager.
  • moveToTrash(path) moves a file or directory to the system trash.

Use absolute filesystem paths for filesystem operations. views:// URLs are for webview content, not native file APIs.

File dialog

import { Utils } from "electrobun/main";
const paths = await Utils.openFileDialog({
startingFolder: "~/Documents",
allowedFileTypes: "png,jpg,jpeg",
canChooseFiles: true,
canChooseDirectory: false,
allowsMultipleSelection: true,
});
for (const path of paths) {
console.log("Selected", path);
}

openFileDialog() resolves to string[]. An empty array means the user did not select a path. Every option is optional; current defaults allow files, directories, and multiple selections. In Zig and Odin, openFileDialogPaths returns a parsed path list (release it with freeDialogPaths); Rust and Go return the raw JSON array string from open_file_dialog / OpenFileDialog. None of the native SDKs currently exposes a save dialog.

Message boxes

import { Utils } from "electrobun/main";
const { response } = await Utils.showMessageBox({
type: "question",
title: "Delete file?",
message: "This action cannot be undone.",
detail: "The file will be moved to the system trash.",
buttons: ["Delete", "Cancel"],
defaultId: 1,
cancelId: 1,
});
if (response === 0) {
console.log("Delete confirmed");
}

The response is the zero-based index of the selected button. Supported types are info, warning, error, and question.

Notifications

import { Utils } from "electrobun/main";
Utils.showNotification({
title: "Export complete",
subtitle: "Quarterly report",
body: "The PDF is ready.",
silent: false,
});

title is required. subtitle uses the platform’s closest available presentation outside macOS.

Clipboard

import { Utils } from "electrobun/main";
Utils.clipboardWriteText("Hello from Electrobun");
const text = Utils.clipboardReadText();
const png = new Uint8Array();
Utils.clipboardWriteImage(png);
const image = Utils.clipboardReadImage();
const formats = Utils.clipboardAvailableFormats();
Utils.clipboardClear();
void text;
void image;
void formats;

Image methods read and write PNG bytes. Reads return null when the requested clipboard representation is unavailable.

Dock icon

import { Utils } from "electrobun/main";
Utils.setDockIconVisible(false);
const visible = Utils.isDockIconVisible();
void visible;

Dock visibility is a macOS application concept. Unsupported platforms return their native backend’s no-op result. The native SDKs expose the same pair on Core (setDockIconVisible / isDockIconVisible in Zig and Odin, set_dock_icon_visible / is_dock_icon_visible in Rust, SetDockIconVisible / IsDockIconVisible in Go).

Paths

Utils.paths resolves standard user directories and app-scoped directories:

import { Utils } from "electrobun/main";
const {
home,
appData,
config,
cache,
temp,
logs,
documents,
downloads,
desktop,
pictures,
music,
videos,
userData,
userCache,
userLogs,
} = Utils.paths;
void home;
void appData;
void config;
void cache;
void temp;
void logs;
void documents;
void downloads;
void desktop;
void pictures;
void music;
void videos;
void userData;
void userCache;
void userLogs;

userData, userCache, and userLogs include the packaged app identifier and physical install-root name (<base>/<identifier>/<install-root>) — the same layout on every runtime. The install-root name normally matches the packaged release channel. An app updated from a supported Electrobun v1 release keeps its existing physical root; this preserves its data, browser profile, and update state in place. In a development run, malformed or missing package metadata can produce empty identifier/root path components. The native SDKs resolve the same fields through their Paths type — see the tabbed examples on the Paths page.

For installer builds, these three app-scoped locations are the only user data included by Electrobun’s App and Data uninstall action. It is limited to the current identifier and recorded physical install root; see Uninstalling for details and platform availability.

Quitting

import { Utils } from "electrobun/main";
function finishShutdown(exitCode = 0) {
Utils.quit(exitCode);
}
void finishShutdown;

quit(exitCode) emits the application before-quit event, honors a cancellation, and then performs native cleanup before exiting with the requested status. The exit code defaults to 0. Electrobun also routes process.exit() through that cleanup path while the native runtime is active.