Environment Variables环境变量
Control application configuration and behavior without changing code.在不更改代码的情况下控制应用程序配置和行为。
Certain Electron behaviors are controlled by environment variables because they are initialized earlier than the command line flags and the app's code.某些Electron行为由环境变量控制,因为它们比命令行标志和应用程序代码更早初始化。
POSIX shell example:
$ export ELECTRON_ENABLE_LOGGING=true
$ electron
Windows console example:Windows控制台示例:
> set ELECTRON_ENABLE_LOGGING=true
> electron
Production Variables生产变量
The following environment variables are intended primarily for use at runtime in packaged Electron applications.以下环境变量主要用于运行时打包的Electron应用程序。
NODE_OPTIONS
Electron includes support for a subset of Node's NODE_OPTIONS. Electron包括对Node的NODE_OPTIONS的一个子集的支持。The majority are supported with the exception of those which conflict with Chromium's use of BoringSSL.大多数都得到了支持,但与Chromium使用BoringSL相冲突的除外。
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
are explicitly disallowed in packaged apps, except for the following:在打包的应用程序中明确禁止,但以下情况除外:
--max-http-header-size
--http-parser
GOOGLE_API_KEY
Geolocation support in Electron requires the use of Google Cloud Platform's geolocation webservice.Electron中的地理定位支持需要使用谷歌云平台的地理定位Web服务。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:要启用此功能,请获取Google API key并将以下代码放入主进程文件中,然后再打开任何会发出地理定位请求的浏览器窗口:
process.env.GOOGLE_API_KEY = 'YOUR_KEY_HERE'
By default, a newly generated Google API key may not be allowed to make geolocation requests. 默认情况下,可能不允许新生成的Google API密钥进行地理定位请求。To enable the geolocation webservice for your project, enable it through the API library.要为您的项目启用地理定位Web服务,请通过API库启用它。
N.B. You will need to add a Billing Account to the project associated to the API key for the geolocation webservice to work.注:。您需要将一个计费帐户添加到与API密钥相关联的项目中,地理定位Web服务才能工作。
ELECTRON_NO_ASAR
Disables ASAR support.禁用ASAR支持。This variable is only supported in forked child processes and spawned child processes that set 此变量仅在分叉子进程中受支持,并派生出设置ELECTRON_RUN_AS_NODE
.ELECTRON_RUN_AS_ NODE
的子进程。
ELECTRON_RUN_AS_NODE
Starts the process as a normal Node.js process.将进程作为普通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:在这种模式下,除了以下标志外,您将能够在运行普通Node.js可执行文件时向Node.js asyou传递cli选项:
- "--openssl-config"
- "--use-bundled-ca"
- "--use-openssl-ca",
- "--force-fips"
- "--enable-fips"
These flags are disabled owing to the fact that Electron uses BoringSSL instead of OpenSSL when building Node.js' 这些标志被禁用,因为Electron在构建Node.js的crypto
module, and so will not work as designed.crypto
模块时使用BoringSL而不是OpenSSL,因此无法按设计工作。
ELECTRON_NO_ATTACH_CONSOLE
Windows
Don't attach to the current console session.不要附加到当前控制台会话。
ELECTRON_FORCE_WINDOW_MENU_BAR
Linux
Don't use the global menu bar on Linux.不要在Linux上使用全局菜单栏。
ELECTRON_TRASH
Linux
Set the trash implementation on Linux. 在Linux上设置垃圾实现。Default is 默认为gio
.gio
。
Options:
gvfs-trash
trash-cli
kioclient5
kioclient
Development Variable发展变量s
The following environment variables are intended primarily for development and debugging purposes.以下环境变量主要用于开发和调试目的。
ELECTRON_ENABLE_LOGGING
Prints Chromium's internal logging to the console.将Chromium的内部日志记录打印到控制台。
Setting this variable is the same as passing 设置此变量与在命令行上传递--enable-logging
on the command line. --enable-logging
相同。For more info, see 有关更多信息,请参阅命令行开关中的--enable-logging
in command-line switches.--enable-logging
。
ELECTRON_LOG_FILE
Sets the file destination for Chromium's internal logging.为Chromium的内部日志记录设置文件目标。
Setting this variable is the same as passing 设置此变量与在命令行上传递--log-file
on the command line. --log-file
相同。For more info, see 有关更多信息,请参阅命令行开关中的--log-file
in command-line switches.--log-file
。
ELECTRON_DEBUG_DRAG_REGIONS
Adds coloration to draggable regions on BrowserViews on macOS - draggable regions will be colored green and non-draggable regions will be colored red to aid debugging.
ELECTRON_DEBUG_NOTIFICATIONS
Adds extra logs to Notification lifecycles on macOS to aid in debugging. 在macOS的Notification生命周期中添加额外的日志以帮助调试。Extra logging will be displayed when new Notifications are created or activated. 当创建或激活新的通知时,将显示额外的日志记录。They will also be displayed when common a tions 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
When Electron reads from an ASAR file, log the read offset and file path to the system 当Electron从ASAR文件读取时,将读取偏移量和文件路径记录到系统tmpdir
.tmpdir
。The resulting file can be provided to the ASAR module to optimize file ordering.生成的文件可以提供给ASAR模块,以优化文件排序。
ELECTRON_ENABLE_STACK_DUMPING
Prints the stack trace to the console when Electron crashes.Electron崩溃时,将堆栈跟踪打印到控制台。
This environment variable will not work if the 如果启动了crashReporter
is started.crashReporter
,则此环境变量将不起作用。
ELECTRON_DEFAULT_ERROR_MODE
Windows
Shows the Windows's crash dialog when Electron crashes.当Electron崩溃时,显示Windows的崩溃对话框。
This environment variable will not work if the 如果启动了crashReporter
is started.crashReporter
,则此环境变量将不起作用。
ELECTRON_OVERRIDE_DIST_PATH
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
. electron
包运行时,此变量告诉electron
命令使用指定的Electron版本,而不是npm install
。Usage:用法:
export ELECTRON_OVERRIDE_DIST_PATH=/Users/username/projects/electron/out/Testing
Set By Electron
Electron sets some variables in your environment at runtime.Electron在运行时设置环境中的一些变量。
ORIGINAL_XDG_CURRENT_DESKTOP
This variable is set to the value of 此变量设置为应用程序最初启动时使用的XDG_CURRENT_DESKTOP
that your application originally launched with. XDG_CURRENT_DESKTOP
的值。Electron sometimes modifies the value of Electron有时会修改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.XDG_CURRENT_DESKTOP
的值,以影响Chromium中的其他逻辑,因此如果您想访问原始值,则应查找此环境变量。