源码目录结构

Electron 的源代码主要依据 Chromium 的拆分约定被拆成了许多部分。

为了更好地理解源代码,您可能需要了解一下 Chromium 的多进程架构

源代码的目录结构

  1. Electron
  2. ├── build/ - Build configuration files needed to build with GN.
  3. ├── buildflags/ - Determines the set of features that can be conditionally built.
  4. ├── chromium_src/ - Source code copied from Chromium that isn't part of the content layer.
  5. ├── default_app/ - A default app run when Electron is started without
  6. | providing a consumer app.
  7. ├── docs/ - Electron's documentation.
  8. | ├── api/ - Documentation for Electron's externally-facing modules and APIs.
  9. | ├── development/ - Documentation to aid in developing for and with Electron.
  10. | ├── fiddles/ - A set of code snippets one can run in Electron Fiddle.
  11. | ├── images/ - Images used in documentation.
  12. | └── tutorial/ - Tutorial documents for various aspects of Electron.
  13. ├── lib/ - JavaScript/TypeScript source code.
  14. | ├── browser/ - Main process initialization code.
  15. | | ├── api/ - API implementation for main process modules.
  16. | | └── remote/ - Code related to the remote module as it is
  17. | | used in the main process.
  18. | ├── common/ - Relating to logic needed by both main and renderer processes.
  19. | | └── api/ - API implementation for modules that can be used in
  20. | | both the main and renderer processes
  21. | ├── isolated_renderer/ - Handles creation of isolated renderer processes when
  22. | | contextIsolation is enabled.
  23. | ├── renderer/ - Renderer process initialization code.
  24. | | ├── api/ - API implementation for renderer process modules.
  25. | | ├── extension/ - Code related to use of Chrome Extensions
  26. | | | in Electron's renderer process.
  27. | | ├── remote/ - Logic that handes use of the remote module in
  28. | | | the main process.
  29. | | └── web-view/ - Logic that handles the use of webviews in the
  30. | | renderer process.
  31. | ├── sandboxed_renderer/ - Logic that handles creation of sandboxed renderer
  32. | | | processes.
  33. | | └── api/ - API implementation for sandboxed renderer processes.
  34. | └── worker/ - Logic that handles proper functionality of Node.js
  35. | environments in Web Workers.
  36. ├── patches/ - Patches applied on top of Electron's core dependencies
  37. | | in order to handle differences between our use cases and
  38. | | default functionality.
  39. | ├── boringssl/ - Patches applied to Google's fork of OpenSSL, BoringSSL.
  40. | ├── chromium/ - Patches applied to Chromium.
  41. | ├── node/ - Patches applied on top of Node.js.
  42. | └── v8/ - Patches applied on top of Google's V8 engine.
  43. ├── shell/ - C++ source code.
  44. | ├── app/ - 系统入口代码.
  45. | ├── browser/ - 包含了主窗口、UI 和所有主进程相关的东西.
  46. | | | 它会告诉渲染进程如何管理页面.
  47. | | ├── ui/ - 不同平台上 UI 部分的实现.
  48. | | | ├── cocoa/ - Cocoa 部分的源代码.
  49. | | | ├── win/ - Windows GUI 部分的源代码.
  50. | | | └── x/ - X11 部分的源代码.
  51. | | ├── api/ - 主进程 API 的实现.
  52. | | ├── net/ - 网络相关的代码.
  53. | | ├── mac/ - 与 Mac 有关的 Objective-C 代码.
  54. | | └── resources/ - 图标,平台相关的文件等.
  55. | ├── renderer/ - 运行在渲染进程中的代码.
  56. | | └── api/ - 渲染进程 API 的实现.
  57. | └── common/ - 同时被主进程和渲染进程用到的代码,
  58. | | 包括了一些用来将 node 的消息循环整合到 Chromium 的
  59. | | 消息循环中时用到的工具函数和代码.
  60. | └── api/ - 同时被主进程和渲染进程使用到的 API 的实现,
  61. | 并且是 Electron 内置模块的基础.
  62. ├── spec/ - Components of Electron's test suite run in the renderer process.
  63. ├── spec-main/ - Components of Electron's test suite run in the main process.
  64. └── BUILD.gn - Electron 的构建规则.

其它目录的结构

  • .circleci - Config file for CI with CircleCI.
  • .github - GitHub-specific config files including issues templates and CODEOWNERS.
  • dist - 由脚本 script/create-dist.py 创建的临时发布目录.
  • external_binaries - 下载了不支持用 gn 构建的第三方框架的二进制文件.
  • node_modules - 在构建中用到的第三方 node 模块.
  • npm - Logic for installation of Electron via npm.
  • out - ninja 的临时输出目录.
  • script - 用于诸如构建、打包、测试等开发用途的脚本等.
  1. script/ - The set of all scripts Electron runs for a variety of purposes.
  2. ├── codesign/ - Fakes codesigning for Electron apps; used for testing.
  3. ├── lib/ - Miscellaneous python utility scripts.
  4. └── release/ - Scripts run during Electron's release process.
  5. ├── notes/ - Generates release notes for new Electron versions.
  6. └── uploaders/ - Uploads various release-related files during release.
  • 工具 - Helper scripts used by GN files.
    • Scripts put here should never be invoked by users directly, unlike those in script.
  • typings - TypeScript typings for Electron’s internal code.
  • vendor - Source code for some third party dependencies, including boto and requests.

让 Git 子模块保持最新

Electron信息库有一些被提供的依赖, 在 /vendor 目录中可以找到. 运行 git status 时,偶尔会看到这样的消息:

  1. $ git status
  2. modified: vendor/depot_tools (new commits)
  3. modified: vendor/boto (new commits)

要更新这些被提供的依赖关系,运行以下命令:

  1. git submodule update --init --recursive

如果您发现自己经常运行此命令, 你可以在 ~/.gitconfig 文件中创建一个别名:

  1. [alias]
  2. su = submodule update --init --recursive