Skip to main content

Electron 6.0.0

· 10 min read

Electron 团队非常高兴地宣布 Electron 6.0.0 正式发布!你可以通过 npm install electron@latest 使用 npm 安装它,也可以从我们的 发布网站。此版本包含升级、修复和新功能。我们迫不及待地想看看你使用它们构建的内容!继续阅读以了解有关此版本的详细信息,并请分享你的任何反馈!

¥The Electron team is excited to announce the release of Electron 6.0.0! You can install it with npm via npm install electron@latest or download it from our releases website. The release is packed with upgrades, fixes, and new features. We can't wait to see what you build with them! Continue reading for details about this release, and please share any feedback you have!


新功能

¥What's New

今天是 Electron 项目的首次亮相:这是我们首次在 Chrome 稳定版本 发布的同一天发布稳定的 Electron 版本!🎉

¥Today marks a first for the Electron project: this is the first time we've made a stable Electron release on the same day as the corresponding Chrome stable release! 🎉

Electron 的大部分功能由 Chromium、Node.js 和 V8 的核心组件提供。Electron 会持续关注这些项目,为我们的用户提供新的 JavaScript 功能、性能改进和安全修复。以下每个软件包在 Electron 6 中都有一个主要版本升级:

¥Much of Electron's functionality is provided by the core components of Chromium, Node.js, and V8. Electron keeps up-to-date with these projects to provide our users with new JavaScript features, performance improvements, and security fixes. Each of these packages has a major version bump in Electron 6:

此版本还包含对 Electron API 的改进。发行说明 有更完整的列表,但以下是重点内容:

¥This release also includes improvements to Electron's APIs. The release notes have a more complete list, but here are the highlights:

Promisification

Electron 6.0 延续了 5.0 版中启动的 initiative 现代化升级,以增强对 Promise 的支持。

¥Electron 6.0 continues the modernization initiative started in 5.0 to improve Promise support.

这些函数现在返回 Promises,并且仍然支持旧版基于回调的调用:

¥These functions now return Promises and still support older callback-based invocation:

  • contentTracing.getCategories() #16583

  • contentTracing.getCategories() #16583

  • contentTracing.getTraceBufferUsage() #16600

  • contents.executeJavaScript() #17312

  • cookies.flushStore() #16464

  • cookies.get() #16464

  • cookies.remove() #16464

  • cookies.set() #16464

  • dialog.showCertificateTrustDialog() #17181

  • inAppPurchase.getProducts() #17355

  • inAppPurchase.purchaseProduct()#17355

  • netLog.stopLogging() #16862

  • session.clearAuthCache() #17259

  • session.clearCache() #17185

  • session.clearHostResolverCache() #17229

  • session.clearStorageData() #17249

  • session.getBlobData() #17303

  • session.getCacheSize() #17185

  • session.resolveProxy() #17222

  • session.setProxy() #17222

  • webContents.hasServiceWorker() #16535

  • webContents.printToPDF() #16795

  • webContents.savePage() #16742

  • webFrame.executeJavaScript() #17312

  • webFrame.executeJavaScriptInIsolatedWorld() #17312

  • webviewTag.executeJavaScript() #17312

这些函数现在有两种形式:同步和基于 Promise 的异步:

¥These functions now have two forms, synchronous and Promise-based asynchronous:

  • dialog.showMessageBox()/dialog.showMessageBoxSync() #17298

  • dialog.showOpenDialog()/dialog.showOpenDialogSync() #16973

  • dialog.showSaveDialog()/dialog.showSaveDialogSync() #17054

这些函数现在返回 Promises:

¥These functions now return Promises:

Electron Helper (Renderer).appElectron Helper (GPU).appElectron Helper (Plugin).app

¥Electron Helper (Renderer).app, Electron Helper (GPU).app and Electron Helper (Plugin).app

为了启用 强化运行时(它会限制可写可执行内存以及加载由不同 Team ID 签名的代码等操作),需要为 Helper 授予特殊的代码签名权限。

¥In order to enable the hardened runtime, which restricts things like writable-executable memory and loading code signed by a different Team ID, special code signing entitlements needed to be granted to the Helper.

为了将这些权限限定在需要它们的进程类型内,Chromium added 提供了三个新的 Helper 应用变体:一个用于渲染器 (Electron Helper (Renderer).app),一个用于 GPU 进程 (Electron Helper (GPU).app),一个用于插件 (Electron Helper (Plugin).app)。

¥To keep these entitlements scoped to the process types that require them, Chromium added three new variants of the Helper app: one for renderers (Electron Helper (Renderer).app), one for the GPU process (Electron Helper (GPU).app) and one for plugins (Electron Helper (Plugin).app).

使用 electron-osx-sign 对其 Electron 应用进行协同设计的用户无需对其构建逻辑进行任何更改。如果你使用自定义脚本对应用进行代码签名,则应确保三个新的辅助应用已正确进行代码签名。

¥Folks using electron-osx-sign to codesign their Electron app shouldn't have to make any changes to their build logic. If you're codesigning your app with custom scripts, you should ensure that the three new Helper applications are correctly codesigned.

为了正确使用这些新的 Helper 打包你的应用,你需要使用 electron-packager@14.0.4 或更高版本。如果你使用的是 electron-builder,则应该关注 这个问题 来跟踪对这些新助手的支持情况。

¥In order to package your application correctly with these new helpers you need to be using electron-packager@14.0.4 or higher. If you are using electron-builder you should follow this issue to track support for these new helpers.

重大变化

