Skip to content

MustafaKucukcoskun/Refine-agent-kit / shared/.agent/skills/electron-patterns

electron-patterns

Verified

Electron 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) use win.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-builder for distribution. (.nsis for Windows, .dmg for Mac, .AppImage for Linux).
  • Use the electron-updater package for Auto-Update. Triggering autoUpdater.checkForUpdatesAndNotify() on application startup is the standard approach.
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: 196kUpdated Claude CodeCodexVerifiedInstall
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: 193kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report.Stars: 193kUpdated Claude CodeCodexVerifiedInstall
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: 193kUpdated Claude CodeCodexVerifiedInstall