环境变量
¥Environment Variables
无需更改代码即可控制应用配置和行为。
¥Control application configuration and behavior without changing code.
某些 Electron 行为由环境变量控制,因为它们的初始化早于命令行标志和应用代码。
¥Certain Electron behaviors are controlled by environment variables because they are initialized earlier than the command line flags and the app's code.
POSIX shell 示例:
¥POSIX shell example:
$ export ELECTRON_ENABLE_LOGGING=true
$ electron
Windows 控制台示例:
¥Windows console example:
> set ELECTRON_ENABLE_LOGGING=true
> electron
生产变量
¥Production Variables
以下环境变量主要用于在打包的 Electron 应用中运行时使用。
¥The following environment variables are intended primarily for use at runtime in packaged Electron applications.
NODE_OPTIONS
Electron 包含对 Node NODE_OPTIONS
子集的支持。大多数都受到支持,但与 Chromium 使用 BoringSSL 冲突的除外。
¥Electron includes support for a subset of Node's NODE_OPTIONS
. The majority are supported with the exception of those which conflict with Chromium's use of BoringSSL.
示例:
¥Example:
export NODE_OPTIONS="--no-warnings --max-old-space-size=2048"
不支持的选项有:
¥Unsupported options are:
--use-bundled-ca
--force-fips
--enable-fips
--openssl-config
--use-openssl-ca
打包应用中明确禁止使用 NODE_OPTIONS
,但以下情况除外:
¥NODE_OPTIONS
are explicitly disallowed in packaged apps, except for the following:
--max-http-header-size
--http-parser
如果 nodeOptions
保险丝 被禁用,NODE_OPTIONS
将被忽略。
¥If the nodeOptions
fuse is disabled, NODE_OPTIONS
will be ignored.
NODE_EXTRA_CA_CERTS
详情请参见 Node.js cli 文档。
¥See Node.js cli documentation for details.
export NODE_EXTRA_CA_CERTS=/path/to/cert.pem
如果 nodeOptions
保险丝 被禁用,NODE_EXTRA_CA_CERTS
将被忽略。
¥If the nodeOptions
fuse is disabled, NODE_EXTRA_CA_CERTS
will be ignored.
GOOGLE_API_KEY
Electron 中的地理定位支持需要使用 Google Cloud Platform 的地理定位网络服务。要启用此功能,请获取 谷歌 API 密钥 并将以下代码放入主进程文件中,然后再打开任何发出地理定位请求的浏览器窗口:
¥Geolocation support in Electron requires the use of Google Cloud Platform's geolocation webservice. To enable this feature, acquire a Google API key and place the following code in your main process file, before opening any browser windows that will make geolocation requests:
process.env.GOOGLE_API_KEY = 'YOUR_KEY_HERE'
默认情况下,新生成的 Google API 密钥可能不允许发出地理定位请求。要为你的项目启用地理定位 Web 服务,请通过 API 库。
¥By default, a newly generated Google API key may not be allowed to make geolocation requests. To enable the geolocation webservice for your project, enable it through the API library.
注意:你需要将 计费账户 添加到与 API 密钥关联的项目中,以便地理定位 Web 服务正常工作。
¥N.B. You will need to add a Billing Account to the project associated to the API key for the geolocation webservice to work.
ELECTRON_NO_ASAR
禁用 ASAR 支持。此变量仅在设置 ELECTRON_RUN_AS_NODE
的派生子进程和派生子进程中受支持。
¥Disables ASAR support. This variable is only supported in forked child processes
and spawned child processes that set ELECTRON_RUN_AS_NODE
.
ELECTRON_RUN_AS_NODE
作为普通 Node.js 进程启动该进程。
¥Starts the process as a normal Node.js process.
在此模式下,你将能够像运行普通 Node.js 可执行文件一样将 命令行选项 传递给 Node.js,但以下标志除外:
¥In this mode, you will be able to pass cli options to Node.js as you would when running the normal Node.js executable, with the exception of the following flags:
-
"--openssl-config"
-
"--use-bundled-ca"
-
"--use-openssl-ca",
-
"--force-fips"
-
"--enable-fips"
这些标志被禁用是因为 Electron 在构建 Node.js 的 crypto
模块时使用 BoringSSL 而不是 OpenSSL,因此无法按设计工作。
¥These flags are disabled owing to the fact that Electron uses BoringSSL instead of OpenSSL when building Node.js'
crypto
module, and so will not work as designed.
如果 runAsNode
保险丝 被禁用,ELECTRON_RUN_AS_NODE
将被忽略。
¥If the runAsNode
fuse is disabled, ELECTRON_RUN_AS_NODE
will be ignored.
ELECTRON_NO_ATTACH_CONSOLE
Windows
不要附加到当前控制台会话。
¥Don't attach to the current console session.
ELECTRON_FORCE_WINDOW_MENU_BAR
Linux
不要在 Linux 上使用全局菜单栏。
¥Don't use the global menu bar on Linux.
ELECTRON_TRASH
Linux
在 Linux 上设置垃圾箱实现。默认为 gio
。
¥Set the trash implementation on Linux. Default is gio
.
选项:
¥Options:
-
gvfs-trash
-
trash-cli
-
kioclient5
-
kioclient
ELECTRON_OZONE_PLATFORM_HINT
Linux
选择 Linux 上使用的首选平台后端。默认值为 x11
。如果可能,auto
选择 Wayland,否则选择 X11。
¥Selects the preferred platform backend used on Linux. The default one is x11
. auto
selects Wayland if possible, X11 otherwise.
选项:
¥Options:
-
auto
-
wayland
-
x11
开发变量
¥Development Variables
以下环境变量主要用于开发和调试目的。
¥The following environment variables are intended primarily for development and debugging purposes.
ELECTRON_ENABLE_LOGGING
将 Chromium 的内部日志记录打印到控制台。
¥Prints Chromium's internal logging to the console.
设置此变量与在命令行上传递 --enable-logging
相同。有关详细信息,请参阅 命令行开关 中的 --enable-logging
。
¥Setting this variable is the same as passing --enable-logging
on the command line. For more info, see --enable-logging
in
command-line switches.
ELECTRON_LOG_FILE
设置 Chromium 内部日志记录的文件目标。
¥Sets the file destination for Chromium's internal logging.
设置此变量与在命令行上传递 --log-file
相同。有关详细信息,请参阅 命令行开关 中的 --log-file
。
¥Setting this variable is the same as passing --log-file
on the command line. For more info, see --log-file
in
command-line switches.
ELECTRON_DEBUG_NOTIFICATIONS
向 macOS 上的 Notification
生命周期添加额外的日志以帮助调试。创建或激活新通知时将显示额外的日志记录。当采取常见操作时,它们也会显示:显示、取消通知、单击其按钮或响应通知。
¥Adds extra logs to Notification
lifecycles on macOS to aid in debugging. Extra logging will be displayed when new Notifications are created or activated. They will also be displayed when common actions are taken: a notification is shown, dismissed, its button is clicked, or it is replied to.
示例输出:
¥Sample output:
Notification created (com.github.Electron:notification:EAF7B87C-A113-43D7-8E76-F88EC9D73D44)
Notification displayed (com.github.Electron:notification:EAF7B87C-A113-43D7-8E76-F88EC9D73D44)
Notification activated (com.github.Electron:notification:EAF7B87C-A113-43D7-8E76-F88EC9D73D44)
Notification replied to (com.github.Electron:notification:EAF7B87C-A113-43D7-8E76-F88EC9D73D44)
ELECTRON_LOG_ASAR_READS
当 Electron 读取 ASAR 文件时,将读取的偏移量和文件路径记录到系统 tmpdir
中。生成的文件可以提供给 ASAR 模块以优化文件排序。
¥When Electron reads from an ASAR file, log the read offset and file path to
the system tmpdir
. The resulting file can be provided to the ASAR module
to optimize file ordering.
ELECTRON_ENABLE_STACK_DUMPING
当 Electron 崩溃时,将堆栈跟踪打印到控制台。
¥Prints the stack trace to the console when Electron crashes.
如果 crashReporter
启动,该环境变量将不起作用。
¥This environment variable will not work if the crashReporter
is started.
ELECTRON_DEFAULT_ERROR_MODE
Windows
当 Electron 崩溃时显示 Windows 的崩溃对话框。
¥Shows the Windows's crash dialog when Electron crashes.
如果 crashReporter
启动,该环境变量将不起作用。
¥This environment variable will not work if the crashReporter
is started.
ELECTRON_OVERRIDE_DIST_PATH
当从 electron
包运行时,此变量告诉 electron
命令使用指定的 Electron 版本,而不是 npm install
下载的版本。用法:
¥When running from the electron
package, this variable tells
the electron
command to use the specified build of Electron instead of
the one downloaded by npm install
. Usage:
export ELECTRON_OVERRIDE_DIST_PATH=/Users/username/projects/electron/out/Testing
由 Electron 设置
¥Set By Electron
Electron 在运行时在你的环境中设置一些变量。
¥Electron sets some variables in your environment at runtime.
ORIGINAL_XDG_CURRENT_DESKTOP
该变量设置为应用最初启动时使用的 XDG_CURRENT_DESKTOP
值。Electron 有时会修改 XDG_CURRENT_DESKTOP
的值来影响 Chromium 中的其他逻辑,因此如果你想访问原始值,你应该查找此环境变量。
¥This variable is set to the value of XDG_CURRENT_DESKTOP
that your application
originally launched with. Electron sometimes modifies the value of XDG_CURRENT_DESKTOP
to affect other logic within Chromium so if you want access to the original value
you should look up this environment variable instead.