¥Breaking Changes

  • 此版本开始为未来在渲染器进程中加载​​的原生 Node 模块必须是 N-API上下文感知 的要求奠定基础。此次变更的原因是性能提升、安全性增强以及维护工作量减少。请阅读 这个问题 中包括建议的时间表在内的完整详情。此更改预计将在 Electron v11 中完成。

    ¥This release begins laying the groundwork for a future requirement that native Node modules loaded in the renderer process be either N-API or Context Aware. The reasons for this change are faster performance, stronger security, and reduced maintenance workload. Read the full details including the proposed timeline in this issue. This change is expected to be completed in Electron v11.

  • net.IncomingMessage 的标头包含 略有改动,以便与 Node.js 行为 更加匹配,尤其是在 set-cookie 的值以及如何处理重复标头方面。#17517

    ¥net.IncomingMessage headers have changed slightly to more closely match Node.js behavior, particularly with the value of set-cookie and how duplicate headers are handled. #17517.

  • shell.showItemInFolder() 现在返回 void 并且是异步调用。#17121

    ¥shell.showItemInFolder() now returns void and is an asynchronous call. #17121

  • 现在,应用在使用 app.getPath('log') 之前必须通过调用新函数 app.setAppLogPath() 明确设置日志路径。#17841

    ¥Apps must now explicitly set a log path by calling the new function app.setAppLogPath() before using app.getPath('log'). #17841

3.x.y 支持终止

¥End of Support for 3.x.y

根据我们的 支持政策,3.x.y 版本已达到生命周期终点。建议开发者和应用升级到较新版本的 Electron。

¥Per our support policy, 3.x.y has reached end of life. Developers and applications are encouraged to upgrade to a newer version of Electron.

应用反馈计划

¥App Feedback Program

我们继续使用我们的 应用反馈计划 进行测试。参与此计划的项目在其应用上测试 Electron 测试版;作为回报,他们发现的新 bug 将优先发布到稳定版本。如果你想参与或了解更多信息,请联系 查看我们关于该程序的博客文章

¥We continue to use our App Feedback Program for testing. Projects who participate in this program test Electron betas on their apps; and in return, the new bugs they find are prioritized for the stable release. If you'd like to participate or learn more, check out our blog post about the program.

下一步计划

¥What's Next

短期内,你可以预期团队将继续专注于跟上构成 Electron 的主要组件(包括 Chromium、Node 和 V8)的开发。虽然我们谨慎地不对发布日期做出承诺,但我们计划大约每季度发布一次 Electron 的新主要版本及其组件的新版本。暂定 7.0.0 计划 模块列出了 Electron 7 开发生命周期中的关键日期。此外,查看我们的版本控制文档 提供了有关 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 release new major versions of Electron with new versions of those components approximately quarterly. The tentative 7.0.0 schedule maps out key dates in the Electron 7 development life cycle. Also, see our versioning document for more detailed information about versioning in Electron.

有关即将推出的 Electron 版本 查看我们的“计划重大变更”文档 中计划的重大变更的信息。

¥For information on planned breaking changes in upcoming versions of Electron, see our Planned Breaking Changes doc.

新的 Electron 发布节奏

· 7 min read
⚡ 更新 (2021-07-14):我们的速度更快了!

2021 年第三季度,Chrome 团队将 提高了发布节奏 的发布频率从每 6 周缩短至每 4 周。Electron 的版本也紧随其后。请阅读更新的 8 周发行周期 博客文章以获取更多最新信息!

¥In Q3 2021, the Chrome team increased their release cadence from every 6 weeks to every 4 weeks. Electron's releases have followed suit. Please read the updated 8 week cadence blog post for more up-to-date information!

🎉 Electron 计划每 12 周发布一个新的主要稳定版本!🎉

¥🎉 Electron is moving to release a new major stable version every 12 weeks! 🎉


⚡ 哇,真快!但是为什么?

¥⚡️ Wow that's quick! But why?

简而言之,Chromium 不会停止发布,因此 Electron 的速度也不会减慢。

¥Simply put, Chromium doesn't stop shipping so Electron is not going to slow down either.

Chromium 每 6 周发布一次 schedule 版本。为了在 Electron 中提供最新版本的 Chromium,我们的进度安排需要与 Electron 保持一致。更多关于 Chromium 发布周期的信息,请参阅 此处

¥Chromium releases on a consistent 6-week schedule. To deliver the most up-to-date versions of Chromium in Electron, our schedule needs to track theirs. More information around Chromium's release cycle can be found here.

🚀 为什么每 12 周更新一次?

¥🚀 Why every 12 weeks?

每 6 周,Chromium 都会发布一个新的版本,其中包含新功能、错误修复/安全修复以及 V8 引擎改进。Electron 的用户一直明确表示希望及时进行这些更改,因此我们调整了稳定版本的发布日期,以匹配其他所有 Chromium 稳定版本。首先,Electron v6.0.0 将包含 M76,并计划于 2019 年 7 月 30 日(与 Chromium M76 同一天)发布稳定版本。

¥Every 6 weeks, a new Chromium release comes out with new features, bug fixes / security fixes, and V8 improvements. Electron's users have been loud and clear about wanting these changes in a timely manner, so we've adjusted our stable release dates to match every other Chromium stable release. Up first, Electron v6.0.0 will include M76 and is scheduled for stable release on July 30, 2019, the same release day as Chromium M76.

🚧 这对我和我的 Electron 应用意味着什么?

¥🚧 What does this mean for me and my Electron app?

你将比以前更快地使用新的 Chromium 和 V8 功能和修复。重要的是,你还会知道这些新变化何时到来,因此你可以比以前更好地规划。

¥You'll have access to new Chromium and V8 features and fixes sooner than before. Importantly, you'll also know when those new changes are coming, so you'll be able to plan with better information than before.

Electron 团队将 继续支持 最新的三个主要版本。例如,在 v6.0.0 于 2019 年 7 月 30 日稳定发布 版本中,我们将支持 v6.x、v5.x 和 v4.x,而 v3.x 将终止支持。

¥The Electron team will continue to support the latest three major versions. For example, when v6.0.0 goes stable on July 30, 2019, we will support v6.x, v5.x, and v4.x, while v3.x will reach End-Of-Life.

