electron-pro
它能做什么
这项技能指导你使用 HTML、CSS 和 JavaScript 等网页工具,配合 Electron 框架,为 Windows、Mac 和 Linux 构建桌面应用。适合想把网页应用变成桌面应用的开发者。
适用场景
- ✓当你想把网页应用变成 Windows、Mac 或 Linux 上的桌面应用时。
- ✓当你需要应用窗口与后台系统之间的安全通信的时候。
- ✓当你想设置自动更新,或为应用商店对应用签名的时候。
技能链接
https://github.com/fathah/hermes-desktop/blob/main/.agents/skills/electron-pro/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请帮我用 Electron 把我的网页应用变成安全的 Windows 和 Mac 桌面应用?”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会推荐安全的项目设置,使窗口与系统级访问相互隔离,然后展示各部分如何相互通信。它还涵盖数据存储、内存占用和应用签名。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Electron Desktop Developer
Purpose
Provides cross-platform desktop application development expertise specializing in Electron, IPC architecture, and OS-level integration. Builds secure, performant desktop applications using web technologies with native capabilities for Windows, macOS, and Linux.
When to Use
- Building cross-platform desktop apps (VS Code, Discord style)
- Migrating web apps to desktop with native capabilities (File system, Notifications)
- Implementing secure IPC (Main ↔ Renderer communication)
- Optimizing Electron memory usage and startup time
- Configuring auto-updaters (electron-updater)
- Signing and notarizing apps for app stores
2. Decision Framework
Architecture Selection
How to structure the app?
│
├─ **Security First (Recommended)**
│ ├─ Context Isolation? → **Yes** (Standard since v12)
│ ├─ Node Integration? → **No** (Never in Renderer)
│ └─ Preload Scripts? → **Yes** (Bridge API)
│
├─ **Data Persistence**
│ ├─ Simple Settings? → **electron-store** (JSON)
│ ├─ Large Datasets? → **SQLite** (`better-sqlite3` in Main process)
│ └─ User Files? → **Native File System API**
│
└─ **UI Framework**
├─ React/Vue/Svelte? → **Yes** (Standard SPA approach)
├─ Multiple Windows? → **Window Manager Pattern**
└─ System Tray App? → **Hidden Window Pattern**
IPC Communication Patterns
| Pattern | Method | Use Case |
|---|---|---|
| One-Way (Renderer → Main) | ipcRenderer.send |
logging, analytics, minimizing window |
| Two-Way (Request/Response) | ipcRenderer.invoke |
DB queries, file reads, heavy computations |
| Main → Renderer | webContents.send |
Menu actions, system events, push notifications |
Red Flags → Escalate to security-auditor:
- Enabling
nodeIntegration: truein production - Disabling
contextIsolation - Loading remote content (
https://) without strict CSP - Using
remotemodule (Deprecated & insecure)
Workflow 2: Performance Optimization (Startup)
Goal: Reduce launch time to < 2s.
Steps:
V8 Snapshot
- Use
electron-linkorv8-compile-cacheto pre-compile JS.
- Use
Lazy Loading Modules
- Don't
require()everything at top ofmain.ts.
// Bad import { heavyLib } from "heavy-lib"; // Good ipcMain.handle("do-work", () => { const heavyLib = require("heavy-lib"); heavyLib.process(); });- Don't
Bundle Main Process
- Use
esbuildorwebpackfor Main process (not just Renderer) to tree-shake unused code and minify.
- Use
4. Patterns & Templates
Pattern 1: Worker Threads (CPU Intensive Tasks)
Use case: Image processing or parsing large files without freezing the UI.
// main.ts
import { Worker } from "worker_threads";
ipcMain.handle("process-image", (event, data) => {
return new Promise((resolve, reject) => {
const worker = new Worker("./worker.js", { workerData: data });
worker.on("message", resolve);
worker.on("error", reject);
});
});
Pattern 2: Deep Linking (Protocol Handler)
Use case: Opening app from browser (myapp://open?id=123).
// main.ts
if (process.defaultApp) {
if (process.argv.length >= 2) {
app.setAsDefaultProtocolClient("myapp", process.execPath, [
path.resolve(process.argv[1]),
]);
}
} else {
app.setAsDefaultProtocolClient("myapp");
}
app.on("open-url", (event, url) => {
event.preventDefault();
// Parse url 'myapp://...' and navigate renderer
mainWindow.webContents.send("navigate", url);
});
6. Integration Patterns
frontend-ui-ux-engineer:
- Handoff: UI Dev builds the React/Vue app → Electron Dev wraps it.
- Collaboration: Handling window controls (custom title bar), vibrancy/acrylic effects.
- Tools: CSS
app-region: drag.
devops-engineer:
- Handoff: Electron Dev provides build config → DevOps sets up CI pipeline.
- Collaboration: Code signing certificates (Apple Developer ID, Windows EV).
- Tools: Electron Builder, Notarization scripts.
security-engineer:
- Handoff: Electron Dev implements feature → Security Dev audits IPC surface.
- Collaboration: Defining Content Security Policy (CSP) headers.
常见问题
什么是 Electron?
Electron 是一个框架,让你可以使用 HTML、CSS 和 JavaScript 等网页技术构建桌面应用。
它默认就是安全的吗?
这项技能推荐安全设置,例如开启上下文隔离、关闭 Node 集成。
它能帮忙处理更新吗?
可以。它涵盖了使用 electron-updater 设置自动更新。
详情
作者的原始描述
Expert in building cross-platform desktop applications using web technologies (HTML/CSS/JS) with the Electron framework.
repo: fathah/hermes-desktop
热度
- GitHub 星标
- 15k
- 排名
- #11137
- 许可证
- MIT
- 更新时间
- 2026/10/13
评论
- …