MustafaKucukcoskun/Refine-agent-kit / shared/.agent/skills/electron-patterns
electron-patterns
VerifiedElectron architecture patterns for Main/Renderer isolation, secure IPC, window hardening, and packaging practices.
Electron Patterns Skill
1. Architectural Principles (Main vs Renderer)
- Main Process: The primary process with full access to Node.js APIs. Window management (
BrowserWindow), native file system, and IPC listening should be handled here. - Renderer Process: A Chromium-based web interface. It should NOT have direct access to Node.js APIs (security violation). Move Node logic to Main and communicate via IPC (Inter-Process Communication).
2. Secure IPC Usage (ContextBridge)
-
Only expose the functions we need to the Renderer via preload scripts.
-
Preload.js Example:
const { contextBridge, ipcRenderer } = require("electron"); contextBridge.exposeInMainWorld("myAPI", { readFile: (path) => ipcRenderer.invoke("read-file", path), // Two-way (returns Promise) onUpdateMsg: (callback) => ipcRenderer.on("update-msg", (_event, value) => callback(value)), // One-way (Main -> Renderer) }); -
Main.js Example:
ipcMain.handle("read-file", async (event, path) => { return await fs.promises.readFile(path, "utf8"); });
3. Window Management (BrowserWindow)
- Do not override the secure default settings when creating windows:
const win = new BrowserWindow({ webPreferences: { nodeIntegration: false, // NEVER set to true contextIsolation: true, // NEVER set to false preload: path.join(__dirname, "preload.js"), // Preload script is mandatory }, }); - If loading a local HTML file use
win.loadFile('index.html'), if loading a URL (React/Vue dev server) usewin.loadURL('http://localhost:3000'). - To open external links (e.g., href="https://google.com") in the user's default browser instead of the Electron window:
win.webContents.setWindowOpenHandler(({ url }) => { require("electron").shell.openExternal(url); return { action: "deny" }; });
4. Application Packaging (electron-builder)
- Always prefer
electron-builderfor distribution. (.nsisfor Windows,.dmgfor Mac,.AppImagefor Linux). - Use the
electron-updaterpackage for Auto-Update. TriggeringautoUpdater.checkForUpdatesAndNotify()on application startup is the standard approach.
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack." | Stars: 196k | Updated | Claude CodeCodex | Verified | Install |
| ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read. | Stars: 193k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report. | Stars: 193k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt. | Stars: 193k | Updated | Claude CodeCodex | Verified | Install |