💬 应用反馈计划

¥💬 App Feedback Program

请考虑加入我们的 应用反馈计划,帮助我们测试 Beta 版本并进行稳定化。参与此计划的项目在其应用上测试 Electron 测试版;作为回报,他们发现的新 bug 将优先发布到稳定版本。

¥Please consider joining our App Feedback Program to help us with testing our beta releases and stabilization. Projects who participate in this program test Electron betas on their apps; and in return, the new bugs they find are prioritized for the stable release.

📝 Electron 发布简史

¥📝 A brief history of Electron releases

v3.0.0 之前的稳定版本决策并未遵循既定时间表。我们在 v3.0.0 和 v4.0.0 版本中为项目添加了内部调度机制。今年早些时候,我们决定首次公布 Electron v5.0.0 的稳定发布日期。我们宣布稳定版本发布日期总体上获得了积极的反响,我们很高兴在未来的版本中继续保持这种势头。

¥The decisions around stable releases before v3.0.0 did not follow a schedule. We added internal schedules to the project with v3.0.0 and v4.0.0. Earlier this year, we decided to publicize our stable release date for the first time for Electron v5.0.0. Announcing our stable release dates was positively received overall and we're excited to continue doing that for future releases.

为了更好地简化这些与升级相关的工作,我们在 治理 系统内创建了 升级发布 工作组。它们使我们能够更好地确定工作的优先级并委派任务,我们希望这一点在后续的每个版本中都能更加明显。

¥In order to better streamline these upgrade-related efforts, our Upgrades and Releases Working Groups were created within our Governance system. They have allowed us to better prioritize and delegate this work, which we hope will become more apparent with each subsequent release.

以下是我们新的开发节奏与 Chromium 的开发节奏对比:比较 Electron 和 Chromium 版本的折线图

¥Here is where our new cadence will put us in comparison to Chromium's cadence: line graph comparing Electron versus Chromium versions

📨 如果你有任何疑问,请发送邮件至 info@electronjs.org

¥📨 If you have questions, please mail us at info@electronjs.org.

Electron 5.0.0

· 10 min read

Electron 团队非常高兴地宣布 Electron 5.0.0 正式发布!你可以通过 npm install electron@latest 使用 npm 安装它,也可以从 我们的发布页面 下载 tarball。此版本包含升级、修复和新功能。我们迫不及待地想看看你使用它们构建的内容!继续阅读以了解有关此版本的详细信息,并请分享你的任何反馈!

¥The Electron team is excited to announce the release of Electron 5.0.0! You can install it with npm via npm install electron@latest or download the tarballs from our releases page. The release is packed with upgrades, fixes, and new features. We can't wait to see what you build with them! Continue reading for details about this release, and please share any feedback you have!


有什么新功能?

¥What's New?

Electron 的大部分功能由 Chromium、Node.js 和 V8 的核心组件提供。Electron 会持续关注这些项目,为我们的用户提供新的 JavaScript 功能、性能改进和安全修复。以下每个软件包在 Electron 5 中都有一个主要版本升级:

¥Much of Electron's functionality is provided by the core components of Chromium, Node.js, and V8. Electron keeps up-to-date with these projects to provide our users with new JavaScript features, performance improvements, and security fixes. Each of these packages has a major version bump in Electron 5:

Electron 5 还包含对 Electron 特定 API 的改进。主要变更摘要如下:查看完整的变更列表,请查看 Electron v5.0.0 版本说明

¥Electron 5 also includes improvements to Electron-specific APIs. A summary of the major changes is below; for the full list of changes, check out the Electron v5.0.0 release notes.

Promisification

Electron 5 延续了 Promisification 倡议 的计划,将 Electron 基于回调的 API 转换为使用 Promises。以下 API 已针对 Electron 5 进行转换:

¥Electron 5 continues Promisification initiative initiative to convert Electron's callback-based API to use Promises. These APIs were converted for Electron 5:

  • app.getFileIcon

  • contentTracing.getCategories

  • contentTracing.startRecording

  • contentTracing.stopRecording

  • debugger.sendCommand

  • Cookies API

  • shell.openExternal

  • webContents.loadFile

  • webContents.loadURL

  • webContents.zoomLevel

  • webContents.zoomFactor

  • win.capturePage

macOS 的系统颜色访问

¥System colors access for macOS

这些函数已更改或添加到 systemPreferences,以访问 macOS 系统的颜色:

¥These functions were changed or added to systemPreferences to access macOS systems' colors:

  • systemPreferences.getAccentColor

  • systemPreferences.getColor

  • systemPreferences.getSystemColor

进程内存信息

¥Process memory information

已添加函数 process.getProcessMemoryInfo 以获取有关当前进程的内存使用情况统计信息。

¥The function process.getProcessMemoryInfo has been added to get memory usage statistics about the current process.

远程 API 的额外筛选功能

¥Additional filtering for remote APIs

为了提高 remote API 的安全性,添加了新的远程事件,以便 remote.getBuiltinremote.getCurrentWindowremote.getCurrentWebContents<webview>.getWebContents 可以作为 filtered 使用。

¥To improve security in the remote API, new remote events have been added so that remote.getBuiltin, remote.getCurrentWindow, remote.getCurrentWebContents and <webview>.getWebContents can be filtered.

浏览器窗口上的多个浏览器视图

¥Multiple BrowserViews on BrowserWindow

BrowserWindow 现在支持在同一个 BrowserWindow 中管理多个 BrowserView。

¥BrowserWindow now supports managing multiple BrowserViews within the same BrowserWindow.

重大变化

¥Breaking Changes

打包应用的默认值

¥Defaults for packaged apps

打包应用现在的行为与默认应用相同:除非应用本身有默认菜单,否则将创建默认应用菜单;除非应用处理该事件,否则将自动处理 window-all-closed 事件。

