Customize Consent Preferences

We use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.

The cookies that are categorized as "Necessary" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... 

Always Active

Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.

No cookies to display.

Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.

No cookies to display.

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.

No cookies to display.

Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.

No cookies to display.

Advertisement cookies are used to provide visitors with customized advertisements based on the pages you visited previously and to analyze the effectiveness of the ad campaigns.

No cookies to display.

0

摘要: Electron 框架迎来十周年,它极大地降低了桌面应用开发的门槛,但其臃肿、安全等问题也饱受诟病。本文深入探讨了 Electron 的起源、技术选择、争议以及未来发展趋势,分析了开发者对 Electron 褒贬不一的原因。

北京 – 在现代软件开发领域,Electron 框架无疑是一个举足轻重的存在。它将 Node.js 和 Chromium 结合,为 Web 技术提供了一个强大的桌面运行时,使得开发者能够使用熟悉的 Web 技术栈快速构建跨平台桌面应用。然而,在 Electron 迎来十周年之际,关于其价值和意义的讨论仍在继续。

Electron 的诞生与崛起

Electron 的故事始于 2013 年,由 GitHub 工程师 Cheng Zhao 为了开发 Atom 编辑器而创建。在 Electron 出现之前,开发者需要为每个平台编写独立的本地应用程序,这无疑是一项繁琐且耗时的任务。Electron 的出现,让 Web 开发者能够轻松地将 Web 应用打包成桌面应用,极大地降低了开发成本和时间。

GitHub 对 Electron 进行了大力支持和推广,使其迅速获得了广泛的应用。Slack、GitKraken 等知名公司都选择使用 Electron 构建桌面应用。而微软更是基于 Electron 开发了 Visual Studio Code (VSCode),这无疑是对 Electron 最大的认可。

Electron 的技术选择

Electron 的核心在于同时嵌入了 Node.js 和 Chromium。Node.js 赋予 JavaScript 直接与操作系统底层功能通信的能力,而 Chromium 则提供了基于浏览器的用户界面渲染能力。这种结合使得 Web 开发者能够使用熟悉的 HTML、CSS 和 JavaScript 构建桌面应用,而无需学习新的编程语言和技术。

Electron 采用多进程架构,类似于 Chromium:

  • 主进程: 负责应用程序的生命周期管理、窗口创建、操作系统 API 连接等。
  • 渲染器进程: 每个窗口或视图都在独立的进程中运行,负责渲染 HTML、CSS 和 JavaScript。
  • 自动更新器: Electron 内置的自动更新模块,方便开发者发布更新。

这种架构使得 Electron 应用具有良好的稳定性和可维护性。

Electron 的争议

尽管 Electron 带来了诸多便利,但它也一直饱受批评。最主要的批评集中在以下几个方面:

  • 臃肿: 每个 Electron 应用都自带一个 Chromium 实例,导致应用体积庞大,占用大量内存。一个简单的 Hello, world 应用可能超过 100MB。
  • 安全: Electron 应用不像现代浏览器标签页那样被置于沙盒中,存在安全风险。不安全的依赖关系或加载的脚本可能导致攻击者访问操作系统。

这些问题使得一些对性能和资源占用有较高要求的团队对 Electron 望而却步。

Tauri 与未来

尽管存在争议,Electron 仍然是构建跨平台桌面应用的热门选择。然而,一些新的框架,如 Tauri,正在挑战 Electron 的地位。Tauri 使用 Rust 构建,具有更小的体积和更好的性能。

未来,桌面应用开发领域可能会出现更多选择。开发者需要根据自身的需求和项目的特点,选择最合适的框架。

结论

Electron 框架在过去十年中极大地改变了桌面应用开发的面貌。它降低了开发门槛,使得更多的开发者能够参与到桌面应用的开发中来。然而,Electron 的臃肿和安全问题也需要引起重视。随着新的框架的出现,桌面应用开发领域将迎来更多的可能性。

参考文献:

  • Foster, G. (2024, February 3). 10 years later, developers still don’t get Electron. Small Diffs.
  • Electron Official Website: https://www.electronjs.org/

作者:

[你的名字]

前新华社、人民日报、中央电视台、华尔街日报、纽约时报资深新闻记者和编辑


>>> Read more <<<

Views: 0

0

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注