When to use this skill
Use this skill whenever the user wants to:
- Build cross-platform desktop applications with Electron
- Understand Electron architecture (main process, renderer process, preload)
- Implement IPC (Inter-Process Communication) between processes
- Create and manage BrowserWindow instances
- Implement menus, tray icons, and native features
- Package and distribute Electron applications
- Use Electron Forge for project scaffolding and building
- Debug and test Electron applications
- Implement security best practices
- Use Electron APIs (app, BrowserWindow, ipcMain, ipcRenderer, etc.)
How to use this skill
This skill is organized to match the Electron official documentation structure (https://www.electronjs.org/zh/docs/latest/, https://www.electronjs.org/zh/docs/latest/api/app). When working with Electron:
Identify the topic from the user's request:
- Getting started/快速开始 →
examples/getting-started/installation.md or examples/getting-started/quick-start.md
- Main process/主进程 →
examples/processes/main-process.md
- Renderer process/渲染进程 →
examples/processes/renderer-process.md
- IPC communication/IPC 通信 →
examples/processes/ipc-communication.md
- BrowserWindow/窗口 →
examples/api/browser-window.md
- Menu/菜单 →
examples/api/menu.md
- Packaging/打包 →
examples/advanced/packaging.md
- Security/安全 →
examples/advanced/security.md
Load the appropriate example file from the examples/ directory:
Getting Started (快速开始) - examples/getting-started/:
examples/getting-started/installation.md - Installing Electron and basic setup
examples/getting-started/quick-start.md - Quick start tutorial
Processes (进程) - examples/processes/:
examples/processes/main-process.md - Main process concepts and usage
examples/processes/renderer-process.md - Renderer process concepts
examples/processes/preload-scripts.md - Preload scripts usage
examples/processes/ipc-communication.md - IPC communication patterns
API Examples (API 示例) - examples/api/:
examples/api/browser-window.md - BrowserWindow usage
examples/api/menu.md - Menu and context menu
examples/api/tray.md - System tray
examples/api/dialog.md - File dialogs
examples/api/ipc-main.md - ipcMain usage
examples/api/ipc-renderer.md - ipcRenderer usage
Advanced (高级) - examples/advanced/:
examples/advanced/packaging.md - Application packaging
examples/advanced/security.md - Security best practices
examples/advanced/auto-updater.md - Auto updater
examples/advanced/native-modules.md - Native modules
Tools (工具) - examples/tools/:
examples/tools/electron-forge.md - Electron Forge usage
examples/tools/electron-fiddle.md - Electron Fiddle usage
Follow the specific instructions in that example file for syntax, structure, and best practices
Important Notes:
- All examples follow Electron latest API
- Examples use both CommonJS (require) and ES modules (import)
- Each example file includes key concepts, code examples, and key points
- Always check the example file for best practices and common patterns
- Electron supports Windows, macOS, and Linux
Reference API documentation in the api/ directory when needed:
api/app.md - app module API
api/browser-window.md - BrowserWindow API
api/ipc-main.md - ipcMain API
api/ipc-renderer.md - ipcRenderer API
api/menu.md - Menu API
api/tray.md - Tray API
Use templates from the templates/ directory:
templates/main-process.md - Main process template
templates/preload-script.md - Preload script template
templates/renderer-process.md - Renderer process template
templates/package-json.md - package.json template
Doc mapping (one-to-one with official documentation)
Quick Start Example
// main.js
const { app, BrowserWindow, ipcMain } = require('electron')
const path = require('path')
function createWindow() {
const win = new BrowserWindow({
width: 800, height: 600,
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
nodeIntegration: false, // Security: always disable
contextIsolation: true // Security: always enable
}
})
win.loadFile('index.html')
}
app.whenReady().then(createWindow)
// IPC handler example
ipcMain.handle('get-data', async () => {
return { message: 'Hello from main process' }
})
// preload.js
const { contextBridge, ipcRenderer } = require('electron')
contextBridge.exposeInMainWorld('api', {
getData: () => ipcRenderer.invoke('get-data')
})
API Reference (api/)
api/app.md - app module API
api/browser-window.md - BrowserWindow API
api/ipc-main.md / api/ipc-renderer.md - IPC APIs
api/menu.md / api/tray.md / api/dialog.md - UI APIs
Best Practices
- Security: Never enable nodeIntegration in renderer process, use preload scripts
- Process separation: Keep main and renderer processes separate
- IPC communication: Use IPC for safe communication between processes
- Resource management: Properly clean up resources (windows, listeners)
- Error handling: Implement proper error handling and crash reporting
- Performance: Optimize for performance, use webContents for debugging
- Packaging: Use Electron Forge or electron-builder for packaging
- Auto updates: Implement auto-updater for production apps
- Native modules: Handle native module compatibility
- Cross-platform: Test on all target platforms
Resources
Keywords
Electron, desktop app, main process, renderer process, preload, IPC, BrowserWindow, Menu, Tray, Dialog, packaging, electron-builder, electron-forge, electron-fiddle, cross-platform, 桌面应用, 主进程, 渲染进程, IPC 通信, 窗口, 菜单, 托盘, 打包
1---2name: electron3description: Build cross-platform desktop applications with Electron, covering main/renderer process architecture, IPC communication, BrowserWindow management, menus, tray icons, packaging, and security best practices. Use when the user asks about Electron, needs to create desktop applications, implement Electron features, or build cross-platform desktop apps.4license: Complete terms in LICENSE.txt5---67## When to use this skill89Use this skill whenever the user wants to:10- Build cross-platform desktop applications with Electron11- Understand Electron architecture (main process, renderer process, preload)12- Implement IPC (Inter-Process Communication) between processes13- Create and manage BrowserWindow instances14- Implement menus, tray icons, and native features15- Package and distribute Electron applications16- Use Electron Forge for project scaffolding and building17- Debug and test Electron applications18- Implement security best practices19- Use Electron APIs (app, BrowserWindow, ipcMain, ipcRenderer, etc.)2021## How to use this skill2223This skill is organized to match the Electron official documentation structure (https://www.electronjs.org/zh/docs/latest/, https://www.electronjs.org/zh/docs/latest/api/app). When working with Electron:24251. **Identify the topic** from the user's request:26 - Getting started/快速开始 → `examples/getting-started/installation.md` or `examples/getting-started/quick-start.md`27 - Main process/主进程 → `examples/processes/main-process.md`28 - Renderer process/渲染进程 → `examples/processes/renderer-process.md`29 - IPC communication/IPC 通信 → `examples/processes/ipc-communication.md`30 - BrowserWindow/窗口 → `examples/api/browser-window.md`31 - Menu/菜单 → `examples/api/menu.md`32 - Packaging/打包 → `examples/advanced/packaging.md`33 - Security/安全 → `examples/advanced/security.md`34352. **Load the appropriate example file** from the `examples/` directory:3637 **Getting Started (快速开始) - `examples/getting-started/`**:38 - `examples/getting-started/installation.md` - Installing Electron and basic setup39 - `examples/getting-started/quick-start.md` - Quick start tutorial4041 **Processes (进程) - `examples/processes/`**:42 - `examples/processes/main-process.md` - Main process concepts and usage43 - `examples/processes/renderer-process.md` - Renderer process concepts44 - `examples/processes/preload-scripts.md` - Preload scripts usage45 - `examples/processes/ipc-communication.md` - IPC communication patterns4647 **API Examples (API 示例) - `examples/api/`**:48 - `examples/api/browser-window.md` - BrowserWindow usage49 - `examples/api/menu.md` - Menu and context menu50 - `examples/api/tray.md` - System tray51 - `examples/api/dialog.md` - File dialogs52 - `examples/api/ipc-main.md` - ipcMain usage53 - `examples/api/ipc-renderer.md` - ipcRenderer usage5455 **Advanced (高级) - `examples/advanced/`**:56 - `examples/advanced/packaging.md` - Application packaging57 - `examples/advanced/security.md` - Security best practices58 - `examples/advanced/auto-updater.md` - Auto updater59 - `examples/advanced/native-modules.md` - Native modules6061 **Tools (工具) - `examples/tools/`**:62 - `examples/tools/electron-forge.md` - Electron Forge usage63 - `examples/tools/electron-fiddle.md` - Electron Fiddle usage64653. **Follow the specific instructions** in that example file for syntax, structure, and best practices6667 **Important Notes**:68 - All examples follow Electron latest API69 - Examples use both CommonJS (require) and ES modules (import)70 - Each example file includes key concepts, code examples, and key points71 - Always check the example file for best practices and common patterns72 - Electron supports Windows, macOS, and Linux73744. **Reference API documentation** in the `api/` directory when needed:75 - `api/app.md` - app module API76 - `api/browser-window.md` - BrowserWindow API77 - `api/ipc-main.md` - ipcMain API78 - `api/ipc-renderer.md` - ipcRenderer API79 - `api/menu.md` - Menu API80 - `api/tray.md` - Tray API81825. **Use templates** from the `templates/` directory:83 - `templates/main-process.md` - Main process template84 - `templates/preload-script.md` - Preload script template85 - `templates/renderer-process.md` - Renderer process template86 - `templates/package-json.md` - package.json template878889### Doc mapping (one-to-one with official documentation)9091- `examples/` → https://www.electronjs.org/zh/docs/latest/92- `api/` → https://www.electronjs.org/zh/docs/latest/api/app9394## Quick Start Example9596```javascript97// main.js98const { app, BrowserWindow, ipcMain } = require('electron')99const path = require('path')100101function createWindow() {102 const win = new BrowserWindow({103 width: 800, height: 600,104 webPreferences: {105 preload: path.join(__dirname, 'preload.js'),106 nodeIntegration: false, // Security: always disable107 contextIsolation: true // Security: always enable108 }109 })110 win.loadFile('index.html')111}112113app.whenReady().then(createWindow)114115// IPC handler example116ipcMain.handle('get-data', async () => {117 return { message: 'Hello from main process' }118})119```120121```javascript122// preload.js123const { contextBridge, ipcRenderer } = require('electron')124contextBridge.exposeInMainWorld('api', {125 getData: () => ipcRenderer.invoke('get-data')126})127```128129## API Reference (`api/`)130131- `api/app.md` - app module API132- `api/browser-window.md` - BrowserWindow API133- `api/ipc-main.md` / `api/ipc-renderer.md` - IPC APIs134- `api/menu.md` / `api/tray.md` / `api/dialog.md` - UI APIs135136## Best Practices1371381. **Security**: Never enable nodeIntegration in renderer process, use preload scripts1392. **Process separation**: Keep main and renderer processes separate1403. **IPC communication**: Use IPC for safe communication between processes1414. **Resource management**: Properly clean up resources (windows, listeners)1425. **Error handling**: Implement proper error handling and crash reporting1436. **Performance**: Optimize for performance, use webContents for debugging1447. **Packaging**: Use Electron Forge or electron-builder for packaging1458. **Auto updates**: Implement auto-updater for production apps1469. **Native modules**: Handle native module compatibility14710. **Cross-platform**: Test on all target platforms148149## Resources150151- **Official Website**: https://www.electronjs.org/zh/152- **Documentation**: https://www.electronjs.org/zh/docs/latest/153- **API Reference**: https://www.electronjs.org/zh/docs/latest/api/app154- **Electron Forge**: https://www.electronforge.io155- **Electron Fiddle**: https://www.electronjs.org/zh/fiddle156- **GitHub Repository**: https://github.com/electron/electron157158## Keywords159160Electron, desktop app, main process, renderer process, preload, IPC, BrowserWindow, Menu, Tray, Dialog, packaging, electron-builder, electron-forge, electron-fiddle, cross-platform, 桌面应用, 主进程, 渲染进程, IPC 通信, 窗口, 菜单, 托盘, 打包