¥Packaged apps will now behave the same as the default app: a default application menu will be created unless the app has one and the window-all-closed event will be automatically handled unless the app handles the event.

混合沙盒

¥Mixed sandbox

混合沙盒模式现已默认启用。使用 sandbox: true 启动的渲染器现在将真正处于沙盒状态,而以前只有在启用混合沙盒模式时才会处于沙盒状态。

¥Mixed sandbox mode is now enabled by default. Renderers launched with sandbox: true will now be actually sandboxed, where previously they would only be sandboxed if mixed-sandbox mode was also enabled.

安全性改进

¥Security improvements

为了提高安全性,nodeIntegrationwebviewTag 的默认值现已改为 false

¥The default values of nodeIntegration and webviewTag are now false to improve security.

拼写检查器现在异步

¥Spellchecker now asynchronous

SpellCheck API 已更改为提供 异步结果

¥The SpellCheck API has been changed to provide asynchronous results.

弃用

¥Deprecations

以下 API 在 Electron 5.0.0 中被弃用,并计划在 6.0.0 中删除:

¥The following APIs are newly deprecated in Electron 5.0.0 and planned for removal in 6.0.0:

适用于 arm 和 arm64 的 Mksnapshot 二进制文件

¥Mksnapshot binaries for arm and arm64

mksnapshot 的 arm 和 arm64 原生二进制文件已弃用,并将在 6.0.0 版本中移除。可以使用 x64 二进制文件为 arm 和 arm64 创建快照。

¥Native binaries of mksnapshot for arm and arm64 are deprecated and will be removed in 6.0.0. Snapshots can be created for arm and arm64 using the x64 binaries.

WebContents 上的 ServiceWorker API

¥ServiceWorker APIs on WebContents

已弃用 WebContents 上的 ServiceWorker API,准备将其移除。

¥Deprecated ServiceWorker APIs on WebContents in preparation for their removal.

  • webContents.hasServiceWorker

  • webContents.unregisterServiceWorker

带有沙盒 webContents 的自动模块

¥Automatic modules with sandboxed webContents

为了提高安全性,以下模块已弃用,无法通过 require 直接使用,而是需要通过 remote.require 将其包含在沙盒化的 Web 内容中:

¥In order to improve security, the following modules are being deprecated for use directly via require and will instead need to be included via remote.require in a sandboxed webcontents:

  • electron.screen

  • child_process

  • fs

  • os

  • path

webFrame 隔离世界 API

¥webFrame Isolated World APIs

webFrame.setIsolatedWorldContentSecurityPolicywebFrame.setIsolatedWorldHumanReadableNamewebFrame.setIsolatedWorldSecurityOrigin 已被弃用,取而代之的是 webFrame.setIsolatedWorldInfo

¥webFrame.setIsolatedWorldContentSecurityPolicy,webFrame.setIsolatedWorldHumanReadableName, webFrame.setIsolatedWorldSecurityOrigin have been deprecated in favor of webFrame.setIsolatedWorldInfo.

混合沙盒

¥Mixed sandbox

enableMixedSandbox--enable-mixed-sandbox 命令行开关仍然存在,以实现兼容性,但已被弃用且无效。

¥enableMixedSandbox and the --enable-mixed-sandbox command-line switch still exist for compatibility, but are deprecated and have no effect.

2.0.x 停止支持

¥End of support for 2.0.x

根据我们的 支持的版本政策,2.0.x 版本已达到生命周期终点。

¥Per our supported versions policy, 2.0.x has reached end of life.

应用反馈计划

¥App Feedback Program

我们继续使用我们的 应用反馈计划 进行测试。参与此计划的项目在其应用上测试 Electron 测试版;作为回报,他们发现的新 bug 将优先发布到稳定版本。如果你想参与或了解更多信息,请联系 查看我们关于该程序的博客文章

¥We continue to use our App Feedback Program for testing. Projects who participate in this program test Electron betas on their apps; and in return, the new bugs they find are prioritized for the stable release. If you'd like to participate or learn more, check out our blog post about the program.

下一步计划

¥What's Next

短期内,你可以预期团队将继续专注于跟上构成 Electron 的主要组件(包括 Chromium、Node 和 V8)的开发。虽然我们谨慎地不对发布日期做出承诺,但我们计划大约每季度发布一次 Electron 的新主要版本及其组件的新版本。暂定 6.0.0 计划 模块列出了 Electron 6 开发生命周期中的关键日期。此外,查看我们的版本控制文档 提供了有关 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 release new major versions of Electron with new versions of those components approximately quarterly. The tentative 6.0.0 schedule maps out key dates in the Electron 6 development life cycle. Also, see our versioning document for more detailed information about versioning in Electron.

有关即将推出的 Electron 版本 查看我们的“计划重大变更”文档 中计划的重大变更的信息。

¥For information on planned breaking changes in upcoming versions of Electron, see our Planned Breaking Changes doc.

Electron 中从原生到 JavaScript

· 8 min read

Electron 中用 C++ 或 Objective-C 编写的功能是如何转化为 JavaScript 供终端用户使用的?

¥How do Electron's features written in C++ or Objective-C get to JavaScript so they're available to an end-user?


背景

¥Background

Electron 是一个 JavaScript 平台,其主要目的是降低开发者构建健壮桌面应用的门槛,而无需担心特定于平台的实现。然而,从本质上讲,Electron 本身仍然需要用特定的系统语言编写特定于平台的功能。

¥Electron is a JavaScript platform whose primary purpose is to lower the barrier to entry for developers to build robust desktop apps without worrying about platform-specific implementations. However, at its core, Electron itself still needs platform-specific functionality to be written in a given system language.

实际上,Electron 会为你处理原生代码,以便你可以专注于单个 JavaScript API。

¥In reality, Electron handles the native code for you so that you can focus on a single JavaScript API.

但是,这到底是怎么回事?Electron 中用 C++ 或 Objective-C 编写的功能是如何转化为 JavaScript 供终端用户使用的?

