### Install Dependencies and Start Development Source: https://github.com/blackboardsh/electrobun/blob/main/docs/src/content/docs/electrobun/guides/quick-start.mdx Navigate to your project directory, install dependencies using Bun, and start the development server. ```bash cd my-app bun install bun start ``` -------------------------------- ### Clone and Setup Repository Source: https://github.com/blackboardsh/electrobun/blob/main/README.md Initial steps to clone the repository with submodules and install dependencies. ```bash git clone --recurse-submodules https://github.com/blackboardsh/electrobun.git cd electrobun/package bun install bun dev:clean ``` -------------------------------- ### Install and Run Development Mode Source: https://github.com/blackboardsh/electrobun/blob/main/templates/go-maze-wgpu/README.md Commands to install dependencies and start the development server for the Electrobun project. ```bash bun install bun dev ``` -------------------------------- ### Install Dependencies and Run Commands Source: https://github.com/blackboardsh/electrobun/blob/main/templates/svelte/README.md Use these commands to install dependencies and run the development server or build the production application. ```bash bun install ``` ```bash bun run dev ``` ```bash bun run dev:hmr ``` ```bash bun run build ``` ```bash bun run build:prod ``` -------------------------------- ### Install dependencies Source: https://github.com/blackboardsh/electrobun/blob/main/templates/hello-world/README.md Run this command to install the necessary project dependencies. ```bash bun install ``` -------------------------------- ### Open File Dialog Source: https://github.com/blackboardsh/electrobun/blob/main/docs/src/content/docs/electrobun/apis/utils.mdx Initiate a file selection dialog for the user. This example demonstrates setting a starting folder, file types, and allowing multiple selections. Ensure `join` and `homedir` are imported. ```javascript // To simplify this example we'll just show a dialogue after a 2 second timeout setTimeout(async () => { const chosenPaths = await Utils.openFileDialog({ startingFolder: join(homedir(), "Desktop"), allowedFileTypes: "*", // allowedFileTypes: "png,jpg", canChooseFiles: true, canChooseDirectory: false, allowsMultipleSelection: true, }); console.log("chosen paths", chosenPaths); }, 2000); ``` -------------------------------- ### Electrobun Full Build Configuration Example Source: https://github.com/blackboardsh/electrobun/blob/main/docs/src/content/docs/electrobun/apis/cli/build-configuration.mdx A comprehensive example of an electrobun.config.ts file demonstrating various configuration options for app metadata, build settings, asset copying, and platform-specific configurations. ```javascript // electrobun.config.ts import type { ElectrobunConfig } from "electrobun"; export default { app: { name: "Electrobun (Playground)", identifier: "dev.electrobun.playground", version: "0.0.1", }, build: { bun: { entrypoint: "src/bun/index.ts", }, views: { mainview: { entrypoint: "src/mainview/index.ts", }, myextension: { entrypoint: "src/myextension/preload.ts", }, webviewtag: { entrypoint: "src/webviewtag/index.ts", }, }, copy: { "src/mainview/index.html": "views/mainview/index.html", "src/mainview/index.css": "views/mainview/index.css", "src/webviewtag/index.html": "views/webviewtag/index.html", "src/webviewtag/electrobun.png": "views/webviewtag/electrobun.png", "assets/electrobun-logo-32-template.png": "views/assets/electrobun-logo-32-template.png", }, mac: { codesign: true, notarize: true, bundleCEF: true, defaultRenderer: 'cef', entitlements: { "com.apple.security.device.camera": "This app needs camera access for video features", "com.apple.security.device.microphone": "This app needs microphone access for audio features", }, icons: "App.icon", // or "icon.iconset" }, linux: { bundleCEF: true, defaultRenderer: 'cef', }, win: { bundleCEF: true, defaultRenderer: 'cef', }, }, scripts: { postBuild: "./buildScript.ts", }, release: { baseUrl: "https://static.electrobun.dev/playground/", }, } satisfies ElectrobunConfig; ``` -------------------------------- ### RPC Communication Examples Source: https://github.com/blackboardsh/electrobun/blob/main/docs/src/content/docs/electrobun/apis/browser/electroview-class.mdx Examples demonstrating how to make requests to the main Bun process and send messages to it using the established RPC channel. ```APIDOC ## RPC Communication ### Description Interact with the main Bun process from the browser using the typed RPC interface provided by the `Electroview` instance. ### Methods #### Requesting data from Bun Initiate a request to a function defined in the main Bun process and handle the response. - **`electroview.rpc.request.someBunFunction({ a: number, b: number })`**: Calls the `someBunFunction` in the main process with provided parameters and returns a Promise resolving with the response. ### Sending messages to Bun Send messages to the main Bun process without expecting a direct response. - **`electroview.rpc.send.logToBun({ msg: string })`**: Sends a `logToBun` message to the main process with the specified string message. ### Request Example ```javascript // Requesting a result from a Bun function electroview.rpc.request.someBunFunction({ a: 9, b: 8 }).then((result) => { console.log("result: ", result); }); // Sending a message to a Bun function electroview.rpc.send.logToBun({ msg: "hi from browser" }); ``` ``` -------------------------------- ### Initialize New Electrobun Project Source: https://github.com/blackboardsh/electrobun/blob/main/docs/src/content/docs/electrobun/guides/quick-start.mdx Use this command to create a new Electrobun project with a chosen template. Ensure you have Bun installed. ```bash bunx electrobun init ``` -------------------------------- ### Install Electrobun Beta Versions Source: https://github.com/blackboardsh/electrobun/blob/main/BETA_RELEASE.md Use these npm commands to install the latest beta, a specific beta version, or view available versions. ```bash # Install latest beta npm install electrobun@beta ``` ```bash # Install specific beta version npm install electrobun@0.0.19-beta.1 ``` ```bash # View available versions npm view electrobun versions --json ``` -------------------------------- ### Install, Develop, and Build Electrobun App Source: https://github.com/blackboardsh/electrobun/blob/main/templates/multitab-browser/README.md Commands to manage dependencies, run the application in development, and build it for production. ```bash # Install dependencies bun install # Run in development mode bun run dev # Build for production bun run build ``` -------------------------------- ### Install indicator support for Unity Source: https://github.com/blackboardsh/electrobun/blob/main/package/src/sdks/bun/proc/linux.md Required package installation for system tray functionality on Unity desktop environments. ```bash # Install indicator support sudo apt install indicator-application ``` -------------------------------- ### Example with ASAR Configuration and Unpack Glob Patterns Source: https://github.com/blackboardsh/electrobun/blob/main/docs/src/content/docs/electrobun/apis/cli/build-configuration.mdx An example Electrobun configuration enabling ASAR packaging and specifying common file types and large data files to be unpacked. ```typescript import type { ElectrobunConfig } from "electrobun"; export default { app: { name: "MyApp", identifier: "com.example.myapp", version: "1.0.0", }, build: { useAsar: true, asarUnpack: [ "*.node", // Native modules "*.dll", // Windows DLLs "*.dylib", // macOS dynamic libraries "*.so", // Linux shared objects "data/large/**/*", // Large data files ], bun: { entrypoint: "src/bun/index.ts", }, }, } satisfies ElectrobunConfig; ``` -------------------------------- ### Constructing Download URLs Source: https://github.com/blackboardsh/electrobun/blob/main/docs/src/content/docs/electrobun/guides/bundling-and-distribution.mdx Examples of how to construct full download URLs by combining a base URL with artifact filenames for various platforms and architectures. ```shell # Examples (assuming baseUrl is "https://releases.example.com/myapp"): # macOS ARM (Apple Silicon) https://releases.example.com/myapp/canary-macos-arm64-MyCoolApp-canary.dmg # macOS Intel https://releases.example.com/myapp/canary-macos-x64-MyCoolApp-canary.dmg # Windows https://releases.example.com/myapp/canary-win-x64-MyCoolApp-Setup-canary.zip # Linux x64 https://releases.example.com/myapp/canary-linux-x64-MyCoolAppSetup-canary.tar.gz # Linux ARM https://releases.example.com/myapp/canary-linux-arm64-MyCoolAppSetup-canary.tar.gz ``` -------------------------------- ### Run in development mode Source: https://github.com/blackboardsh/electrobun/blob/main/templates/hello-world/README.md Starts the application in development mode for testing and debugging. ```bash bun run dev ``` -------------------------------- ### Store App Data Example Source: https://github.com/blackboardsh/electrobun/blob/main/docs/src/content/docs/electrobun/apis/utils.mdx Demonstrates how to create a directory for user data and write/read a settings file using Electrobun's utility paths and Node.js file system modules. ```javascript import { Utils } from "electrobun/bun"; import { join } from "path"; import { mkdirSync, writeFileSync, readFileSync } from "fs"; // Ensure the directory exists mkdirSync(Utils.paths.userData, { recursive: true }); // Write a settings file const settingsPath = join(Utils.paths.userData, "settings.json"); writeFileSync(settingsPath, JSON.stringify({ theme: "dark" })); // Read it back const settings = JSON.parse(readFileSync(settingsPath, "utf-8")); ``` -------------------------------- ### Install System Dependencies on Ubuntu/Debian Source: https://github.com/blackboardsh/electrobun/blob/main/README.md Required packages for building Electrobun on Linux distributions. ```bash sudo apt install build-essential cmake pkg-config libgtk-3-dev libwebkit2gtk-4.1-dev libayatana-appindicator3-dev librsvg2-dev ``` -------------------------------- ### Install Dependencies and Run Scripts Source: https://github.com/blackboardsh/electrobun/blob/main/templates/react-tailwind-vite/README.md Use these commands to install project dependencies and run development or build scripts. `bun run dev:hmr` is recommended for development due to its hot module replacement feature. ```bash bun install bun run dev bun run dev:hmr bun run build bun run build:prod ``` -------------------------------- ### Add Build and Start Scripts to package.json Source: https://github.com/blackboardsh/electrobun/blob/main/docs/src/content/docs/electrobun/guides/hello-world.mdx Add 'start' and 'dev' scripts to your package.json to build and run your Electrobun application. These scripts utilize the electrobun CLI. ```javascript { "name": "my-app", "devDependencies": { "@types/bun": "latest" }, "peerDependencies": { "typescript": "^5.0.0" }, "dependencies": { "electrobun": "^0.0.1" }, "scripts": { "start": "electrobun dev", "dev": "electrobun dev --watch" } } ``` -------------------------------- ### Save Downloads Example Source: https://github.com/blackboardsh/electrobun/blob/main/docs/src/content/docs/electrobun/apis/utils.mdx Shows how to construct a path for saving downloaded files within the user's designated downloads folder using Electrobun's utility paths. ```javascript import { Utils } from "electrobun/bun"; import { join } from "path"; const savePath = join(Utils.paths.downloads, "report.pdf"); await Bun.write(savePath, pdfData); ``` -------------------------------- ### Create Tray-Only App (macOS) Source: https://github.com/blackboardsh/electrobun/blob/main/docs/src/content/docs/electrobun/apis/utils.mdx This example demonstrates setting up a tray-only application on macOS by hiding the Dock icon and creating a system tray icon. It requires importing `Utils` and `Tray` from `electrobun/bun`. ```javascript import { Utils, Tray } from "electrobun/bun"; // Hide from dock - this is a tray-only app Utils.setDockIconVisible(false); // Create a tray icon instead const tray = new Tray({ title: "My App", image: "views://assets/icon-template.png", template: true, width: 22, height: 22, }); ``` -------------------------------- ### Register Global Shortcut to Toggle App Visibility Source: https://github.com/blackboardsh/electrobun/blob/main/docs/src/content/docs/electrobun/apis/utils.mdx Example of registering a global shortcut to toggle the visibility of the main application window. Ensure the 'electrobun/bun' module is imported. ```javascript import { GlobalShortcut, BrowserWindow } from "electrobun/bun"; // Register a shortcut to show/hide the main window GlobalShortcut.register("CommandOrControl+Shift+H", () => { const win = BrowserWindow.getById(1); if (win) { // Toggle visibility if (win.isVisible()) { win.hide(); } else { win.show(); } } }); ``` -------------------------------- ### Install Electrobun CLI Source: https://github.com/blackboardsh/electrobun/blob/main/docs/src/content/docs/electrobun/apis/cli/cli-args.mdx Installs the Electrobun CLI tool into your project's node_modules/bin folder. This makes the `electrobun` command available for use in npm scripts or via package runners like `bunx` or `npx`. ```bash bun install electrobun ``` -------------------------------- ### Access BuildConfig Properties Source: https://github.com/blackboardsh/electrobun/blob/main/docs/src/content/docs/electrobun/apis/build-config.mdx Retrieve and log various properties of the build configuration, such as the default renderer and available renderers. This example demonstrates how to check for specific renderer availability. ```javascript import { BuildConfig } from "electrobun/bun"; const config = await BuildConfig.get(); console.log("Default renderer:", config.defaultRenderer); // Output: "cef" or "native" console.log("Available renderers:", config.availableRenderers); // Output: ["native", "cef"] or ["native"] // Check if CEF is available if (config.availableRenderers.includes('cef')) { console.log("CEF is bundled with this app"); } ``` -------------------------------- ### Get Window Position Source: https://github.com/blackboardsh/electrobun/blob/main/docs/src/content/docs/electrobun/apis/browser-window.mdx Get the current position of the window using `getPosition()`. It returns an object with `x` and `y` properties. Example shows checking if the window is at the origin. ```javascript // Get current window position const pos = win.getPosition(); console.log(`Window is at (${pos.x}, ${pos.y})`); // Check if window is at origin const { x, y } = win.getPosition(); if (x === 0 && y === 0) { console.log("Window is at origin"); } ``` -------------------------------- ### Complete Electrobun Build Configuration Example Source: https://github.com/blackboardsh/electrobun/blob/main/docs/src/content/docs/electrobun/apis/build-config.mdx Loads and logs the build configuration at application startup using `BuildConfig.get()`. It then creates windows, utilizing the default renderer, and conditionally creates a CEF window if CEF is available. ```javascript import Electrobun, { BrowserWindow, BuildConfig } from "electrobun/bun"; // Load and log build configuration at startup const buildConfig = await BuildConfig.get(); console.log("Build Configuration:"); console.log(" Default Renderer:", buildConfig.defaultRenderer); console.log(" Available Renderers:", buildConfig.availableRenderers.join(", ")); // Create windows - they'll use the configured default renderer const mainWindow = new BrowserWindow({ title: "My App", url: "views://main/index.html", }); // If you need CEF-specific features, check availability first if (buildConfig.availableRenderers.includes('cef')) { const cefWindow = new BrowserWindow({ title: "CEF Window", url: "views://special/index.html", renderer: 'cef', }); } ``` -------------------------------- ### Get Local Update Information Source: https://github.com/blackboardsh/electrobun/blob/main/docs/src/content/docs/electrobun/apis/updater.mdx Retrieve information about the currently installed version of the app. This data is read from the bundled version.json file. ```yaml const localInfo = await Electrobun.Updater.getLocalInfo(); localInfo: { version: string; hash: string; baseUrl: string; channel: string; name: string; identifier: string; }; ``` -------------------------------- ### Application Menu Setup Source: https://github.com/blackboardsh/electrobun/blob/main/docs/src/content/docs/electrobun/guides/creating-ui.mdx This TypeScript code defines and sets the application's main menu, including standard edit functions like cut, copy, paste, and select all, enabling keyboard shortcuts. ```typescript import { BrowserWindow, ApplicationMenu } from "electrobun/bun"; ApplicationMenu.setApplicationMenu([ { submenu: [{ label: "Quit", role: "quit" }], }, { label: "Edit", submenu: [ { role: "undo" }, { role: "redo" }, { type: "separator" }, { label: "Custom Menu Item 🚀", action: "custom-action-1", tooltip: "I'm a tooltip", }, { label: "Custom menu disabled", enabled: false, action: "custom-action-2", }, { type: "separator" }, { role: "cut" }, { role: "copy" }, { role: "paste" }, { role: "pasteAndMatchStyle" }, { role: "delete" }, { role: "selectAll" }, ], }, ]); const win = new BrowserWindow({ title: "Hello Electrobun", url: "views://main-ui/index.html", }); ``` -------------------------------- ### Bun-side WGPU Context Configuration and Resizing Source: https://github.com/blackboardsh/electrobun/blob/main/docs/src/content/docs/electrobun/apis/browser/electrobun-wgpu-tag.mdx This example illustrates the Bun-side logic for handling WGPU surface configuration, particularly reconfiguring the context when the window or view resizes. It ensures that size-dependent resources are updated correctly. ```javascript // Bun-side render loop example const ctx = webgpu.createContext(win); let size = win.getSize(); function resizeIfNeeded() { const next = win.getSize(); if (next.width !== size.width || next.height !== size.height) { size = next; ctx.configure({ device, format: webgpu.navigator.getPreferredCanvasFormat(), alphaMode: "premultiplied", size: [size.width, size.height], }); } } ``` -------------------------------- ### macOS Artifact Naming Conventions Source: https://github.com/blackboardsh/electrobun/blob/main/docs/src/content/docs/electrobun/guides/bundling-and-distribution.mdx Examples of artifact filenames for macOS, including version metadata, installers, app bundles, and patch files for canary and stable releases. ```shell # Canary: canary-macos-arm64-update.json # Version metadata for the Updater API canary-macos-arm64-MyCoolApp-canary.dmg # Installer DMG for first-time installs canary-macos-arm64-MyCoolApp-canary.app.tar.zst # Compressed app bundle for updates canary-macos-arm64-a1b2c3d4.patch # Incremental patch from previous version # Stable (no channel suffix): stable-macos-arm64-MyCoolApp.dmg stable-macos-arm64-MyCoolApp.app.tar.zst ``` -------------------------------- ### Get Window Size Source: https://github.com/blackboardsh/electrobun/blob/main/docs/src/content/docs/electrobun/apis/browser-window.mdx Retrieve the current size of the window using `getSize()`. It returns an object with `width` and `height` properties. Example shows calculating the aspect ratio. ```javascript // Get current window size const size = win.getSize(); console.log(`Window is ${size.width}x${size.height}`); // Check aspect ratio const { width, height } = win.getSize(); const aspectRatio = width / height; console.log(`Aspect ratio: ${aspectRatio.toFixed(2)}`); ``` -------------------------------- ### Linux Artifact Naming Conventions Source: https://github.com/blackboardsh/electrobun/blob/main/docs/src/content/docs/electrobun/guides/bundling-and-distribution.mdx Examples of artifact filenames for Linux, including version metadata, installers, compressed app bundles, and patch files for canary and stable releases. ```shell # Canary: canary-linux-x64-update.json # Version metadata canary-linux-x64-MyCoolAppSetup-canary.tar.gz # tar.gz containing the self-extracting setup canary-linux-x64-MyCoolApp-canary.tar.zst # Compressed app for updates canary-linux-x64-a1b2c3d4.patch # Incremental patch # Stable: stable-linux-x64-MyCoolAppSetup.tar.gz stable-linux-x64-MyCoolApp.tar.zst ``` -------------------------------- ### Windows Artifact Naming Conventions Source: https://github.com/blackboardsh/electrobun/blob/main/docs/src/content/docs/electrobun/guides/bundling-and-distribution.mdx Examples of artifact filenames for Windows, including version metadata, installers, compressed app bundles, and patch files for canary and stable releases. ```shell # Canary: canary-win-x64-update.json # Version metadata canary-win-x64-MyCoolApp-Setup-canary.zip # Zip containing the Setup .exe installer canary-win-x64-MyCoolApp-canary.tar.zst # Compressed app for updates canary-win-x64-a1b2c3d4.patch # Incremental patch # Stable: stable-win-x64-MyCoolApp-Setup.zip stable-win-x64-MyCoolApp.tar.zst ``` -------------------------------- ### Initialize Electrobun Project Source: https://github.com/blackboardsh/electrobun/blob/main/docs/src/content/docs/electrobun/apis/cli/cli-args.mdx Initializes a new Electrobun project. You can either select a template interactively or specify a template name directly. Use `bunx` to execute the command. ```bash bunx electrobun init ``` ```bash bunx electrobun init photo-booth ``` ```bash bunx electrobun init multitab-browser ``` -------------------------------- ### Initialize Native Templates Source: https://github.com/blackboardsh/electrobun/blob/main/docs/src/content/docs/electrobun/guides/native-main-process.mdx Use the CLI to scaffold new projects with pre-configured native language templates. ```bash bunx electrobun init --template=zig-wgpu bunx electrobun init --template=rust-flock-wgpu bunx electrobun init --template=go-maze-wgpu bunx electrobun init --template=odin-particles-wgpu ``` -------------------------------- ### Electrobun Build Configuration Example Source: https://github.com/blackboardsh/electrobun/blob/main/docs/src/content/docs/electrobun/apis/cli/build-configuration.mdx Configure the application name, identifier, version, build entry point, and watch settings. Use `watch` to include additional directories and `watchIgnore` to exclude specific files or patterns from triggering rebuilds. ```typescript // electrobun.config.ts import type { ElectrobunConfig } from "electrobun"; export default { app: { name: "MyApp", identifier: "com.example.myapp", version: "1.0.0", }, build: { bun: { entrypoint: "src/bun/index.ts", }, // Watch additional directories for changes watch: [ "scripts", // postBuild scripts that compile extra assets "vendor/my-native-lib", // native code compiled by a hook ], // Don't trigger rebuilds for these files watchIgnore: [ "assets/licenses.html", // generated during build "**/*.generated.*", // any generated files "data/cache/**", // cache directory ], }, scripts: { postBuild: "./scripts/compile-extras.ts", }, } satisfies ElectrobunConfig; ``` -------------------------------- ### Build for Production Source: https://github.com/blackboardsh/electrobun/blob/main/templates/photo-booth/README.md Execute this command to bundle the application for production deployment. ```bash bun build ``` -------------------------------- ### Check Clipboard Contents Example Source: https://github.com/blackboardsh/electrobun/blob/main/docs/src/content/docs/electrobun/apis/utils.mdx This example shows how to check for specific data formats (text and image) in the clipboard using `Utils.clipboardAvailableFormats()` before attempting to read them. ```javascript const formats = Utils.clipboardAvailableFormats(); if (formats.includes("text")) { const text = Utils.clipboardReadText(); console.log("Text:", text); } if (formats.includes("image")) { const imageData = Utils.clipboardReadImage(); console.log("Image size:", imageData?.length, "bytes"); } ``` -------------------------------- ### Initialize Electrobun Project Source: https://github.com/blackboardsh/electrobun/blob/main/README.md Commands to add Electrobun to an existing project or initialize a new one from a template. ```bash npm add electrobun ``` ```bash npx electrobun init ``` -------------------------------- ### Get Available Clipboard Formats Source: https://github.com/blackboardsh/electrobun/blob/main/docs/src/content/docs/electrobun/apis/utils.mdx Call `Utils.clipboardAvailableFormats()` to get an array of strings representing the data types currently available in the clipboard (e.g., 'text', 'image', 'files', 'html'). ```javascript const formats = Utils.clipboardAvailableFormats(); console.log("Clipboard contains:", formats); // Possible values: ["text", "image", "files", "html"] ``` -------------------------------- ### Create Hello World Window Source: https://github.com/blackboardsh/electrobun/blob/main/docs/src/content/docs/electrobun/guides/hello-world.mdx Create the main entry point for your Electrobun application. This code defines a new browser window with a title and a URL to load. ```typescript import { BrowserWindow } from "electrobun/bun"; const win = new BrowserWindow({ title: "Hello Electrobun", url: "https://electrobun.dev", }); ``` -------------------------------- ### Get Cached BuildConfig Synchronously Source: https://github.com/blackboardsh/electrobun/blob/main/docs/src/content/docs/electrobun/apis/build-config.mdx Access the build configuration synchronously using `getCached()`. This method returns the configuration if it has already been loaded by `get()`, otherwise it returns `null`. It's useful for accessing configuration after it's guaranteed to be loaded. ```javascript import { BuildConfig } from "electrobun/bun"; // First, load the config (usually done at app startup) await BuildConfig.get(); // Later, access it synchronously const cached = BuildConfig.getCached(); if (cached) { console.log("Using renderer:", cached.defaultRenderer); } ``` -------------------------------- ### Execute Build and Development Commands Source: https://github.com/blackboardsh/electrobun/blob/main/BUILD.md Standard commands for building and developing Electrobun applications from the package directory. ```bash cd electrobun/package # Full build with all platforms bun build.ts # Development build with the kitchen sink test app bun dev # Release build bun build.ts --release # CI build bun build.ts --ci ``` -------------------------------- ### getPosition() Source: https://github.com/blackboardsh/electrobun/blob/main/docs/src/content/docs/electrobun/apis/browser-window.mdx Get the current position of the window. Returns an object with `x` and `y` properties. ```APIDOC ## getPosition() ### Description Get the current position of the window. Returns an object with `x` and `y` properties. ### Returns - **object**: An object containing the window's position. - **x** (number) - The x-coordinate of the window's top-left corner. - **y** (number) - The y-coordinate of the window's top-left corner. ### Usage Examples ```javascript // Get current window position const pos = win.getPosition(); console.log(`Window is at (${pos.x}, ${pos.y})`); // Check if window is at origin const { x, y } = win.getPosition(); if (x === 0 && y === 0) { console.log("Window is at origin"); } ``` ``` -------------------------------- ### BrowserWindow Creation with Default Renderer Source: https://github.com/blackboardsh/electrobun/blob/main/docs/src/content/docs/electrobun/apis/cli/build-configuration.mdx Demonstrates creating a `BrowserWindow` that uses the default configured renderer (CEF in this case). Also shows how to explicitly override the default to use the native renderer for a specific window. ```javascript // Uses CEF (the configured default) const mainWindow = new BrowserWindow({ title: "My App", url: "views://main/index.html", }); // Explicitly use native renderer for this specific window const settingsWindow = new BrowserWindow({ title: "Settings", url: "views://settings/index.html", renderer: 'native', // Override the default }); ``` -------------------------------- ### Run Electrobun Application Source: https://github.com/blackboardsh/electrobun/blob/main/docs/src/content/docs/electrobun/apis/cli/cli-args.mdx Launches a previously built development bundle without rebuilding. This is useful for quickly relaunching the app after a build. ```bash electrobun run ``` -------------------------------- ### getSize() Source: https://github.com/blackboardsh/electrobun/blob/main/docs/src/content/docs/electrobun/apis/browser-window.mdx Get the current size of the window. Returns an object with `width` and `height` properties. ```APIDOC ## getSize() ### Description Get the current size of the window. Returns an object with `width` and `height` properties. ### Returns - **object**: An object containing the window's size. - **width** (number) - The current width of the window in pixels. - **height** (number) - The current height of the window in pixels. ### Usage Examples ```javascript // Get current window size const size = win.getSize(); console.log(`Window is ${size.width}x${size.height}`); // Check aspect ratio const { width, height } = win.getSize(); const aspectRatio = width / height; console.log(`Aspect ratio: ${aspectRatio.toFixed(2)}`); ``` ``` -------------------------------- ### Create a GPU Window and WebGPU Context Source: https://github.com/blackboardsh/electrobun/blob/main/docs/src/content/docs/electrobun/apis/webgpu.mdx Instantiate a GpuWindow and create a WebGPU context for rendering. Request a compatible adapter and device, then configure the context. ```javascript import { GpuWindow, webgpu } from "electrobun/bun"; const win = new GpuWindow({ title: "WebGPU", frame: { width: 800, height: 600, x: 200, y: 120 }, }); // Create a WebGPU context bound to this window. const ctx = webgpu.createContext(win); const adapter = await webgpu.navigator.requestAdapter({ compatibleSurface: ctx, }); const device = await adapter.requestDevice(); ctx.configure({ device, format: webgpu.navigator.getPreferredCanvasFormat(), alphaMode: "premultiplied", }); ``` -------------------------------- ### did-commit-navigation Event Source: https://github.com/blackboardsh/electrobun/blob/main/docs/src/content/docs/electrobun/apis/browser-view.mdx Fired when the webview begins receiving content for the main frame after a navigation has started. ```APIDOC ## did-commit-navigation Event ### Description The webview has started to receive content for the main frame after a navigation. ### Event Data - **detail** (string) - The URL that is being committed. ### Example ```javascript webview.on("did-commit-navigation", (e) => { console.log("Navigation committed for:", e.detail); }); ``` ``` -------------------------------- ### Get Current Cursor Screen Position Source: https://github.com/blackboardsh/electrobun/blob/main/docs/src/content/docs/electrobun/apis/utils.mdx Retrieve and log the current coordinates of the mouse cursor on the screen. ```javascript const cursor = Screen.getCursorScreenPoint(); console.log(`Cursor at: (${cursor.x}, ${cursor.y})`); ``` -------------------------------- ### Run Electrobun in Canary Mode Source: https://github.com/blackboardsh/electrobun/blob/main/CLAUDE.md Use this command from the package folder to build the kitchen app in canary mode. This is an alternative to the standard dev mode. ```bash bun dev:canary ``` -------------------------------- ### BrowserView Constructor Source: https://github.com/blackboardsh/electrobun/blob/main/docs/src/content/docs/electrobun/apis/browser-view.mdx Demonstrates the creation of a BrowserView with various configuration options including frame, url, html, partition, and preload scripts. ```APIDOC ## new BrowserView(options) ### Description Creates a new BrowserView instance. BrowserViews can be controlled directly or are automatically created by `BrowserWindow` and `WebviewTag`. ### Parameters #### Constructor Options - **url** (string) - Optional - Set the initial url for the BrowserView to navigate to when it opens. Can use any valid URL or the `views://` scheme for local content. - **html** (string) - Optional - Set an HTML string for the BrowserView to load. Use this instead of `url`. - **frame** (object) - Optional - Set the Webview's dimensions relative to the window. - **width** (number) - The width of the frame. - **height** (number) - The height of the frame. - **x** (number) - The x-coordinate of the frame. - **y** (number) - The y-coordinate of the frame. - **partition** (string) - Optional - Separates browser sessions (cookies, etc.). Prefix with `persist:` for persistent sessions. - **preload** (string) - Optional - Set a preload script to run after HTML is parsed but before other JavaScript executes. Can be a URL, `views://` scheme, or inline JavaScript. ### Request Example ```javascript // Example with URL and frame const webviewWithUrl = new BrowserView({ url: "https://electrobun.dev", frame: { width: 1800, height: 600, x: 2000, y: 2000, }, }); // Example with HTML and partition const htmlString = "
This is the text that will appear in your system tray
### imageThis is an optional url to an image to load. You can use the `views://` schema to access local bundled images.
### templateYou can use a full-color image like a png but that image will just be shown as is. On MacOS you can create a template image and set the `template` property to true. A template image uses opacity to define a black and white image that adapts to your systems light/dark mode.
### width and heightSet the dimensions of the image used in the system tray
``` -------------------------------- ### Copy and Paste Text Example Source: https://github.com/blackboardsh/electrobun/blob/main/docs/src/content/docs/electrobun/apis/utils.mdx Demonstrates a basic copy-paste workflow using `Utils.clipboardWriteText()` to copy text and `Utils.clipboardReadText()` to retrieve it. ```javascript // Copy text to clipboard Utils.clipboardWriteText("Hello World"); // Later, read it back const text = Utils.clipboardReadText(); console.log(text); // "Hello World" ``` -------------------------------- ### Configure Bundled Assets in `electrobun.config` Source: https://github.com/blackboardsh/electrobun/blob/main/docs/src/content/docs/electrobun/apis/bundled-assets.mdx Configure the `electrobun.config` file to bundle static assets using the `views://` schema. The `views` section defines entry points, and the `copy` section specifies assets to be included in the build output. ```javascript build: { views: { mainview: { entrypoint: "src/mainview/index.ts", // All Bun.build() options are supported here, e.g.: // plugins: [myPlugin()], // sourcemap: "linked", // minify: true, }, }, copy: { "src/mainview/index.html": "views/mainview/index.html", "src/mainview/style.css": "views/mainview/style.css", "src/mainview/script.js": "views/mainview/script.js", }, } ``` -------------------------------- ### Get Tray Icon Bounds Source: https://github.com/blackboardsh/electrobun/blob/main/docs/src/content/docs/electrobun/apis/tray.mdx Retrieves the position and dimensions of the tray icon. Returns an object with x, y, width, and height. ```javascript const bounds = tray.getBounds(); console.log(`Tray icon at (${bounds.x}, ${bounds.y}) size ${bounds.width}x${bounds.height}`); ``` -------------------------------- ### Run Built Application Source: https://github.com/blackboardsh/electrobun/blob/main/templates/photo-booth/README.md Use this command to launch the application after it has been built for production. ```bash bun start ``` -------------------------------- ### Run Electrobun in Dev Mode Source: https://github.com/blackboardsh/electrobun/blob/main/CLAUDE.md Use this command from the package folder to build and run the kitchen app in development mode. Ensure you are in the correct directory before executing. ```bash bun dev ``` -------------------------------- ### setPageZoom / getPageZoom Source: https://github.com/blackboardsh/electrobun/blob/main/docs/src/content/docs/electrobun/apis/browser-window.mdx Control and get the page zoom level for the window's webview. A value of `1.0` represents 100% zoom. ```APIDOC ## setPageZoom ### Description Sets the zoom level for the window's webview. ### Method Signature `win.setPageZoom(level: number): void` ### Parameters * **level** (number) - Required - The zoom level. `1.0` is 100%. ### Example ```javascript // Set zoom to 150% win.setPageZoom(1.5); // Reset to default zoom win.setPageZoom(1.0); ``` ## getPageZoom ### Description Gets the current page zoom level for the window's webview. ### Method Signature `win.getPageZoom(): number` ### Returns * `number` - The current zoom level. `1.0` represents 100%. ### Example ```javascript const zoom = win.getPageZoom(); console.log(`Current zoom: ${zoom * 100}%`); ``` ### Notes Page zoom is fully supported on macOS. On Windows and Linux, these methods are available but are no-ops; `getPageZoom()` will always return `1.0`. ``` -------------------------------- ### Verify Environment Variable Setup Source: https://github.com/blackboardsh/electrobun/blob/main/docs/src/content/docs/electrobun/guides/code-signing.mdx Use this command to confirm that your environment variables, specifically ELECTROBUN_TEAMID, are correctly set in your terminal session. ```bash echo $ELECTROBUN_TEAMID ``` -------------------------------- ### BrowserWindow Constructor with RPC Source: https://github.com/blackboardsh/electrobun/blob/main/docs/src/content/docs/electrobun/apis/browser-window.mdx Illustrates setting up Remote Procedure Calls (RPC) for a BrowserWindow, enabling asynchronous communication between the main Electrobun process and the browser context. ```APIDOC ## BrowserWindow Constructor with RPC ### Description Configure a BrowserWindow to enable Remote Procedure Calls (RPC) between the main Electrobun process and the browser view. This allows defining functions that can be called from either context, with results returned asynchronously. ### Usage Pass the `rpc` option to the `BrowserWindow` constructor, providing an `RPCSchema` object with handlers for requests and messages. ### Options - **rpc** (RPCSchema) - An object defining the RPC schema and handlers for communication. ### Example: Defining RPC Handlers in the Main Process #### Shared Types (`src/shared/types.ts`) ```typescript export type MyWebviewRPCType = { // functions that execute in the main process bun: RPCSchema<{ requests: { someBunFunction: { params: { a: number; b: number }; response: number; }; }; messages: { logToBun: { msg: string }; }; }>; // functions that execute in the browser context webview: RPCSchema<{ requests: { someWebviewFunction: { params: { a: number; b: number }; response: number; }; }; messages: { logToWebview: { msg: string }; }; }>; }; ``` #### Main Process RPC Setup (`src/bun/index.ts`) ```typescript import { BrowserWindow, BrowserView } from "electrobun/bun"; import { type MyWebviewRPCType } from "../shared/types"; const myWebviewRPC = BrowserView.defineRPC