¥With the success of December Quiet Month 2021, we wanted to bring it back for 2022. December continues to be a quiet month for most companies, so we want to give our maintainers a chance to recharge. Everyone is looking forward to 2023, and we expect good things to come! We encourage other projects to consider similar measures.
¥We are excited to announce that Electron Forge v6.0.0 is now available! This release marks the first major release of Forge since 2018 and moves the project from electron-userland into the main electron organization on Github.
继续阅读,了解最新动态以及你的应用如何应用 Electron Forge!
¥Keep on reading to see what's new and how your app can adopt Electron Forge!
Electron Forge 是一款用于打包和分发 Electron 应用的工具。它将 Electron 的构建工具生态系统统一到一个可扩展的界面中,以便任何人都可以直接开始制作 Electron 应用。
¥Electron Forge is a tool for packaging and distributing Electron applications. It unifies Electron's build tooling ecosystem into a single extensible interface so that anyone can jump right into making Electron apps.
亮点功能包括:
¥Highlight features include:
📦 应用打包和代码签名
¥📦 Application packaging and code signing
🚚 可在 Windows、macOS 和 Linux 上自定义的安装程序(DMG、deb、MSI、PKG、AppX 等)
¥🚚 Customizable installers on Windows, macOS, and Linux (DMG, deb, MSI, PKG, AppX, etc.)
¥From v1 to v5, Electron Forge was based on the now-discontinued electron-compile project. Forge 6 is a complete rewrite of the project with a new modular architecture that can be extended to meet any Electron application's needs.
¥In the past few years, Forge v6.0.0-beta has achieved feature parity with v5 and code churn has slowed down dramatically, making the tool ready for general adoption.
¥For versions 5 and below, Electron Forge was published to the electron-forge package on npm.
Starting with the v6 rewrite, Forge is instead structured as a monorepo project with many smaller
projects.
从历史上看,Electron 维护者对构建工具一直持开放态度,将这项任务留给了各种社区软件包。然而,随着 Electron 项目的日趋成熟,新的 Electron 开发者越来越难以理解构建和分发应用所需的工具。
¥Historically, Electron maintainers have been unopinionated about build tooling, leaving the task to various community packages. However, with Electron maturing as a project, it has become harder for new Electron developers to understand which tools they need to build and distribute their apps.
为了指导 Electron 开发者完成分发流程,我们决定将 Forge 作为 Electron 的官方完整构建流程。
¥To help guide Electron developers in the distribution process, we have have decided to make Forge the official batteries-included build pipeline for Electron.
在过去的一年里,我们一直在慢慢地将 Forge 集成到 Electron 官方文档中,最近我们已将 Forge 从 electron-userland/electron-forge 的旧仓库迁移到 electron/forge 仓库。现在,我们终于准备好向公众发布 Electron Forge 了!
¥Over the past year, we have been slowly integrating Forge into the official Electron documentation, and we have recently moved Forge over from its old home in electron-userland/electron-forge to the electron/forge repo. Now, we are finally ready to release Electron Forge to a general audience!
¥The above snippet uses Forge's Webpack Template, which we recommend as a starting point for new Electron projects. This template is built around the @electron-forge/plugin-webpack plugin, which integrates webpack with Electron Forge in a few ways, including:
¥When you use the import command, Electron Forge will add a few core dependencies and create a new forge.config.js configuration. If you have any existing build tooling (e.g. Electron Packager, Electron Builder, or Forge 5), it will try to migrate as many settings as possible. Some of your existing configuration may need to be migrated manually.
如果你已经拥有用于打包和发布 Electron 应用的工具,那么采用 Electron Forge 带来的好处仍然可以超过最初的切换成本。
¥If you already have tooling for packaging and publishing your Electron app, the benefits associated with adopting Electron Forge can still outweigh the initial switching cost.
我们认为使用 Forge 有两个主要好处:
¥We believe there are two main benefits to using Forge:
Forge 会在 Electron 支持新功能后立即提供应用构建功能。这样,你无需自行添加新的工具支持,也无需等待其他软件包最终实现该支持后再进行升级。有关最新示例,请参阅 macOS 通用二进制文件 和 ASAR 完整性检查。
¥Forge receives new features for application building as soon as they are supported in Electron. In this case, you won't need to wire in new tooling support yourself, or wait for that support to be eventually implemented by other packages before upgrading. For recent examples, see macOS universal binaries and ASAR integrity checking.
Forge 的多包架构使其易于理解和扩展。由于 Forge 由许多职责明确的小型软件包组成,因此更容易遵循代码流程。此外,Forge 的可扩展 API 设计意味着你可以编写自己的额外构建逻辑,而无需使用提供的配置选项来处理高级用例。有关编写自定义 Forge 插件、创建器和发布器的更多详细信息,请参阅文档的 扩展 Electron Forge 部分。
¥Forge's multi-package architecture makes it easy to understand and extend. Since Forge is made up of many smaller packages with clear responsibilities, it is easier to follow code flow. In addition, Forge's extensible API design means that you can write your own additional build logic separate from the provided configuration options for advanced use cases. For more details on writing custom Forge plugins, makers, and publishers, see the Extending Electron Forge section of the docs.
¥Forge 6 has spent a long time in the beta phase, and its release cadence has gradually slowed down. However, we have accelerated development in the second half of 2022 and used the last few releases to push some final breaking changes before the v6.0.0 stable release.
如果你是 Electron Forge 6 测试版用户,请参阅 v6.0.0 GitHub 发行说明 表格,查看近期测试版(>=6.0.0-beta.65)中的重大更改列表。
¥If you are an Electron Forge 6 beta user, see the v6.0.0 GitHub release notes for a list of breaking changes made in recent betas (>=6.0.0-beta.65).
¥Tell us what you need! The Electron Forge team is always looking to build the project to better suit its users.
你可以通过提交功能请求、发布 issues 或仅仅告诉我们你的反馈来帮助我们改进 Electron Forge!你还可以加入我们的 官方 Electron Discord 服务器,那里有一个专门的 Electron Forge 讨论通道。
¥You can help us improve Electron Forge by submitting feature requests, posting issues, or just letting us know your feedback! You can also join us in the official Electron Discord server, where there is a dedicated channel for Electron Forge discussion.
¥Last month, Electron’s maintainer group met up in Vancouver, Canada to discuss the direction of the
project for 2023 and beyond. Over four days in a conference room, core maintainers and invited
collaborators discussed new initiatives, maintenance pain points, and general project health.
展望未来,团队仍将全力以赴地定期快速发布 Chromium 升级,修复错误,并使 Electron 更加安全、高效,造福所有人。我们还有一些正在进行的激动人心的项目,很乐意与社区分享!
¥Going forward, the team will still be fully dedicated to releasing regular and rapid
Chromium upgrades, fixing bugs, and making Electron more secure and performant for everyone.
We also have a few exciting projects in the works we would love to share with
the community!
Electron 项目中需要达成共识的主要 API 提案将经过征求意见稿 (RFC) 流程,并由 API 工作组成员进行审核。
¥Major API proposals in the Electron project that require consensus go through a Request for Comments
(RFC) process, which gets reviewed by members of our API Working Group.
今年,我们推进了两项重要提案,它们有可能为 Electron 应用开启新的功能维度。这些提案仍处于高度实验性阶段,但让我们先睹为快!
¥This year, we have driven forward two major proposals that have the potential to unlock a new
dimension of capabilities for Electron apps. These proposals are highly experimental, but here’s a
sneak peek of what to expect!
此提案概述了 Electron C API 的新层,允许应用开发者编写自己的原生 Node 插件,并与 Electron 的内部资源进行交互,类似于 Node 自身的 Node-API。有关拟议的新 API 可以在这里找到 的更多信息。
¥This proposal outlines a new layer of Electron C APIs that will allow app developers to write their
own Native Node Addons that interface with Electron’s internal resources, similar to Node’s
own Node-API. More information about the proposed new API can be found here.
¥Example: Supercharging apps with Chromium resources
许多 Electron 应用维护自己的分支,以便直接与 Chromium 内部组件交互,否则原始(未修改的)Electron 无法访问这些组件。通过在 C API 层公开这些资源,这些代码可以作为原生模块与 Electron 共存,从而潜在地减轻应用开发者的维护负担。
¥Many Electron apps maintain their own forks to interact directly with Chromium internals that would
otherwise be inaccessible with vanilla (unmodified) Electron. By exposing these resources in the C
API layer, this code can instead live as a native module alongside Electron, potentially reducing
app developer maintenance burden.
Chrome 用户界面 (UI) 中非网站部分,例如工具栏、标签页或按钮,都是基于名为 Views 的框架构建的。Views API 提案将该框架的部分内容作为 JavaScript 类引入到 Electron 中,最终目标是允许开发者为其 Electron 应用创建非 Web UI 元素。这将防止应用拼凑网页内容。
¥Under the hood, the non-website parts of Chrome’s user interface (UI), such as toolbars, tabs, or
buttons, are built with a framework called Views. The Views API proposal introduces parts of this
framework as JavaScript classes in Electron, with the eventual goal of allowing developers to create
non-web UI elements to their Electron applications. This will prevent apps from having to hack
together web contents.
目前正在进行实现这套新 API 的基础工作。以下是一些你近期可以期待的早期功能。
¥The groundwork to make this new set of APIs possible is currently in progress. Here are a few of the
first things you can expect in the near future.
¥Example: Refactoring the window model with WebContentsView
我们计划的第一个变更是将 Chrome 的 WebContentsView 暴露给 Electron 的 API 接口,这将取代我们现有的 BrowserView API(尽管名称如此,但它是 Electron 特有的代码,与 Chromium Views 无关)。随着 WebContentsView 的公开,我们将拥有一个可重用的 View 对象,它可以显示 Web 内容,从而为将 BrowserWindow 类变成纯 JavaScript 语言打开了大门,并进一步降低了代码复杂性。
¥Our first planned change is to expose Chrome’s WebContentsView to Electron’s API surface, which will
be the successor to our existing BrowserView API (which, despite the name, is Electron-specific code
unrelated to Chromium Views). With WebContentsView exposed, we will have a reusable View object that
can display web contents, opening the door to making the BrowserWindow class pure JavaScript and
eliminating even more code complexity.
¥Although this change doesn’t provide a lot of new functionality to app developers, it is a large
refactor that eliminates a lot of code under the hood, simplifying Chromium upgrades and reducing
the risk of new bugs appearing between major versions.
如果你是 Electron 开发者,并在应用中使用 BrowserViews:别担心,我们没有忘记你!我们计划将现有的 BrowserView 类作为 WebContentsView 的填充程序,以便在你过渡到较新的 API 时提供缓冲。
¥If you’re an Electron developer using BrowserViews in your app: don’t worry, we haven’t forgotten
about you! We plan on making the existing BrowserView class a shim for WebContentsView to provide a
buffer as you transition to the newer APIs.
我们在 Stack 的朋友们一直在推动一项计划,将 Chromium ScrollView 组件开放给 Electron 的 API。使用此新 API,任何子视图组件都可以水平或垂直滚动。
¥Our friends at Stack have been driving an initiative to expose the Chromium ScrollView component to
Electron’s API. With this new API, any child View component can be made scrollable horizontally or
vertically.
虽然这个新 API 仅实现了一个较小的功能,但团队的最终目标是构建一组实用的 View 组件,可用作构建更复杂的非 HTML 界面的工具包。
¥Although this new API fulfills a single smaller functionality, the team’s eventual goal is to build
a set of utility View components that can be used as a toolkit to build more complex non-HTML
interfaces.
你是一位 Electron 应用开发者,对这两个 API 提案感兴趣吗?虽然我们尚未准备好接收更多 RFC,但请继续关注未来的更多详细信息!
¥Are you an Electron app developer interested in either of these API proposals? Although we’re not
quite ready to receive additional RFCs, please stay tuned for more details in the future!
¥Since the framework’s inception, Electron’s build tooling ecosystem has been largely
community-driven and has consisted of many small single-purpose packages (e.g. electron-winstaller,
electron-packager, electron-notarize, electron-osx-sign). Although these tools work well, it’s
intimidating for users to piece together a working build pipeline.
为了给 Electron 开发者打造更友好的体验,我们构建了 Electron Forge,这是一个一体化解决方案,将所有现有工具整合到一个界面中。尽管 Forge 自 2017 年以来一直在开发中,但该项目在过去几年中一直处于停滞状态。然而,考虑到社区对 Electron 构建工具状态的反馈,我们一直在努力发布 Forge 的下一代稳定主版本。
¥To help build a friendlier experience for Electron developers, we built Electron Forge, an
all-in-one solution that combines all this existing tooling into a single interface. Although Forge
has been in development since 2017, the project has lain dormant for the last few years. However,
given community feedback on the state of build tooling in Electron, we have been hard at work on
releasing the next-gen stable major version of Forge.
Electron Forge 6 提供一流的 TypeScript 和 Webpack 支持,以及一个可扩展的 API,允许开发者创建自己的插件和安装程序。
¥Electron Forge 6 comes with first-class TypeScript and Webpack support, as well as an extensible
API that allows developers to create their own plugins and installers.
如果你有兴趣使用 Forge 构建项目,或者使用 Forge 可扩展的第三方 API 构建模板或插件,请持续关注我们本月发布的 Forge v6 稳定版官方公告!
¥If you’re interested in building a project with Forge or building templates or plugins with Forge’s
extensible third-party APIs, stay tuned for our official announcement on the Forge v6 stable
release sometime this month!
除此之外,团队一直在考虑一系列探索性项目,以改善应用开发者和终端用户的 Electron 体验。我们正在尝试其他更新工具、API 审核流程和增强文档。我们希望在不久的将来有更多新闻分享!
¥Aside from the above, the team is always thinking of a bunch of exploratory projects to make the
Electron experience better for app developers and end users. Updater tooling, API review processes,
and enhanced documentation are other things we are experimenting with. We hope to have more news to
share in the near future!
Electron 21.0.0 已发布!它包含对 Chromium 106、V8 10.6 和 Node.js 16.16.0 的升级。请阅读下文了解更多详情!
¥Electron 21.0.0 has been released! It includes upgrades to Chromium 106, V8 10.6, and Node.js 16.16.0. Read below for more details!
Electron 团队非常高兴地宣布 Electron 21.0.0 正式发布!你可以通过 npm install electron@latest 使用 npm 安装它,也可以从我们的 发布网站。继续阅读以了解有关此版本的详细信息。
¥The Electron team is excited to announce the release of Electron 21.0.0! You can install it with npm via npm install electron@latest or download it from our releases website. Continue reading for details about this release.
如果你有任何反馈,请在 Twitter 上与我们分享,或加入我们的社区 Discord!可以在 Electron 的 问题跟踪器 中报告错误和功能请求。
¥If you have any feedback, please share it with us on Twitter, or join our community Discord! Bugs and feature requests can be reported in Electron's issue tracker.
¥Electron 21 enables V8 sandboxed pointers, following Chrome's decision to do the same in Chrome 103. This has some implications for native modules. This feature has performance and security benefits, but also places some new restrictions on native modules, e.g. use of ArrayBuffers that point to external ("off-heap") memory. Please see this blog post for more information. #34724
Electron 18.x.y 已根据项目 支持政策 终止支持。建议开发者和应用升级到较新版本的 Electron。
¥Electron 18.x.y has reached end-of-support as per the project's support policy. Developers and applications are encouraged to upgrade to a newer version of Electron.
短期内,你可以预期团队将继续专注于跟上构成 Electron 的主要组件(包括 Chromium、Node 和 V8)的开发。
¥In the short term, you can expect the team to continue to focus on keeping up with the development of the major components that make up Electron, including Chromium, Node, and V8.
Electron 20.0.0 已发布!它包含对 Chromium 104、V8 10.4 和 Node.js 16.15.0 的升级。请阅读下文了解更多详情!
¥Electron 20.0.0 has been released! It includes upgrades to Chromium 104, V8 10.4, and Node.js 16.15.0. Read below for more details!
Electron 团队非常高兴地宣布 Electron 20.0.0 正式发布!你可以通过 npm install electron@latest 使用 npm 安装它,也可以从我们的 发布网站。继续阅读以了解有关此版本的详细信息,并请分享你的任何反馈!
¥The Electron team is excited to announce the release of Electron 20.0.0! You can install it with npm via npm install electron@latest or download it from our releases website. Continue reading for details about this release and please share any feedback you have!
以下是 Electron 20 中引入的重大变更。有关这些变更和未来变更的更多信息,请参阅 计划中的突发事件变更 页面。
¥Below are breaking changes introduced in Electron 20. More information about these and future changes can be found on the Planned Breaking Changes page.
¥Default Changed: renderers without nodeIntegration: true are sandboxed by default
以前,指定预加载脚本的渲染器默认为未沙箱化。这意味着默认情况下,预加载脚本可以访问 Node.js。在 Electron 20 中,这个默认值已经改变。从 Electron 20 开始,渲染器将默认被沙箱化,除非指定了 nodeIntegration: true 或 sandbox: false。
¥Previously, renderers that specified a preload script defaulted to being unsandboxed. This meant that by default, preload scripts had access to Node.js. In Electron 20, this default has changed. Beginning in Electron 20, renderers will be sandboxed by default, unless nodeIntegration: true or sandbox: false is specified.
¥If your preload scripts do not depend on Node, no action is needed. If your preload scripts do depend on Node, either refactor them to remove Node usage from the renderer, or explicitly specify sandbox: false for the relevant renderers.
¥Fixed: spontaneous crashing in nan native modules
在 Electron 20 中,我们更改了两项与原生模块相关的内容:
¥In Electron 20, we changed two items related to native modules:
V8 的头文件现在默认使用 c++17。此标志已添加到 electron-rebuild 中。
¥V8 headers now use c++17 by default. This flag was added to electron-rebuild.
我们修复了缺少 include 会导致依赖于 nan 的原生模块自发崩溃的问题。
¥We fixed an issue where a missing include would cause spontaneous crashing in native modules that depended on nan.
为了获得最高的稳定性,我们建议在重新构建原生模块(尤其是依赖于 nan 的模块)时使用 node-gyp >=8.4.0 和 electron-rebuild >=3.2.9。请参阅 electron #35160 和 node-gyp #2497 了解更多信息。
¥For the most stability, we recommend using node-gyp >=8.4.0 and electron-rebuild >=3.2.9 when rebuilding native modules, particularly modules that depend on nan. See electron #35160 and node-gyp #2497 for more information.
在 X11 上,skipTaskbar 向 X11 窗口管理器发送 _NET_WM_STATE_SKIP_TASKBAR 消息。Wayland 没有直接的等效项,并且已知的解决方法具有不可接受的权衡(例如 GNOME 中的 Window.is_skip_taskbar 需要不安全模式),因此 Electron 无法在 Linux 上支持此功能。
¥On X11, skipTaskbar sends a _NET_WM_STATE_SKIP_TASKBAR message to the X11 window manager. There is not a direct equivalent for Wayland, and the known workarounds have unacceptable tradeoffs (e.g. Window.is_skip_taskbar in GNOME requires unsafe mode), so Electron is unable to support this feature on Linux.
Electron 17.x.y 已根据项目 支持政策 终止支持。建议开发者和应用升级到较新版本的 Electron。
¥Electron 17.x.y has reached end-of-support as per the project's support policy. Developers and applications are encouraged to upgrade to a newer version of Electron.
短期内,你可以预期团队将继续专注于跟上构成 Electron 的主要组件(包括 Chromium、Node 和 V8)的开发。虽然我们谨慎地不对发布日期做出承诺,但我们计划大约每两个月发布一次 Electron 的新主要版本及其组件的新版本。
¥In the short term, you can expect the team to continue to focus on keeping up with the development of the major components that make up Electron, including Chromium, Node, and V8. Although we are careful not to make promises about release dates, our plan is to release new major versions of Electron with new versions of those components approximately every 2 months.
¥To track ongoing discussion about native module usage in Electron 21+, see electron/electron#35801.
在 Electron 21 中,我们将在 Electron 中启用 V8 沙盒指针,紧随 Chrome 的 决定在 Chrome 103 中也采取同样的措施 之后。这对原生模块有一些影响。此外,我们之前在 Electron 14 中启用了相关技术 指针压缩。当时我们并没有过多讨论指针压缩,但指针压缩确实会影响 V8 的最大堆大小。
¥In Electron 21, we will be enabling V8 sandboxed pointers in Electron, following Chrome's decision to do the same in Chrome 103. This has some implications for native modules. Also, we previously enabled a related technology, pointer compression, in Electron 14. We didn't talk about it much then, but pointer compression has implications for the maximum V8 heap size.
启用这两项技术后,将显著提升安全性、性能和内存使用率。然而,启用它们也有一些缺点。
¥These two technologies, when enabled, are significantly beneficial for security, performance and memory usage. However, there are some downsides to enabling them, too.
启用沙盒指针的主要缺点是指向外部("off-heap")内存的 ArrayBuffer 不再被允许。这意味着依赖于 V8 中此功能的原生模块需要重构才能继续在 Electron 20 及更高版本中工作。
¥The main downside of enabling sandboxed pointers is that ArrayBuffers which point to external ("off-heap") memory are no longer allowed. This means that native modules which rely on this functionality in V8 will need to be refactored to continue working in Electron 20 and later.
¥The main downside of enabling pointer compression is that the V8 heap is limited to a maximum size of 4GB. The exact details of this are a little complicated—for example, ArrayBuffers are counted separately from the rest of the V8 heap, but have their own limits.
¥The Electron Upgrades Working Group believes that the benefits of pointer compression and the V8 memory cage outweigh the downsides. There are three main reasons for doing so:
¥It keeps Electron closer to Chromium. The less Electron diverges from Chromium in complex internal details such as V8 configuration, the less likely we are to accidentally introduce bugs or security vulnerabilities. Chromium's security team is formidable, and we want to make sure we are taking advantage of their work. Further, if a bug only affects configurations that aren't used in Chromium, fixing it is not likely to be a priority for the Chromium team.
更安全。一些 Electron 应用运行不受信任的 JavaScript(希望遵循我们的 安全建议!),对于这些应用,启用 V8 内存笼可以保护它们免受大量 V8 漏洞的攻击。
¥It's more secure. Some Electron apps run untrusted JavaScript (hopefully following our security recommendations!), and for those apps, having the V8 memory cage enabled protects them from a large class of nasty V8 vulnerabilities.
最后,对于确实需要更大堆大小的应用,有一些解决方法。例如,你可以在你的应用中包含一个 Node.js 副本,该副本在构建时禁用了指针压缩,并将占用大量内存的工作移至子进程。虽然有些复杂,但如果你决定根据特定用例进行不同的权衡,也可以构建一个禁用指针压缩的自定义 Electron 版本。最后,在不久的将来,wasm64 将允许使用 WebAssembly 在 Web 和 Electron 中构建的应用使用超过 4GB 的内存。
¥Lastly, there are workarounds for apps that really need a larger heap size. For example, it is possible to include a copy of Node.js with your app, which is built with pointer compression disabled, and move the memory-intensive work to a child process. Though somewhat complicated, it is also possible to build a custom version of Electron with pointer compression disabled, if you decide you want a different trade-off for your particular use case. And lastly, in the not-too-distant future, wasm64 will allow apps built with WebAssembly both on the Web and in Electron to use significantly more than 4GB of memory.
¥If you don't use any native Node modules in your app, you're safe—there's no way to trigger this crash from pure JS. This change only affects native Node modules which allocate memory outside of the V8 heap (e.g. using malloc or new) and then wrap the external memory with an ArrayBuffer. This is a fairly rare use case, but some modules do use this technique, and such modules will need to be refactored in order to be compatible with Electron 20+.
¥Some documents refer to it as the "V8 sandbox", but that term is easily confusable with other kinds of sandboxing that happen in Chromium, so I'll stick to the term "memory cage".
有一种相当常见的 V8 漏洞利用方式如下:
¥There's a fairly common kind of V8 exploit that goes something like this:
¥Find a bug in V8's JIT engine. JIT engines analyze code in order to be able to omit slow runtime type checks and produce fast machine code. Sometimes logic errors mean it gets this analysis wrong, and omits a type check that it actually needed—say, it thinks x is a string, but in fact it's an object.
利用这种混淆来覆盖 V8 堆中的部分内存,例如,指向 ArrayBuffer 开头的指针。
¥Abuse this confusion to overwrite some bit of memory inside the V8 heap, for instance, the pointer to the beginning of an ArrayBuffer.
¥Now you have an ArrayBuffer that points wherever you like, so you can read and write any memory in the process, even memory that V8 normally doesn't have access to.
¥The V8 memory cage is a technique designed to categorically prevent this kind of attack. The way this is accomplished is by not storing any pointers in the V8 heap. Instead, all references to other memory inside the V8 heap are stored as offsets from the beginning of some reserved region. Then, even if an attacker manages to corrupt the base address of an ArrayBuffer, for instance by exploiting a type confusion error in V8, the worst they can do is read and write memory inside the cage, which they could likely already do anyway.
There's a lot more available to read on how the V8 memory cage works, so I won't go into further detail here—the best place to start reading is probably the high-level design doc from the Chromium team.
¥There are two ways to go about refactoring a native module to be compatible with the V8 memory cage. The first is to copy externally-created buffers into the V8 memory cage before passing them to JavaScript. This is generally a simple refactor, but it can be slow when the buffers are large. The other approach is to use V8's memory allocator to allocate memory which you intend to eventually pass to JavaScript. This is a bit more involved, but will allow you to avoid the copy, meaning better performance for large buffers.
为了更具体说明,以下是一个使用外部数组缓冲区的 N-API 模块示例:
¥To make this more concrete, here's an example N-API module that uses external array buffers:
// Create some externally-allocated buffer. // |create_external_resource| allocates memory via malloc(). size_t length =0; void* data =create_external_resource(&length); // Wrap it in a Buffer--will fail if the memory cage is enabled! napi_value result; napi_create_external_buffer( env, length, data, finalize_external_resource,NULL,&result);
¥This will crash when the memory cage is enabled, because data is allocated outside the cage. Refactoring to instead copy the data into the cage, we get:
size_t length =0; void* data =create_external_resource(&length); // Create a new Buffer by copying the data into V8-allocated memory napi_value result; void* copied_data =NULL; napi_create_buffer_copy(env, length, data,&copied_data,&result); // If you need to access the new copy, |copied_data| is a pointer // to it!
¥This will copy the data into a newly-allocated memory region that is inside the V8 memory cage. Optionally, N-API can also provide a pointer to the newly-copied data, in case you need to modify or reference it after the fact.
¥Refactoring to use V8's memory allocator is a little more complicated, because it requires modifying the create_external_resource function to use memory allocated by V8, instead of using malloc. This may be more or less feasible, depending on whether or not you control the definition of create_external_resource. The idea is to first create the buffer using V8, e.g. with napi_create_buffer, and then initialize the resource into the memory that has been allocated by V8. It is important to retain a napi_ref to the Buffer object for the lifetime of the resource, otherwise V8 may garbage-collect the Buffer and potentially result in use-after-free errors.
Electron 19.0.0 已发布!它包含对 Chromium 102、V8 10.2 和 Node.js 16.14.2 的升级。请阅读下文了解更多详情!
¥Electron 19.0.0 has been released! It includes upgrades to Chromium 102, V8 10.2, and Node.js 16.14.2. Read below for more details!
Electron 团队非常高兴地宣布 Electron 19.0.0 正式发布!你可以通过 npm install electron@latest 使用 npm 安装它,也可以从我们的 发布网站。继续阅读以了解有关此版本的详细信息,并请分享你的任何反馈!
¥The Electron team is excited to announce the release of Electron 19.0.0! You can install it with npm via npm install electron@latest or download it from our releases website. Continue reading for details about this release and please share any feedback you have!
该项目正在恢复其先前的支持最新三个主要版本的政策。查看我们的版本控制文档 了解 Electron 版本控制和支持的更多详细信息。为了帮助用户适应从 Electron 15 开始的新发布节奏,我们暂时将其分为四个主要版本。你可以阅读 完整详情请见此处。
¥The project is returning to its earlier policy of supporting the latest three major versions. See our versioning document for more detailed information about Electron versioning and support. This had temporarily been four major versions to help users adjust to the new release cadence that began in Electron 15. You can read the full details here.
以下是 Electron 19 中引入的重大变更。有关这些变更和未来变更的更多信息,请参阅 计划中的突发事件变更 页面。
¥Below are breaking changes introduced in Electron 19. More information about these and future changes can be found on the Planned Breaking Changes page.
Electron 14.x.y 和 15.x.y 均已终止支持。此 returns Electron 更新至其 现有政策,支持最新的三个主要版本。建议开发者和应用升级到较新版本的 Electron。
¥Electron 14.x.y and 15.x.y have both reached end-of-support. This returns Electron to its existing policy of supporting the latest three major versions. Developers and applications are encouraged to upgrade to a newer version of Electron.
短期内,你可以预期团队将继续专注于跟上构成 Electron 的主要组件(包括 Chromium、Node 和 V8)的开发。虽然我们谨慎地不对发布日期做出承诺,但我们计划大约每两个月发布一次 Electron 的新主要版本及其组件的新版本。
¥In the short term, you can expect the team to continue to focus on keeping up with the development of the major components that make up Electron, including Chromium, Node, and V8. Although we are careful not to make promises about release dates, our plan is to release new major versions of Electron with new versions of those components approximately every 2 months.
¥A significant amount of Electron's build artifacts are uploaded to an S3 bucket called gh-contractor-zcbenz. As part of ongoing infrastructure/ownership migrations that started way back in 2020, we will be changing everything that used gh-contractor-zcbenz from its old home in S3 to a new storage system hosted at https://artifacts.electronjs.org. The path prefix that most of our assets use is changing slightly as well. Examples are included below:
¥Anyone using standard build tooling such as electron-rebuild, electron-packager or @electron/get won't have to do anything. This should be the majority of people.
对于直接引用 S3 存储桶的任何人,你必须更新引用以指向主机名并更新路径。
¥For anyone directly referencing the S3 bucket, you must update your reference to point at the hostname and update the path as well.
¥Most data that existed on the gh-contractor-zcbenz bucket has been cloned into the new storage system. This means all debug symbols and all headers have been copied. If you relied on some data in that bucket that hasn't been copied over please raise an issue in electron/electron and let us know.
¥The current gh-contractor-zcbenz S3 bucket will not be actively deleted. However, we can't guarantee how long that bucket will be left alive. We strongly recommend updating to target the new bucket as soon as possible.
Electron 18.0.0 已发布!它包含对 Chromium 100、V8 10.0 和 Node.js 16.13.2 的升级。请阅读下文了解更多详情!
¥Electron 18.0.0 has been released! It includes upgrades to Chromium 100, V8 10.0, and Node.js 16.13.2. Read below for more details!
Electron 团队非常高兴地宣布 Electron 18.0.0 正式发布!你可以通过 npm install electron@latest 使用 npm 安装它,也可以从我们的 发布网站。继续阅读以了解有关此版本的详细信息,并请分享你的任何反馈!
¥The Electron team is excited to announce the release of Electron 18.0.0! You can install it with npm via npm install electron@latest or download it from our releases website. Continue reading for details about this release and please share any feedback you have!
¥Additionally, Electron has changed supported versions from latest three versions to latest four versions until May 2022. See our versioning document for more detailed information about versioning in Electron. After May 2022, we will return to supporting latest three versions.
¥Added a first-instance-ack event to the app.requestSingleInstanceLock() flow, allowing users to seamlessly transmit data from the first instance to the second instance. #31460
以下是 Electron 18 中引入的重大变更。有关这些变更和未来变更的更多信息,请参阅 计划中的突发事件变更 页面。
¥Below are breaking changes introduced in Electron 18. More information about these and future changes can be found on the Planned Breaking Changes page.
在 Electron 15 之前,window.open 默认情况下使用 BrowserWindowProxy。这意味着 window.open('about:blank') 无法打开同步可编写脚本的子窗口,以及其他不兼容性。从 Electron 15 开始,nativeWindowOpen 已默认启用。
¥Prior to Electron 15, window.open was by default shimmed to use BrowserWindowProxy. This meant that window.open('about:blank') did not work to open synchronously scriptable child windows, among other incompatibilities. Since Electron 15, nativeWindowOpen has been enabled by default.
Electron 14.x.y 已根据项目 支持政策 终止支持。建议开发者和应用升级到较新版本的 Electron。
¥Electron 14.x.y has reached end-of-support as per the project's support policy. Developers and applications are encouraged to upgrade to a newer version of Electron.
从 Electron 15 开始,我们已将支持的版本从最新的三个版本更改为最新的四个版本,直至 2022 年 5 月 Electron 19 的发布。Electron 19 发布后,我们将恢复对最新三个版本的支持。此版本支持更改是我们新节奏更改的一部分。请参阅 我们的博客文章,详情请点击此处。
¥As of Electron 15, we have changed supported versions from latest three versions to latest four versions until May 2022 with Electron 19. After Electron 19, we will return to supporting the latest three versions. This version support change is part of our new cadence change. Please see our blog post for full details here.
短期内,你可以预期团队将继续专注于跟上构成 Electron 的主要组件(包括 Chromium、Node 和 V8)的开发。虽然我们谨慎地不对发布日期做出承诺,但我们计划大约每两个月发布一次 Electron 的新主要版本及其组件的新版本。
¥In the short term, you can expect the team to continue to focus on keeping up with the development of the major components that make up Electron, including Chromium, Node, and V8. Although we are careful not to make promises about release dates, our plan is to release new major versions of Electron with new versions of those components approximately every 2 months.
Google Summer of Code (GSoC) 是一项年度指导计划,旨在将开源软件项目与潜在贡献者联系起来。以前仅对学生开放,现在任何 18 岁及以上的人都可以注册 GSoC。
¥Google Summer of Code (GSoC) is a yearly mentoring program connecting open source software projects with potential contributors. Previously open only to students, anyone ages 18 and up can now register for GSoC.
¥Want to apply? First, check out the five project idea drafts that we have prepared. All of the listed ideas are currently open for proposals. We are also open to accepting new ideas that are not on the proposed project list.
你的应用应包含:
¥Your application should include:
你的提案,即一份书面文件,详细描述了你计划在夏季实现的目标。
¥Your proposal, which is a written document that describes in detail what you plan to achieve over the course of the summer.
你的开发者背景。如果你有简历,请附上副本;否则,请描述你的过去经验,并着重介绍相关的技术经验。
¥Your background as a developer. If you have a resume, please include a copy, otherwise tell us about your past experience with an emphasis on relevant technical experience.