¥How does that work, though? How do Electron's features written in C++ or Objective-C get to JavaScript so they're available to an end-user?

要追溯这条路径,让我们从 app 模块 开始。

¥To trace this pathway, let's start with the app module.

通过在 lib/ 中打开 app.ts 文件目录,你会在顶部找到以下代码行:

¥By opening the app.ts file inside our lib/ directory, you'll find the following line of code towards the top:

const binding = process.electronBinding('app');

此行代码直接指向 Electron 将其 C++/Objective-C 模块绑定到 JavaScript 以供开发者使用的机制。此功能由标头和 ElectronBindings 类的 实现文件 创建。

¥This line points directly to Electron's mechanism for binding its C++/Objective-C modules to JavaScript for use by developers. This function is created by the header and implementation file for the ElectronBindings class.

process.electronBinding

这些文件添加了 process.electronBinding 函数,其行为类似于 Node.js 的 process.bindingprocess.binding 是 Node.js require() 方法的低级实现,不同之处在于它允许用户 require 原生代码,而不是其他 JS 代码。此自定义 process.electronBinding 函数允许从 Electron 加载原生代码。

¥These files add the process.electronBinding function, which behaves like Node.js’ process.binding. process.binding is a lower-level implementation of Node.js' require() method, except it allows users to require native code instead of other code written in JS. This custom process.electronBinding function confers the ability to load native code from Electron.

当顶层 JavaScript 模块(如 app)需要此原生代码时,如何确定和设置该原生代码的状态?暴露给 JavaScript 的方法在哪里?属性呢?

¥When a top-level JavaScript module (like app) requires this native code, how is the state of that native code determined and set? Where are the methods exposed up to JavaScript? What about the properties?

native_mate

目前,这个问题的答案可以在 native_mate 中找到:Chromium gin 的一个 fork,可以更轻松地在 C++ 和 JavaScript 之间编组类型。

¥At present, answers to this question can be found in native_mate: a fork of Chromium's gin library that makes it easier to marshal types between C++ and JavaScript.

native_mate/native_mate 内部包含 object_template_builder 的头文件和实现文件。这使得我们能够使用原生代码构建模块,其结构符合 JavaScript 开发者的期望。

¥Inside native_mate/native_mate there's a header and implementation file for object_template_builder. This is what allow us to form modules in native code whose shape conforms to what JavaScript developers would expect.

mate::ObjectTemplateBuilder

如果我们将每个 Electron 模块视为 object,就更容易理解为什么我们要使用 object_template_builder 来构建它们。此类构建于公开的类之上由谷歌开源高性能 JavaScript 和 WebAssembly 引擎 V8 开发,使用 C++ 编写。V8 实现了 JavaScript(ECMAScript)规范,因此其原生功能实现可以直接与 JavaScript 中的实现关联。例如,v8::ObjectTemplate 为我们提供了 JavaScript 对象,而无需专用的构造函数和原型。它使用 Object[.prototype],在 JavaScript 中相当于 Object.create()

¥If we look at every Electron module as an object, it becomes easier to see why we would want to use object_template_builder to construct them. This class is built on top of a class exposed by V8, which is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++. V8 implements the JavaScript (ECMAScript) specification, so its native functionality implementations can be directly correlated to implementations in JavaScript. For example, v8::ObjectTemplate gives us JavaScript objects without a dedicated constructor function and prototype. It uses Object[.prototype], and in JavaScript would be equivalent to Object.create().

要查看实际运行情况,请查看应用模块 atom_api_app.cc 的实现文件。底部内容如下:

¥To see this in action, look to the implementation file for the app module, atom_api_app.cc. At the bottom is the following:

mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
.SetMethod("getGPUInfo", &App::GetGPUInfo)

在上面的一行中,.SetMethodmate::ObjectTemplateBuilder 上被调用。可以在 ObjectTemplateBuilder 类的任何实例上调用 .SetMethod,以 JavaScript 方式设置 对象原型 上的方法,语法如下:

¥In the above line, .SetMethod is called on mate::ObjectTemplateBuilder. .SetMethod can be called on any instance of the ObjectTemplateBuilder class to set methods on the Object prototype in JavaScript, with the following syntax:

.SetMethod("method_name", &function_to_bind)

这是 JavaScript 等效的:

¥This is the JavaScript equivalent of:

function App{}
App.prototype.getGPUInfo = function () {
// implementation here
}

此类还包含用于设置模块属性的函数:

¥This class also contains functions to set properties on a module:

.SetProperty("property_name", &getter_function_to_bind)

or

.SetProperty("property_name", &getter_function_to_bind, &setter_function_to_bind)

这些将是 Object.defineProperty 的 JavaScript 实现:

¥These would in turn be the JavaScript implementations of Object.defineProperty:

function App {}
Object.defineProperty(App.prototype, 'myProperty', {
get() {
return _myProperty
}
})

and

function App {}
Object.defineProperty(App.prototype, 'myProperty', {
get() {
return _myProperty
}
set(newPropertyValue) {
_myProperty = newPropertyValue
}
})

现在,我们可以按照开发者的期望,创建由原型和属性构成的 JavaScript 对象,并且更清晰地推断在这个较低的系统级别实现的函数和属性!

¥It’s possible to create JavaScript objects formed with prototypes and properties as developers expect them, and more clearly reason about functions and properties implemented at this lower system level!

关于在何处实现任何给定模块方法的决定本身就是一个复杂且常常不确定的问题,我们将在以后的文章中讨论。

¥The decision around where to implement any given module method is itself a complex and oft-nondeterministic one, which we'll cover in a future post.

Electron 治理

· 5 min read

随着 Electron 在桌面应用中越来越受欢迎,其开发团队也在不断壮大:我们有更多的全职维护人员,他们为不同的公司工作,生活在不同的时区,并且有不同的兴趣。我们正在引入治理结构,以便我们能够平稳发展。

