electron
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseWhen 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.)
当用户有以下需求时,可使用此技能:
- 使用Electron构建跨平台桌面应用
- 了解Electron架构(主进程、渲染进程、预加载脚本)
- 实现进程间的IPC(进程间通信)
- 创建和管理BrowserWindow实例
- 实现菜单、托盘图标及原生功能
- 打包和分发Electron应用
- 使用Electron Forge进行项目脚手架搭建和构建
- 调试和测试Electron应用
- 实施安全最佳实践
- 使用Electron API(app、BrowserWindow、ipcMain、ipcRenderer等)
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/快速开始 → or
examples/getting-started/installation.mdexamples/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
- Getting started/快速开始 →
-
Load the appropriate example file from thedirectory:
examples/Getting Started (快速开始) -:examples/getting-started/- - Installing Electron and basic setup
examples/getting-started/installation.md - - Quick start tutorial
examples/getting-started/quick-start.md
Processes (进程) -:examples/processes/- - Main process concepts and usage
examples/processes/main-process.md - - Renderer process concepts
examples/processes/renderer-process.md - - Preload scripts usage
examples/processes/preload-scripts.md - - IPC communication patterns
examples/processes/ipc-communication.md
API Examples (API 示例) -:examples/api/- - BrowserWindow usage
examples/api/browser-window.md - - Menu and context menu
examples/api/menu.md - - System tray
examples/api/tray.md - - File dialogs
examples/api/dialog.md - - ipcMain usage
examples/api/ipc-main.md - - ipcRenderer usage
examples/api/ipc-renderer.md
Advanced (高级) -:examples/advanced/- - Application packaging
examples/advanced/packaging.md - - Security best practices
examples/advanced/security.md - - Auto updater
examples/advanced/auto-updater.md - - Native modules
examples/advanced/native-modules.md
Tools (工具) -:examples/tools/- - Electron Forge usage
examples/tools/electron-forge.md - - Electron Fiddle usage
examples/tools/electron-fiddle.md
-
Follow the specific instructions in that example file for syntax, structure, and best practicesImportant 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 thedirectory when needed:
api/- - app module API
api/app.md - - BrowserWindow API
api/browser-window.md - - ipcMain API
api/ipc-main.md - - ipcRenderer API
api/ipc-renderer.md - - Menu API
api/menu.md - - Tray API
api/tray.md
-
Use templates from thedirectory:
templates/- - Main process template
templates/main-process.md - - Preload script template
templates/preload-script.md - - Renderer process template
templates/renderer-process.md - - package.json template
templates/package-json.md
本技能的组织结构与Electron官方文档结构一致(https://www.electronjs.org/zh/docs/latest/、https://www.electronjs.org/zh/docs/latest/api/app)。使用Electron时:
-
从用户请求中确定主题:
- 快速开始 → 或
examples/getting-started/installation.mdexamples/getting-started/quick-start.md - 主进程 →
examples/processes/main-process.md - 渲染进程 →
examples/processes/renderer-process.md - IPC通信 →
examples/processes/ipc-communication.md - BrowserWindow/窗口 →
examples/api/browser-window.md - 菜单 →
examples/api/menu.md - 打包 →
examples/advanced/packaging.md - 安全 →
examples/advanced/security.md
- 快速开始 →
-
从目录加载对应的示例文件:
examples/快速开始 -:examples/getting-started/- - Electron安装及基础设置
examples/getting-started/installation.md - - 快速入门教程
examples/getting-started/quick-start.md
进程 -:examples/processes/- - 主进程概念与使用
examples/processes/main-process.md - - 渲染进程概念
examples/processes/renderer-process.md - - 预加载脚本使用
examples/processes/preload-scripts.md - - IPC通信模式
examples/processes/ipc-communication.md
API示例 -:examples/api/- - BrowserWindow使用方法
examples/api/browser-window.md - - 菜单与上下文菜单
examples/api/menu.md - - 系统托盘
examples/api/tray.md - - 文件对话框
examples/api/dialog.md - - ipcMain使用方法
examples/api/ipc-main.md - - ipcRenderer使用方法
examples/api/ipc-renderer.md
高级 -:examples/advanced/- - 应用打包
examples/advanced/packaging.md - - 安全最佳实践
examples/advanced/security.md - - 自动更新器
examples/advanced/auto-updater.md - - 原生模块
examples/advanced/native-modules.md
工具 -:examples/tools/- - Electron Forge使用方法
examples/tools/electron-forge.md - - Electron Fiddle使用方法
examples/tools/electron-fiddle.md
-
遵循示例文件中的具体说明,包括语法、结构和最佳实践重要说明:
- 所有示例均遵循Electron最新API
- 示例同时使用CommonJS(require)和ES模块(import)
- 每个示例文件包含核心概念、代码示例和关键点
- 务必查看示例文件中的最佳实践和通用模式
- Electron支持Windows、macOS和Linux系统
-
必要时参考目录中的API文档:
api/- - app模块API
api/app.md - - BrowserWindow API
api/browser-window.md - - ipcMain API
api/ipc-main.md - - ipcRenderer API
api/ipc-renderer.md - - Menu API
api/menu.md - - Tray API
api/tray.md
-
使用目录中的模板:
templates/- - 主进程模板
templates/main-process.md - - 预加载脚本模板
templates/preload-script.md - - 渲染进程模板
templates/renderer-process.md - - package.json模板
templates/package-json.md
Doc mapping (one-to-one with official documentation)
文档映射(与官方文档一一对应)
Examples and Templates
示例与模板
This skill includes detailed examples organized to match the official documentation structure. All examples are in the directory (see mapping above).
examples/To use examples:
- Identify the topic from the user's request
- Load the appropriate example file from the mapping above
- Follow the instructions, syntax, and best practices in that file
- Adapt the code examples to your specific use case
To use templates:
- Reference templates in directory for common scaffolding
templates/ - Adapt templates to your specific needs and coding style
本技能包含详细的示例,组织结构与官方文档一致。所有示例均位于目录(见上述映射)。
examples/使用示例的方法:
- 从用户请求中确定主题
- 根据上述映射加载对应的示例文件
- 遵循文件中的说明、语法和最佳实践
- 根据具体用例调整代码示例
使用模板的方法:
- 参考目录中的模板进行通用脚手架搭建
templates/ - 根据具体需求和编码风格调整模板
API Reference
API参考
Detailed API documentation is available in the directory, organized to match the official Electron API documentation structure:
api/详细的API文档位于目录,组织结构与Electron官方API文档一致:
api/Core APIs (api/
)
api/核心API (api/
)
api/- - app module API
api/app.md - - BrowserWindow API
api/browser-window.md - - ipcMain API
api/ipc-main.md - - ipcRenderer API
api/ipc-renderer.md - - Menu API
api/menu.md - - Tray API
api/tray.md - - Dialog API
api/dialog.md
To use API reference:
- Identify the API you need help with
- Load the corresponding API file from the directory
api/ - Find the API signature, parameters, return type, and examples
- Reference the linked example files for detailed usage patterns
- All API files include links to relevant example files in the directory
examples/
- - app模块API
api/app.md - - BrowserWindow API
api/browser-window.md - - ipcMain API
api/ipc-main.md - - ipcRenderer API
api/ipc-renderer.md - - Menu API
api/menu.md - - Tray API
api/tray.md - - Dialog API
api/dialog.md
使用API参考的方法:
- 确定所需的API
- 从目录加载对应的API文件
api/ - 查找API签名、参数、返回类型和示例
- 参考关联的示例文件获取详细使用模式
- 所有API文件均包含指向目录中相关示例文件的链接
examples/
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
- 安全: 切勿在渲染进程中启用nodeIntegration,使用预加载脚本
- 进程分离: 保持主进程与渲染进程分离
- IPC通信: 使用IPC实现进程间的安全通信
- 资源管理: 正确清理资源(窗口、监听器)
- 错误处理: 实施完善的错误处理和崩溃报告
- 性能: 优化性能,使用webContents进行调试
- 打包: 使用Electron Forge或electron-builder进行打包
- 自动更新: 为生产应用实现自动更新功能
- 原生模块: 处理原生模块的兼容性问题
- 跨平台: 在所有目标平台上进行测试
Resources
资源
- Official Website: https://www.electronjs.org/zh/
- Documentation: https://www.electronjs.org/zh/docs/latest/
- API Reference: https://www.electronjs.org/zh/docs/latest/api/app
- Electron Forge: https://www.electronforge.io
- Electron Fiddle: https://www.electronjs.org/zh/fiddle
- GitHub Repository: https://github.com/electron/electron
- 官方网站: https://www.electronjs.org/zh/
- 文档: https://www.electronjs.org/zh/docs/latest/
- API参考: https://www.electronjs.org/zh/docs/latest/api/app
- Electron Forge: https://www.electronforge.io
- Electron Fiddle: https://www.electronjs.org/zh/fiddle
- GitHub仓库: https://github.com/electron/electron
Keywords
关键词
Electron, desktop app, main process, renderer process, preload, IPC, BrowserWindow, Menu, Tray, Dialog, packaging, electron-builder, electron-forge, electron-fiddle, cross-platform, 桌面应用, 主进程, 渲染进程, IPC 通信, 窗口, 菜单, 托盘, 打包
Electron, 桌面应用, 主进程, 渲染进程, 预加载, IPC, BrowserWindow, 菜单, 托盘, 对话框, 打包, electron-builder, electron-forge, electron-fiddle, 跨平台, 桌面应用, 主进程, 渲染进程, IPC通信, 窗口, 菜单, 托盘, 打包