源码目录结构
Electron 的源代码主要依据 Chromium 的拆分约定被拆成了许多部分。
You may need to become familiar with Chromium's multi-process architecture to understand the source code better.
Project structure
Electron is a complex project containing multiple upstream dependencies, which are tracked in source control via the DEPS file. When initializing a local Electron checkout, Electron's source code is just one of many nested folders within the project root.
The project contains a single src folder that corresponds a specific git checkout of Chromium's src folder. In addition, Electron's repository code is contained in src/electron (with its own nested git repository), and other Electron-specific third-party dependencies (e.g. nan or node) are located in src/third_party (along with all other Chromium third-party dependencies, such as WebRTC or ANGLE).
For all code outside of src/electron, Electron-specific code changes are maintained via git patches. See the Patches development guide for more information.
Project Root
└── src
├── electron
├── third_party
│ ├── nan
│ ├── electron_node
│ └── ...other third party deps
└── ...other folders
Structure of Electron source code
Electron
├── build/ - 使用 GN 构建所需要的配置文件。
├── buildflags/ - 条件编译时可选的Features.
├── chromium_src/ - 从Chromium复制的源代码,不属于内容层。
├── default_app/ - 在没有提供应用程序的情况下启动的 Electron 默认程序.
├── docs/ - Electron 的文档。
| ├── api/ - Electron 外向模块和 API 的文档
| ├── development/ - 帮助为了开发 Electron 与和 Electron 一起开发的文档
| ├── fiddles/ - A set of code snippets one can run in Electron Fiddle.
| ├── images/ - Images used in documentation.
| └── tutorial/ - Tutorial documents for various aspects of Electron.
├── lib/ - JavaScript/TypeScript 源码。
| ├── browser/ - Main process initialization code.
| | ├── api/ - API implementation for main process modules.
| ├── common/ - Relating to logic needed by both main and renderer processes.
| | └── api/ - API implementation for modules that can be used in
| | both the main and renderer processes
| ├── isolated_renderer/ - Handles creation of isolated renderer processes when
| | contextIsolation is enabled.
| ├── node/ - Initialization code for Node.js in the main process.
│ ├── preload_realm/ - Initialization code for sandboxed renderer preload scripts.
│ │ └── api/ - API implementation for preload scripts.
| ├── renderer/ - Renderer process initialization code.
| | ├── api/ - API implementation for renderer process modules.
| | └── web-view/ - Logic that handles the use of webviews in the
| | renderer process.
| ├── sandboxed_renderer/ - Logic that handles creation of sandboxed renderer
| | | processes.
| | └── api/ - API implementation for sandboxed renderer processes.
│ ├── utility/ - Utility process initialization code.
│ │ └── api/ - API implementation for utility process modules.
| └── worker/ - Logic that handles proper functionality of Node.js
| environments in Web Workers.
├── patches/ - Patches applied on top of Electron's core dependencies
| | in order to handle differences between our use cases and
| | default functionality.
| | --boringssl/ - 对谷歌的 BoringSSL (谷歌对OpenSSL的Fork)的Patches。
| ├── chromium/ - 对Chromium的Patches.
| ├── node/ - 对Node.js的Patches.
| └── v8/ - 对Google V8引擎的Patches.
├── shell/ - C++源代码。
| ├── app/ - 系统入口代码.
| ├── browser/ - 包含了主窗口、UI 和所有主进程相关的东西.
| | | 它会告诉渲染进程如何管理页面.
| | ├── ui/ - 不同平台上 UI 部分的实现.
| | | ├── cocoa/ - Cocoa 部分的源代码.
| | | ├── win/ - Windows GUI 部分的源代码.
| | | └── x/ - X11 部分的源代码.
| | ├── api/ - 主进程 API 的实现.
| | ├── net/ - 网络相关的代码.
| | ├── mac/ - 与 Mac 有关的 Objective-C 代码.
| | └── resources/ - 图标、平台依赖文件等。
| ├── renderer/ - 运行在渲染进程中的代码.
| | └── api/ - 渲染进程 API 的实现.
| ├── common/ - Code that used by both the main and renderer processes,
| | | including some helper functions and code to integrate node's
| | | message loop into Chromium's message loop.
| | └── api/ - The implementation of common APIs, and foundations of
| | Electron's built-in modules.
│ ├── services/node/ - Provides a Node.js runtime to utility processes.
│ └── utility - Code that runs in the utility process.
├── spec/ - 运行在Electron主进程中的Electron测试套件组件.
├── typings/ - Internal TypeScript types that aren't exported in electron.d.ts.
└── BUILD.gn - Electron 的构建规则.
Structure of other Electron directories
- .github - GitHub-specific config files including issues templates, CI with GitHub Actions and CODEOWNERS.
- dist - 由脚本
script/create-dist.py创建的临时发布目录. - node_modules - 在构建中用到的第三方 node 模块.
- npm - 通过 npm 安装 Electron 的逻辑。
- out - Temporary output directory for
siso. - script - 用于诸如构建、打包、测试等开发用途的脚本等.
script/ - The set of all scripts Electron runs for a variety of purposes.
├── codesign/ - Fakes codesigning for Electron apps; used for testing.
├── lib/ - Miscellaneous python utility scripts.
└── release/ - Scripts run during Electron's release process.
├── notes/ - Generates release notes for new Electron versions.
└── uploaders/ - Uploads various release-related files during release.
- typings - Electron的内部代码的 TypeScript typings。