¥As Electron grows in popularity for desktop applications, the team working on it has also grown: we have more fulltime maintainers who work for different companies, live in different timezones, and have different interests. We're introducing a governance structure so we can keep growing smoothly.


为什么要改变?

¥Why are things changing?

Electron 项目的团队成员与来自世界各地的志愿者、全职维护人员以及多家依赖 Electron 的公司进行协调。到目前为止,我们一直在非正式协调方面取得成功;但随着团队的发展,我们发现这种方法无法扩展。我们还想让新的贡献者更容易在项目中找到归属感。

¥People in the Electron project coordinate in timezones around the world with volunteers, with full-time maintainers, and with several companies who all rely on Electron. Until now, we've been successful with informal coordination; but as the team has grown, we've found that the approach doesn't scale. We also want to make it easier for new contributors to find a place to call home in the project.

工作组

¥Working Groups

Electron 治理包括负责项目不同部分的工作组。我们最初有七个小组:

¥Electron governance includes working groups that are responsible for different parts of the project. We're starting out with seven groups:

  • 社区与安全:处理 行为准则 问题。

    ¥Community & Safety: Handles Code of Conduct issues.

  • 文档和工具:监督面向外部的工具(例如 Fiddle锻造)和 Electron documentation

    ¥Docs & Tooling: Oversees externally-focused tooling (e.g. Fiddle, Forge) and the Electron documentation.

  • 推广:有助于 Electron 社区的发展。

    ¥Outreach: Helps grow the Electron community.

  • 发布:确保发布稳定且按计划进行。

    ¥Releases: Ensures releases are stable and on schedule.

  • 安全性:执行安全测试并响应安全问题。

    ¥Security: Performs security testing and responds to security issues.

  • 升级:集成上游升级,例如 V8、Chromium 和 Node 的新版本。

    ¥Upgrades: Integrates upstream upgrades, such as new versions of V8, Chromium, and Node.

  • 网站:维护并改进 Electron 网站

    ¥Website: Maintains and improves the Electron website.

这些小组将相互协调,但每个小组都有自己的会议日程和议程,以便各自提高工作效率。有关这些组的更多详细信息,请参阅 治理代码库

¥These groups will coordinate with each other, but each has their own meeting schedules and agendas to be productive on their own. More details on these groups are available at the governance repository.

这会改变 Electron 项目的方向吗?

¥Does this change the Electron project's direction?

这应该不会对 Electron 的发展方向产生任何直接影响。如果我们的策略成功,工作组将使新贡献者更容易找到他们感兴趣的主题,并通过将与日常工作无关的讨论转移到其他小组,使维护人员的工作更轻松。如果发生这种情况,它可能会通过让更多不受阻碍的人一起工作来间接地影响事情。

¥This shouldn't have any direct effect on Electron's direction. If our strategy is successful, working groups will make it easier for new contributors to find topics that interest them, and make maintainers' lives simpler by moving discussion unrelated to their day-to-day work to other groups. If that happens, it may indirectly affect things by having more unblocked people working together.

我可以在哪里了解更多信息?

¥Where can I learn more?

Chromium FileReader 漏洞修复

· 3 min read

Chrome 中发现了一个高危漏洞,该漏洞会影响所有基于 Chromium 的软件,包括 Electron。

¥A High severity vulnerability has been discovered in Chrome which affects all software based on Chromium, including Electron.

此漏洞已被分配 CVE-2019-5786。你可以在 Chrome 博客帖子 中了解更多信息。

¥This vulnerability has been assigned CVE-2019-5786. You can read more about it in the Chrome Blog Post.

请注意,Chrome 已报告此漏洞正在被广泛利用,因此强烈建议你尽快升级 Electron。

¥Please note that Chrome has reports of this vulnerability being used in the wild so it is strongly recommended you upgrade Electron ASAP.


范围

¥Scope

这会影响任何可能运行第三方或不受信任的 JavaScript 的 Electron 应用。

¥This affects any Electron application that may run third-party or untrusted JavaScript.

缓解措施

¥Mitigation

受影响的应用应升级到 Electron 的修补版本。

¥Affected apps should upgrade to a patched version of Electron.

我们已发布 Electron 的新版本,其中包含针对此漏洞的修复:

¥We've published new versions of Electron which include fixes for this vulnerability:

Electron 5 的最新测试版跟踪了 Chromium 73,因此已经修复:

¥The latest beta of Electron 5 was tracking Chromium 73 and therefore is already patched:

更多信息

¥Further Information

此漏洞由谷歌威胁分析小组的 Clement Lecigne 发现,并报告给 Chrome 团队。Chrome 博客文章可在 此处 中找到。

¥This vulnerability was discovered by Clement Lecigne of Google's Threat Analysis Group and reported to the Chrome team. The Chrome blog post can be found here.

要了解有关保护 Electron 应用安全的最佳实践的更多信息,请参阅我们的 安全教程

¥To learn more about best practices for keeping your Electron apps secure, see our security tutorial.

如果你想报告 Electron 中的漏洞,请发送电子邮件至 security@electronjs.org

¥If you wish to report a vulnerability in Electron, email security@electronjs.org.

停止对 32 位的支持 Linux

· 6 min read

Electron 团队将从 Electron v4.0 开始停止对 32 位 Linux (ia32 / i386) 的支持。支持 32 位 Linux 安装的 Electron 最新版本是 Electron v3.1,它将持续支持到 Electron v6 发布。对基于 64 位 Linux 和 armv7l 的支持将保持不变。

¥The Electron team will discontinue support for 32-bit Linux (ia32 / i386) starting with Electron v4.0. The last version of Electron that supports 32-bit based installations of Linux is Electron v3.1, which will receive support releases until Electron v6 is released. Support for 64-bit based Linux and armv7l will continue unchanged.


