Electron

From TerminalSkills/skills · View interactive version

Electron is an AI agent skill from the GitHub repository TerminalSkills/skills. Assists with building cross-platform desktop applications using Electron. Use when architecting main/renderer process communication, configuring secure contexts, implementing auto-updates, or packaging apps for Windows, macOS, and Linux. Trigger words: electron, desktop app, browserwindow, ipc, auto

How to use this skill

Skill file

Electron

Overview

Electron is a framework for building cross-platform desktop applications using web technologies. It combines a Node.js main process for system access and window management with Chromium renderer processes for the UI, communicating via IPC with context isolation and preload scripts for security.

Instructions

Minimal secure skeleton

// main.js
const { app, BrowserWindow, ipcMain, dialog } = require("electron");
const path = require("node:path");

function createWindow() {
  const win = new BrowserWindow({
    width: 1100, height: 720,
    webPreferences: { preload: path.join(__dirname, "preload.js") }, // defaults stay secure
  });
  win.webContents.setWindowOpenHandler(() => ({ action: "deny" }));
  win.loadFile("index.html");
}

ipcMain.handle("dialog:openFile", async (event) => {
  if (event.senderFrame?.origin !== "file://") return null; // only our own page
  const { canceled, filePaths } = await dialog.showOpenDialog({ properties: ["openFile"] });
  return canceled ? null : filePaths[0];
});

app.whenReady().then(createWindow);
app.on("window-all-closed", () => { if (process.platform !== "darwin") app.quit(); });
{
  "name": "file-manager",
  "version": "1.0.0",
  "main": "main.js",
  "scripts": { "start": "electron ." },
  "devDependencies": { "electron": "^44.5.1" }
}
// preload.js
const { contextBridge, ipcRenderer } = require("electron");
contextBridge.exposeInMainWorld("files", { openFile: () => ipcRenderer.invoke("dialog:openFile") });

Examples

Example 1: Build a file manager with native dialogs

User request: "Create an Electron app that browses and manages files with native dialogs"

Actions:

  1. Set up main process with BrowserWindow and preload script exposing file system commands
  2. Implement IPC handlers for dialog.showOpenDialog(), dialog.showSaveDialog(), and file operations
  3. Build a React-based renderer UI for browsing directories and previewing files
  4. Add context menus and keyboard shortcuts for file operations
  5. Run npx electron . and confirm that window.files.openFile() in DevTools returns a path while require is undefined in the renderer

Output: A cross-platform file manager with native OS dialogs and secure IPC-based file access.

Example 2: Add auto-updates with staged rollout

User request: "Set up auto-updates for my Electron app using GitHub Releases"

Actions:

  1. Configure electron-builder with publish settings pointing to GitHub Releases
  2. Add electron-updater in the main process with update check on startup
  3. Implement update UI in the renderer showing download progress and restart prompt
  4. Set stagingPercentage (for example 10) in the published latest.yml to update a share of users first, and raise it as the release proves stable

Output: An Electron app that automatically checks for updates, downloads them in the background, and prompts the user to restart.

Guidelines

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.