Electron 不再支持哪些功能?

¥What exactly is Electron no longer supporting?

你可能已经在电脑上看到过 "64-bit" 和 "32-bit" 的描述,它们被贴在电脑上,或者作为下载软件的选项。该术语用于描述特定的计算机体系结构。20 世纪 90 年代和 21 世纪初生产的大多数计算机都采用基于 32 位架构的 CPU,而之后生产的大多数计算机则基于更新、更强大的 64 位架构。任天堂 64(明白了吗?)和 PlayStation 2 是第一批广泛使用的采用新架构的消费设备,2010 年后销售的计算机几乎全部采用 64 位处理器。因此,支持范围一直在缩减:Google 于 2016 年 3 月停止发布适用于 32 位 Linux 的 Chrome,Canonical 于 2017 年停止提供 32 位桌面映像,并从 Ubuntu 18.10 开始彻底放弃对 32 位的支持。Arch Linux、elementary OS 和其他知名 Linux 发行版已经放弃了对老旧处理器架构的支持。

¥You may have seen the description "64-bit" and "32-bit" as stickers on your computer or as options for downloading software. The term is used to describe a specific computer architecture. Most computers made in the 1990s and early 2000s were made with CPUs that were based on the 32-bit architecture, while most computers made later were based on the newer and more powerful 64-bit architecture. The Nintendo 64 (get it?) and the PlayStation 2 were the first widely available consumer devices with the new architecture, computers sold after 2010 contained almost exclusively 64-bit processors. As a result, support has been shrinking: Google stopped releasing Chrome for 32-bit Linux in March 2016, Canonical stopped providing 32-bit desktop images in 2017 and dropped support for 32-bit altogether with Ubuntu 18.10. Arch Linux, elementary OS, and other prominent Linux distributions have already dropped support for the aging processor architecture.

到目前为止,Electron 提供并支持在较旧的 32 位架构上运行的版本。从 v4.0 版本开始,Electron 团队将不再提供二进制文件或 32 位 Linux 支持。

¥Until now, Electron has provided and supported builds that run on the older 32-bit architecture. From release v4.0 onwards, the Electron team will no longer be able to provide binaries or support for 32-bit Linux.

Electron 一直是一个充满活力的开源项目,我们将继续支持和鼓励有兴趣为各种架构构建 Electron 的开发者。

¥Electron has always been a vibrant open source project and we continue to support and encourage developers interested in building Electron for exotic architectures.

这对开发者意味着什么?

¥What does that mean for developers?

如果你目前没有为 Linux 提供应用的 32 位发行版,则无需采取任何措施。

¥If you are not currently providing 32-bit distributions of your app for Linux, no action is required.

发布 32 位 Linux Electron 应用的项目需要自行决定如何进行。Electron 3 until 将支持 32 位 Linux,Electron 6 的发布将提供一些时间来制定决策和计划。

¥Projects which ship 32-bit Linux Electron applications will need to decide how to proceed. 32-bit Linux will be supported on Electron 3 until the release of Electron 6, which gives some time to make decisions and plans.

这对用户意味着什么?

¥What does that mean for users?

如果你是 Linux 用户,并且不确定自己运行的是否是 64 位系统,那么你很可能运行的是 64 位架构的系统。为确保万无一失,你可以在终端中运行 lscpuuname -m 命令。两者都会打印你当前的架构。

¥If you are a Linux user and not sure whether or not you're running a 64-bit based system, you are likely running on a 64-bit based architecture. To make sure, you can run the lscpu or uname -m commands in your terminal. Either one will print your current architecture.

如果你使用的是 32 位处理器的 Linux,你可能已经遇到过难以找到适合你操作系统的最新发布软件的情况。Electron 团队与 Linux 社区的其他杰出成员一样,建议你升级到 64 位架构。

¥If you are using Linux on a 32-bit processor, you have likely already encountered difficulties finding recently released software for your operating system. The Electron team joins other prominent members in the Linux community by recommending that you upgrade to a 64-bit based architecture.

BrowserView window.open() 漏洞修复

· 3 min read

发现一个代码漏洞,允许在子窗口中重新启用 Node。

¥A code vulnerability has been discovered that allows Node to be re-enabled in child windows.


使用 sandbox: truenativeWindowOpen: truenodeIntegration: false 打开 BrowserView 会生成一个 webContents,其中可以调用 window.open,并且新打开的子窗口将启用 nodeIntegration。此漏洞影响所有受支持的 Electron 版本。

¥Opening a BrowserView with sandbox: true or nativeWindowOpen: true and nodeIntegration: false results in a webContents where window.open can be called and the newly opened child window will have nodeIntegration enabled. This vulnerability affects all supported versions of Electron.

缓解措施

¥Mitigation

我们已发布 Electron 的新版本,其中包含针对此漏洞的修复:2.0.173.0.153.1.34.0.45.0.0-beta.2。我们鼓励所有 Electron 开发者立即将其应用更新到最新稳定版本。

¥We've published new versions of Electron which include fixes for this vulnerability: 2.0.17, 3.0.15, 3.1.3, 4.0.4, and 5.0.0-beta.2. We encourage all Electron developers to update their apps to the latest stable version immediately.

如果由于某种原因你无法升级 Electron 版本,你可以通过禁用所有子 Web 内容来缓解此问题:

¥If for some reason you are unable to upgrade your Electron version, you can mitigate this issue by disabling all child web contents:

view.webContents.on('-add-new-contents', (e) => e.preventDefault());

更多信息

¥Further Information

此漏洞由 PalmerAL 发现并负责任地报告给 Electron 项目。

¥This vulnerability was found and reported responsibly to the Electron project by PalmerAL.

要了解有关保护 Electron 应用安全的最佳实践的更多信息,请参阅我们的 安全教程

¥To learn more about best practices for keeping your Electron apps secure, see our security tutorial.

如果你想报告 Electron 中的漏洞,请发送电子邮件至 security@electronjs.org

¥If you wish to report a vulnerability in Electron, email security@electronjs.org.

Node.js 原生插件和 Electron 5.0

· 4 min read

如果你在 Electron 5.0 中使用原生 Node.js 插件时遇到问题,则可能需要更新它才能与最新版本的 V8 引擎兼容。

¥If you're having trouble using a native Node.js addon with Electron 5.0, there's a chance it needs to be updated to work with the most recent version of V8.


告别 v8::Handle,迎接 v8::Local

¥Goodbye v8::Handle, Hello v8::Local

2014 年,V8 团队弃用了 v8::Handle,转而使用 v8::Local 作为本地句柄。Electron 5.0 包含一个 V8 版本,该版本最终彻底移除了 v8::Handle,仍在使用该版本的原生 Node.js 插件需要更新才能与 Electron 5.0 一起使用。

¥In 2014, the V8 team deprecated v8::Handle in favor of v8::Local for local handles. Electron 5.0 includes a version of V8 that has finally removed v8::Handle for good, and native Node.js addons that still use it will need to be updated before they can be used with Electron 5.0.

所需的代码更改很少,但每个仍在使用 v8::Handle 的原生 Node 模块都将无法使用 Electron 5.0 构建,需要进行修改。好消息是,Node.js v12 也将包含这项 V8 更改,因此任何使用 v8::Handle 的模块都需要更新才能与即将发布的 Node 版本兼容。

¥The required code change is minimal, but every native Node module that still uses v8::Handle will fail to build with Electron 5.0 and will need to be modified. The good news is that Node.js v12 will also include this V8 change, so any modules that use v8::Handle will need to be updated anyway to work with the upcoming version of Node.

我维护一个原生插件,可以帮忙吗?

¥I maintain a native addon, how can I help?

如果你维护 Node.js 的原生插件,请确保将所有出现的 v8::Handle 替换为 v8::Local。前者只是后者的别名,因此无需进行其他更改即可解决此特定问题。

¥If you maintain a native addon for Node.js, ensure you replace all occurrences of v8::Handle with v8::Local. The former was just an alias of the latter, so no other changes need to be made to address this specific issue.

你可能还想了解一下 N-API,它作为 Node.js 的一部分,独立于 V8 进行维护,旨在将原生插件与底层 JavaScript 引擎的变化隔离开来。你可以在 在 Node.js 网站上的 N-API 文档中 中找到更多信息。

¥You may also be interested in looking into N-API, which is maintained separately from V8 as a part of Node.js itself, and aims to insulate native addons from changes in the underlying JavaScript engine. You can find more information in the N-API documentation on the Node.js website.

求助!我在我的应用中使用了一个原生插件,但它无法运行!

¥Help! I use a native addon in my app and it won't work!

如果你在应用中使用了 Node.js 的原生插件,并且该原生插件由于此问题而无法构建,请与该插件的作者联系,看看他们是否发布了修复此问题的新版本。如果无法解决,联系作者(或 正在提交 Pull 请求!)可能是你最好的选择。

¥If you're consuming a native addon for Node.js in your app and the native addon will not build because of this issue, check with the author of the addon to see if they've released a new version that fixes the problem. If not, reaching out to the author (or opening a Pull Request!) is probably your best bet.

Electron v5.0.0 时间线

· 4 min read

Electron 很高兴首次公布从 v5.0.0 开始的发布计划。这是我们制定公开的长期时间表的第一步。

¥For the first time ever, Electron is excited to publicize our release schedule starting with v5.0.0. This is our first step in having a public, long-term timeline.


正如我们在 v4.0.0 稳定版本 博客文章 中提到的,我们计划大约每季度发布一次,以与 Chromium 的发布节奏保持一致。Chromium 发布新版本的速度非常快 - 每 6 周一次。

¥As mentioned in our v4.0.0 stable release blog post, we are planning to release approximately quarterly to maintain closer cadence with Chromium releases. Chromium releases a new version very quickly -- every 6 weeks.

对比 Electron 与 Chromium 的进展:比较 Electron 和 Chromium 版本的折线图

¥Take a look at progression in Electron versus Chromium side-by-side: line graph comparing Electron versus Chromium versions

2018 年下半年,我们的首要任务是加快发布速度,并更接近 Chromium。我们成功地遵守了预定的时间表。Electron 3.0.0 和 4.0.0 的发布间隔为 2-3 个月。我们对继续保持这一速度并发布 5.0.0 及更高版本充满信心。由于 Electron 大约每季度都会发布一个主要版本,我们现在可以与 Chromium 的发布节奏保持一致。领先于 Chromium 稳定版本一直是我们的目标,我们正在为此努力。

¥In the last half of 2018, our top priority was releasing faster and catching up closer to Chromium. We succeeded by sticking to a predetermined timeline. Electron 3.0.0 and 4.0.0 were released in a 2-3 month timeline for each release. We are optimistic about continuing that pace in releasing 5.0.0 and beyond. With a major Electron release approximately every quarter, we're now keeping pace with Chromium's release cadence. Getting ahead of Chromium stable release is always a goal for us and we are taking steps towards that.

我们希望像 Node.jsChromium 那样承诺未来的日期,但目前我们还没有做到这一点。我们对未来能够达成长期目标充满信心。

¥We would love to promise future dates like Node.js and Chromium do, but we are not at that place yet. We are optimistic that we will reach a long-term timeline in the future.

考虑到这一点,我们迈出了第一步,公开发布了 v5.0.0 的发布时间表。你可以找到 此处

¥With that in mind, we are taking first steps by publicly posting our release schedule for v5.0.0. You can find that here.

为了帮助我们测试 Beta 版本并进行稳定维护,请考虑加入我们的 应用反馈计划

¥To help us with testing our beta releases and stabilization, please consider joining our App Feedback Program.