Skip to main content

app

Control your application's event lifecycle.控制应用程序的事件生命周期。

Process: 进程:Main

The following example shows how to quit the application when the last window is closed:以下示例显示了在关闭最后一个窗口时如何退出应用程序:

const { app } = require('electron')
app.on('window-all-closed', () => {
app.quit()
})

Events事件

The app object emits the following events:app对象发出以下事件:

Event: 'will-finish-launching'

Emitted when the application has finished basic startup. 当应用程序完成基本启动时发出。On Windows and Linux, the will-finish-launching event is the same as the ready event; on macOS, this event represents the applicationWillFinishLaunching notification of NSApplication. 在Windows和Linux上,will-finish-launching事件与ready事件相同;在macOS上,此事件表示NSApplicationapplicationWillFinishLaunching通知。You would usually set up listeners for the open-file and open-url events here, and start the crash reporter and auto updater.通常在这里为open-fileopen-url事件设置侦听器,并启动崩溃报告器和自动更新器。

In most cases, you should do everything in the ready event handler.在大多数情况下,您应该在ready事件处理程序中执行所有操作。

Event: 'ready'

Returns:返回:

Emitted once, when Electron has finished initializing. 当Electron完成初始化时,发射一次。On macOS, launchInfo holds the userInfo of the NSUserNotification or information from UNNotificationResponse that was used to open the application, if it was launched from Notification Center. 在macOS上,launchInfo保存NSUserNotificationuserInfo或用于打开应用程序的UNNotificationResponse的信息(如果应用程序是从通知中心启动的)。You can also call app.isReady() to check if this event has already fired and app.whenReady() to get a Promise that is fulfilled when Electron is initialized.您还可以调用apps.Ready()来检查此事件是否已触发,并调用app.whenReady()来获得在Electron初始化时实现的Promise。

Event: 'window-all-closed'

Emitted when all windows have been closed.关闭所有窗口时发出。

If you do not subscribe to this event and all windows are closed, the default behavior is to quit the app; however, if you subscribe, you control whether the app quits or not. 如果您没有订阅此事件,并且所有窗口都已关闭,则默认行为是退出应用程序;然而,如果你订阅了,你可以控制应用程序是否退出。If the user pressed Cmd + Q, or the developer called app.quit(), Electron will first try to close all the windows and then emit the will-quit event, and in this case the window-all-closed event would not be emitted.如果用户按下Cmd+Q,或者开发人员调用app.quit(),Electron将首先尝试关闭所有窗口,然后发出will-quit事件,在这种情况下,不会发出window-all-closed事件。

Event: 'before-quit'

Returns:返回:

  • event Event

Emitted before the application starts closing its windows. 在应用程序开始关闭其窗口之前发出。Calling event.preventDefault() will prevent the default behavior, which is terminating the application.调用event.preventDefault()将阻止终止应用程序的默认行为。

Note: If application quit was initiated by autoUpdater.quitAndInstall(), then before-quit is emitted after emitting close event on all windows and closing them.如果应用程序退出是由autoUpdater.quitAndInstall()启动的,则在所有窗口上发出close事件并关闭它们后,将发出before-quit

Note: On Windows, this event will not be emitted if the app is closed due to a shutdown/restart of the system or a user logout.在Windows上,如果应用程序因系统关闭/重新启动或用户注销而关闭,则不会发出此事件。

Event: 'will-quit'

Returns:返回:

  • event Event

Emitted when all windows have been closed and the application will quit. 当所有窗口关闭且应用程序将退出时发出。Calling event.preventDefault() will prevent the default behavior, which is terminating the application.调用event.preventDefault()将阻止终止应用程序的默认行为。

See the description of the window-all-closed event for the differences between the will-quit and window-all-closed events.有关will-quitwindow-all-closed事件之间的差异,请参阅window-all-closed的事件的描述。

Note: On Windows, this event will not be emitted if the app is closed due to a shutdown/restart of the system or a user logout.在Windows上,如果应用程序因系统关闭/重新启动或用户注销而关闭,则不会发出此事件。

Event: 'quit'

Returns:返回:

  • event Event
  • exitCode Integer

Emitted when the application is quitting.当应用程序退出时发出。

Note: On Windows, this event will not be emitted if the app is closed due to a shutdown/restart of the system or a user logout.在Windows上,如果应用程序因系统关闭/重新启动或用户注销而关闭,则不会发出此事件。

Event: 'open-file' macOS

Returns:返回:

  • event Event
  • path string

Emitted when the user wants to open a file with the application. 当用户希望使用应用程序打开文件时发出。The open-file event is usually emitted when the application is already open and the OS wants to reuse the application to open the file. open-file事件通常在应用程序已经打开并且OS希望重用应用程序以打开文件时发出。open-file is also emitted when a file is dropped onto the dock and the application is not yet running. 当文件放置到dock上且应用程序尚未运行时,也会发出。Make sure to listen for the open-file event very early in your application startup to handle this case (even before the ready event is emitted).确保在应用程序启动的早期就侦听open-file事件以处理这种情况(甚至在发出ready事件之前)。

You should call event.preventDefault() if you want to handle this event.如果要处理此事件,应调用event.preventDefault()

On Windows, you have to parse process.argv (in the main process) to get the filepath.在Windows上,必须解析process.argv(在主进程中)以获取文件路径。

Event: 'open-url' macOS

Returns:返回:

  • event Event
  • url string

Emitted when the user wants to open a URL with the application. 当用户希望使用应用程序打开URL时发出。Your application's Info.plist file must define the URL scheme within the CFBundleURLTypes key, and set NSPrincipalClass to AtomApplication.应用程序的Info.plist文件必须在CFBundleURLTypes键中定义URL方案,并将NSPrincipalClass设置为AtomApplication

You should call event.preventDefault() if you want to handle this event.如果要处理此事件,应调用event.preventDefault()

Event: 'activate' macOS

Returns:返回:

  • event Event
  • hasVisibleWindows boolean

Emitted when the application is activated. 应用程序激活时发出。Various actions can trigger this event, such as launching the application for the first time, attempting to re-launch the application when it's already running, or clicking on the application's dock or taskbar icon.各种操作都会触发此事件,例如首次启动应用程序、在应用程序已运行时尝试重新启动应用程序,或单击应用程序的停靠或任务栏图标。

Event: 'did-become-active' macOS

Returns:返回:

  • event Event

Emitted when mac application become active. 当mac应用程序激活时发出。Difference from activate event is that did-become-active is emitted every time the app becomes active, not only when Dock icon is clicked or application is re-launched.activate事件不同的是,每次应用程序激活时都会发出did-become-active事件,而不仅仅是在单击Dock图标或重新启动应用程序时。

Event: 'continue-activity' macOS

Returns:返回:

  • event Event
  • type string - A string identifying the activity. string - 标识活动的字符串。Maps to NSUserActivity.activityType.映射到NSUserActivity.activityType
  • userInfo unknown - Contains app-specific state stored by the activity on another device.unknown - 包含其他设备上活动存储的应用程序特定状态。
  • details Object
    • webpageURL string (optional) - A string identifying the URL of the webpage accessed by the activity on another device, if available.string(可选)- 一个字符串,标识活动在另一个设备上访问的网页的URL(如果可用)。

Emitted during Handoff when an activity from a different device wants to be resumed. 当其他设备的活动要恢复时,在切换期间发出。You should call event.preventDefault() if you want to handle this event.如果要处理此事件,应调用event.preventDefault()

A user activity can be continued only in an app that has the same developer Team ID as the activity's source app and that supports the activity's type. 用户活动只能在与活动的源应用程序具有相同开发团队ID且支持活动类型的应用程序中继续。Supported activity types are specified in the app's Info.plist under the NSUserActivityTypes key.支持的活动类型在应用程序的Info.plist中的NSUserActivityTypes键下指定。

Event: 'will-continue-activity' macOS

Returns:返回:

Emitted during Handoff before an activity from a different device wants to be resumed. 切换期间,来自其他设备的活动要恢复之前发出。You should call event.preventDefault() if you want to handle this event.如果要处理此事件,应调用event.preventDefault()

Event: 'continue-activity-error' 事件:“继续活动错误”macOS

Returns:返回:

  • event Event
  • type string - A string identifying the activity. string - 标识活动的字符串。Maps to NSUserActivity.activityType.映射到NSUserActivity.activityType
  • error string - A string with the error's localized description.string - 包含错误本地化描述的字符串。

Emitted during Handoff when an activity from a different device fails to be resumed.当无法恢复来自其他设备的活动时,在切换期间发出。

Event: 'activity-was-continued' macOS

Returns:返回:

  • event Event
  • type string - A string identifying the activity. string - 标识活动的字符串。Maps to NSUserActivity.activityType.映射到NSUserActivity.activityType
  • userInfo unknown - Contains app-specific state stored by the activity.unknown - 包含活动存储的应用程序特定状态。

Emitted during Handoff after an activity from this device was successfully resumed on another one.此设备的活动在另一设备上成功恢复后,在切换期间发出。

Event: 'update-activity-state' macOS

Returns:返回:

  • event Event
  • type string - A string identifying the activity. string - 标识活动的字符串。Maps to NSUserActivity.activityType.映射到NSUserActivity.activityType
  • userInfo unknown - Contains app-specific state stored by the activity.unknown - 包含活动存储的应用程序特定状态。

Emitted when Handoff is about to be resumed on another device. 在另一台设备上即将恢复切换时发出。If you need to update the state to be transferred, you should call event.preventDefault() immediately, construct a new userInfo dictionary and call app.updateCurrentActivity() in a timely manner. 如果需要更新要传输的状态,应立即调用event.preventDefault(),构造一个新的userInfo字典,并及时调用app.updateCurrentActivity()Otherwise, the operation will fail and continue-activity-error will be called.否则,操作将失败,将调用continue-activity-error

Event: 'new-window-for-tab' 事件:'选项卡的新窗口'macOS

Returns:返回:

  • event Event

Emitted when the user clicks the native macOS new tab button. 当用户单击本地macOS新选项卡按钮时发出。The new tab button is only visible if the current BrowserWindow has a tabbingIdentifier仅当当前BrowserWindow具有tabingIdentifier时,新选项卡按钮才可见

Event: 'browser-window-blur'

Returns:返回:

Emitted when a browserWindow gets blurred.browserWindow失去焦点时发出。

Event: 'browser-window-focus'

Returns:返回:

Emitted when a browserWindow gets focused.browserWindow得到焦点时发出。

Event: 'browser-window-created'

Returns:返回:

Emitted when a new browserWindow is created.创建新browserWindow时发出。

Event: 'web-contents-created'

Returns:返回:

Emitted when a new webContents is created.创建新的webContents时发出。

Event: 'certificate-error'

Returns:返回:

  • event Event
  • webContents WebContents
  • url string
  • error string - The error code错误代码
  • certificate Certificate
  • callback Function
    • isTrusted boolean - Whether to consider the certificate as trustedboolean - 是否将证书视为可信证书
  • isMainFrame boolean

Emitted when failed to verify the certificate for url, to trust the certificate you should prevent the default behavior with event.preventDefault() and call callback(true).当验证urlcertificate失败时发出,为了信任证书,应该使用event.preventDefault()callback(true)阻止默认行为。

const { app } = require('electron')

app.on('certificate-error', (event, webContents, url, error, certificate, callback) => {
if (url === 'https://github.com') {
// Verification logic.
event.preventDefault()
callback(true)
} else {
callback(false)
}
})

Event: 'select-client-certificate'

Returns:返回:

Emitted when a client certificate is requested.请求客户端证书时发出。

The url corresponds to the navigation entry requesting the client certificate and callback can be called with an entry filtered from the list. url对应于请求客户端证书的导航条目,可以使用从列表中筛选的条目调用callbackUsing event.preventDefault() prevents the application from using the first certificate from the store.使用event.preventDefault()可防止应用程序使用存储中的第一个证书。

const { app } = require('electron')

app.on('select-client-certificate', (event, webContents, url, list, callback) => {
event.preventDefault()
callback(list[0])
})

Event: 'login'

Returns:返回:

  • event Event
  • webContents WebContents
  • authenticationResponseDetails Object
    • url URL
  • authInfo Object
    • isProxy boolean
    • scheme string
    • host string
    • port Integer
    • realm string
  • callback Function
    • username string (optional)
    • password string (optional)

Emitted when webContents wants to do basic auth.webContents想要进行基本身份验证时发出。

The default behavior is to cancel all authentications. 默认行为是取消所有身份验证。To override this you should prevent the default behavior with event.preventDefault() and call callback(username, password) with the credentials.要覆盖此项,您应该使用event.preventDefault()阻止默认行为,并使用凭据调用callback(username, password)

const { app } = require('electron')

app.on('login', (event, webContents, details, authInfo, callback) => {
event.preventDefault()
callback('username', 'secret')
})

If callback is called without a username or password, the authentication request will be cancelled and the authentication error will be returned to the page.如果在没有用户名或密码的情况下调用callback,则将取消身份验证请求,并将身份验证错误返回到页面。

Event: 'gpu-info-update'

Emitted whenever there is a GPU info update.每当GPU信息更新时发出。

Event: 'gpu-process-crashed' Deprecated

Returns:返回:

  • event Event
  • killed boolean

Emitted when the GPU process crashes or is killed.当GPU进程崩溃或被终止时发出。

Deprecated: This event is superceded by the child-process-gone event which contains more information about why the child process disappeared. 此事件被child-process-gone事件取代,该事件包含有关子进程消失原因的更多信息。It isn't always because it crashed. 这并不总是因为它坠毁了。The killed boolean can be replaced by checking reason === 'killed' when you switch to that event.切换到该事件时,可以通过检查reason === 'killed'来替换killed布尔值。

Event: 'renderer-process-crashed' Deprecated

Returns:返回:

Emitted when the renderer process of webContents crashes or is killed.webContents的渲染器进程崩溃或被终止时发出。

Deprecated: This event is superceded by the render-process-gone event which contains more information about why the render process disappeared. 此事件被render-process-gone事件取代,该事件包含有关渲染进程消失原因的更多信息。It isn't always because it crashed. 这并不总是因为它坠毁了。The killed boolean can be replaced by checking reason === 'killed' when you switch to that event.当您切换到该事件时,可以通过检查reason === 'killed'来替换killed布尔值。

Event: 'render-process-gone'

Returns:返回:

  • event Event
  • webContents WebContents
  • details Object
    • reason string - The reason the render process is gone. 渲染过程消失的原因。Possible values:可能的值:
      • clean-exit - Process exited with an exit code of zero进程退出,退出代码为零
      • abnormal-exit - Process exited with a non-zero exit code进程已退出,退出代码为非零
      • killed - Process was sent a SIGTERM or otherwise killed externally进程被发送SIGTERM或以其他方式从外部终止
      • crashed - Process crashed进程崩溃
      • oom - Process ran out of memory进程内存不足
      • launch-failed - Process never successfully launched进程从未成功启动
      • integrity-failure - Windows code integrity checks failedWindows代码完整性检查失败
    • exitCode Integer - The exit code of the process, unless reason is launch-failed, in which case exitCode will be a platform-specific launch failure error code.进程的退出代码,除非reasonlaunch-failed,在这种情况下,exitCode将是特定于平台的启动失败错误代码。

Emitted when the renderer process unexpectedly disappears. 当渲染器进程意外消失时发出。This is normally because it was crashed or killed.这通常是因为它坠毁或死亡。

Event: 'child-process-gone'

Returns:返回:

  • event Event
  • details Object
    • type string - Process type. 流程类型。One of the following values:以下值之一:
      • Utility
      • Zygote
      • Sandbox helper
      • GPU
      • Pepper Plugin
      • Pepper Plugin Broker
      • Unknown
    • reason string - The reason the child process is gone. 子进程消失的原因。Possible values:可能的值:
      • clean-exit - Process exited with an exit code of zero进程退出,退出代码为零
      • abnormal-exit - Process exited with a non-zero exit code进程已退出,退出代码为非零
      • killed - Process was sent a SIGTERM or otherwise killed externally进程被发送SIGTERM或以其他方式从外部终止
      • crashed - Process crashed进程崩溃
      • oom - Process ran out of memory进程内存不足
      • launch-failed - Process never successfully launched进程从未成功启动
      • integrity-failure - Windows code integrity checks failedWindows代码完整性检查失败
    • exitCode number - The exit code for the process (e.g. status from waitpid if on posix, from GetExitCodeProcess on Windows).进程的退出代码(例如,如果在posix上,则来自waitpid的状态,或者来自Windows上的GetExitCodeProcess的状态)。
    • serviceName string (optional) - The non-localized name of the process.进程的非本地化名称。
    • name string (optional) - The name of the process. 进程的名称。Examples for utility: Audio Service, Content Decryption Module Service, Network Service, Video Capture, etc.实用程序示例:Audio ServiceContent Decryption Module ServiceNetwork ServiceVideo Capture等。

Emitted when the child process unexpectedly disappears. 当子进程意外消失时发出。This is normally because it was crashed or killed. 这通常是因为它坠毁或死亡。It does not include renderer processes.它不包括渲染器进程。

Event: 'accessibility-support-changed' macOS Windows

Returns:返回:

  • event Event
  • accessibilitySupportEnabled boolean - true when Chrome's accessibility support is enabled, false otherwise.启用Chrome的辅助功能支持时为true,否则为false

Emitted when Chrome's accessibility support changes. Chrome的辅助功能支持更改时发出。This event fires when assistive technologies, such as screen readers, are enabled or disabled. 当辅助技术(如屏幕阅读器)被启用或禁用时,会触发此事件。See https://www.chromium.org/developers/design-documents/accessibility for more details.请参阅https://www.chromium.org/developers/design-documents/accessibility以了解更多详细信息。

Event: 'session-created'

Returns:返回:

Emitted when Electron has created a new session.Electron创建新session时发射。

const { app } = require('electron')

app.on('session-created', (session) => {
console.log(session)
})

Event: 'second-instance'

Returns:返回:

  • event Event
  • argv string[] - An array of the second instance's command line arguments第二个实例的命令行参数的数组
  • workingDirectory string - The second instance's working directory第二个实例的工作目录
  • additionalData unknown - A JSON object of additional data passed from the second instance从第二个实例传递的附加数据的JSON对象

This event will be emitted inside the primary instance of your application when a second instance has been executed and calls app.requestSingleInstanceLock().当执行第二个实例并调用appequestSingleInstanceLock()时,此事件将在应用程序的主实例内发出。

argv is an Array of the second instance's command line arguments, and workingDirectory is its current working directory. argv是第二个实例的命令行参数的数组,workingDirectory是其当前的工作目录。Usually applications respond to this by making their primary window focused and non-minimized.通常,应用程序通过使其主窗口集中且不最小化来对此作出响应。

Note: If the second instance is started by a different user than the first, the argv array will not include the arguments.如果第二个实例由与第一个实例不同的用户启动,则argv数组将不包括参数。

This event is guaranteed to be emitted after the ready event of app gets emitted.此事件保证在appready事件发出后发出。

Note: Extra command line arguments might be added by Chromium, such as --original-process-start-time.Chromium可能会添加额外的命令行参数,例如--original-process-start-time

Methods方法

The app object has the following methods:app对象具有以下方法:

Note: Some methods are only available on specific operating systems and are labeled as such.某些方法仅在特定的操作系统上可用,并被标记为这样。

app.quit()

Try to close all windows. 尝试关闭所有窗口。The before-quit event will be emitted first. 将首先发出before-quit事件。If all windows are successfully closed, the will-quit event will be emitted and by default the application will terminate.如果所有窗口都成功关闭,将发出will-quit事件,默认情况下应用程序将终止。

This method guarantees that all beforeunload and unload event handlers are correctly executed. 此方法可确保所有beforeunloadunload事件处理程序都能正确执行。It is possible that a window cancels the quitting by returning false in the beforeunload event handler.窗口可能通过在beforeunload事件处理程序中返回false来取消退出。

app.exit([exitCode])

  • exitCode Integer (optional)

Exits immediately with exitCode. exitCode defaults to 0.使用exitCode立即退出。exitCode默认为0。

All windows will be closed immediately without asking the user, and the before-quit and will-quit events will not be emitted.所有窗口将立即关闭,而无需询问用户,并且不会发出before-quitwill-quit事件。

app.relaunch([options])

  • options Object (optional)
    • args string[] (optional)
    • execPath string (optional)

Relaunches the app when current instance exits.当当前实例退出时重新启动应用程序。

By default, the new instance will use the same working directory and command line arguments with current instance. 默认情况下,新实例将使用与当前实例相同的工作目录和命令行参数。When args is specified, the args will be passed as command line arguments instead. 当指定了args时,这些args将作为命令行参数传递。When execPath is specified, the execPath will be executed for relaunch instead of current app.当指定execPath时,将执行execPath以重新启动,而不是当前应用程序。

Note that this method does not quit the app when executed, you have to call app.quit or app.exit after calling app.relaunch to make the app restart.请注意,此方法在执行时不会退出应用程序,您必须在调用app.relaunch后调用app.quitapp.exit才能重新启动应用程序。

When app.relaunch is called for multiple times, multiple instances will be started after current instance exited.当多次调用app.relaunch时,当前实例退出后会启动多个实例。

An example of restarting current instance immediately and adding a new command line argument to the new instance:立即重新启动当前实例并向新实例添加新命令行参数的示例:

const { app } = require('electron')

app.relaunch({ args: process.argv.slice(1).concat(['--relaunch']) })
app.exit(0)

app.isReady()

Returns boolean - true if Electron has finished initializing, false otherwise. 返回boolean - 如果Electron已完成初始化,则返回true,否则返回falseSee also app.whenReady().另请参阅app.whenReady()

app.whenReady()

Returns 返回Promise<void> - fulfilled when Electron is initialized. Electron初始化时完成。May be used as a convenient alternative to checking app.isReady() and subscribing to the ready event if the app is not ready yet.如果应用程序尚未准备就绪,则可以用作检查app.isReady()和订阅ready事件的方便替代方法。

app.focus([options])

  • options Object (optional)
    • steal boolean macOS - Make the receiver the active app even if another app is currently active.即使另一个应用程序当前处于活动状态,也要将接收器设为活动应用程序。

On Linux, focuses on the first visible window. On macOS, makes the application the active app. 在Linux上,重点关注第一个可见窗口。在macOS上,使应用程序成为活动应用程序。On Windows, focuses on the application's first window.在Windows上,重点关注应用程序的第一个窗口。

You should seek to use the steal option as sparingly as possible.你应该尽量少用steal选项。

app.hide() macOS

Hides all application windows without minimizing them.隐藏所有应用程序窗口而不最小化它们。

app.isHidden() macOS

Returns 返回boolean - true if the application—including all of its windows—is hidden (e.g. with Command-H), false otherwise.如果应用程序包括其所有窗口都被隐藏(例如使用Command-H),则为true,否则为false

app.show() macOS

Shows application windows after they were hidden. 显示隐藏后的应用程序窗口。Does not automatically focus them.不会自动聚焦。

app.setAppLogsPath([path])

  • path string (optional) - A custom path for your logs. 日志的自定义路径。Must be absolute.必须是绝对的。

Sets or creates a directory your app's logs which can then be manipulated with app.getPath() or app.setPath(pathName, newPath).设置或创建应用程序日志的目录,然后可以使用app.getPath()app.setPath(pathName, newPath)对其进行操作。

Calling app.setAppLogsPath() without a path parameter will result in this directory being set to ~/Library/Logs/YourAppName on macOS, and inside the userData directory on Linux and Windows.在没有path参数的情况下调用app.setAppLogsPath()将导致此目录在macOS上设置为~/Library/Logs/YourAppName,在Linux和Windows上设置为userData目录。

app.getAppPath()

Returns 返回string - The current application directory.当前应用程序目录。

app.getPath(name)

  • name string - You can request the following paths by the name:您可以通过名称请求以下路径:
    • home User's home directory.用户的主目录。
    • appData Per-user application data directory, which by default points to:每个用户的应用程序数据目录,默认情况下指向:
      • %APPDATA% on WindowsWindows上的%APPDATA%
      • $XDG_CONFIG_HOME or ~/.config on LinuxLinux上的$XDG_CONFIG_HOME~/.config
      • ~/Library/Application Support on macOSMacOS上的~/Library/Application Support
    • userData The directory for storing your app's configuration files, which by default is the appData directory appended with your app's name. 用于存储应用程序配置文件的目录,默认情况下是附加了应用程序名称的appData目录。By convention files storing user data should be written to this directory, and it is not recommended to write large files here because some environments may backup this directory to cloud storage.按照惯例,存储用户数据的文件应写入此目录,不建议在此处写入大文件,因为某些环境可能会将此目录备份到云存储。
    • sessionData The directory for storing data generated by Session, such as localStorage, cookies, disk cache, downloaded dictionaries, network state, devtools files. 用于存储Session生成的数据的目录,如localStorage、cookie、磁盘缓存、下载的词典、网络状态、devtools文件。By default this points to userData. 默认情况下,它指向userDataChromium may write very large disk cache here, so if your app does not rely on browser storage like localStorage or cookies to save user data, it is recommended to set this directory to other locations to avoid polluting the userData directory.Chromium可能会在此处写入非常大的磁盘缓存,因此,如果您的应用程序不依赖浏览器存储(如localStorage或cookie)来保存用户数据,建议将此目录设置为其他位置,以避免污染userData目录。
    • temp Temporary directory.临时目录。
    • exe The current executable file.当前可执行文件。
    • module The libchromiumcontent library.libchromiumcontent库。
    • desktop The current user's Desktop directory.当前用户的桌面目录。
    • documents Directory for a user's "My Documents".用户“我的文档”的目录;。
    • downloads Directory for a user's downloads.用户下载的目录。
    • music Directory for a user's music.用户音乐的目录。
    • pictures Directory for a user's pictures.用户图片的目录。
    • videos Directory for a user's videos.用户视频的目录。
    • recent Directory for the user's recent files (Windows only).用户最近文件的目录(仅限Windows)。
    • logs Directory for your app's log folder.应用程序日志文件夹的目录。
    • crashDumps Directory where crash dumps are stored.存储故障转储的目录。

Returns string - A path to a special directory or file associated with name. 返回string - 与name关联的特殊目录或文件的路径。On failure, an Error is thrown.失败时,将引发一个Error

If app.getPath('logs') is called without called app.setAppLogsPath() being called first, a default log directory will be created equivalent to calling app.setAppLogsPath() without a path parameter.如果调用app.getPath('logs')时没有首先调用被调用的app.setAppLogsPath(),则将创建一个默认日志目录,相当于在没有path参数的情况下调用app.setAppLogsPath()

app.getFileIcon(path[, options])

  • path string
  • options Object (optional)
    • size string
      • small - 16x16
      • normal - 32x32
      • large - 48x48 on Linux, 32x32 on Windows, unsupported on macOS.Linux上为48x48,Windows上为32x32,macOS不支持。

Returns Promise<NativeImage> - fulfilled with the app's icon, which is a NativeImage.返回Promise<NativeImage> - 用应用程序的图标实现,该图标是NativeImage

Fetches a path's associated icon.获取路径的关联图标。

On Windows, there a 2 kinds of icons:Windows上,有两种图标:

  • Icons associated with certain file extensions, like .mp3, .png, etc.与某些文件扩展名相关联的图标,如.mp3.png等。
  • Icons inside the file itself, like .exe, .dll, .ico.文件内部的图标,如.exe.dll.ico

On Linux and macOS, icons depend on the application associated with file mime type.LinuxmacOS上,图标取决于与文件mime类型相关的应用程序。

app.setPath(name, path)

  • name string
  • path string

Overrides the path to a special directory or file associated with name. 覆盖与name关联的特殊目录或文件的pathIf the path specifies a directory that does not exist, an Error is thrown. 如果路径指定的目录不存在,则会引发ErrorIn that case, the directory should be created with fs.mkdirSync or similar.在这种情况下,应该使用fs.mkdirSync或类似方法创建目录。

You can only override paths of a name defined in app.getPath.您只能覆盖在app.getPath中定义的name的路径。

By default, web pages' cookies and caches will be stored under the sessionData directory. 默认情况下,网页的cookie和缓存将存储在sessionData目录下。If you want to change this location, you have to override the sessionData path before the ready event of the app module is emitted.如果要更改此位置,则必须在发出app模块的ready事件之前覆盖sessionData路径。

app.getVersion()

Returns string - The version of the loaded application. 返回string - 加载的应用程序的版本。If no version is found in the application's package.json file, the version of the current bundle or executable is returned.如果在应用程序的package.json文件中找不到版本,则返回当前捆绑包或可执行文件的版本。

app.getName()

Returns string - The current application's name, which is the name in the application's package.json file.返回string - 当前应用程序的名称,即应用程序的package.json文件中的名称。

Usually the name field of package.json is a short lowercase name, according to the npm modules spec. 根据npm模块规范, package.jsonname字段通常是一个小写的短名称。You should usually also specify a productName field, which is your application's full capitalized name, and which will be preferred over name by Electron.您通常还应该指定一个productName字段,这是您的应用程序的大写全名,它将优先于Electron的name

app.setName(name)

  • name string

Overrides the current application's name.覆盖当前应用程序的名称。

Note: This function overrides the name used internally by Electron; it does not affect the name that the OS uses.此函数覆盖Electron内部使用的名称;它不会影响操作系统使用的名称。

app.getLocale()

Returns string - The current application locale, fetched using Chromium's l10n_util library. 返回string - 使用Chromium的l10n_util库获取的当前应用程序区域设置。Possible return values are documented here.此处记录了可能的返回值。

To set the locale, you'll want to use a command line switch at app startup, which may be found here.要设置区域设置,您需要在应用程序启动时使用命令行开关,可以在此处找到。

Note: When distributing your packaged app, you have to also ship the locales folder.分发打包的应用程序时,还必须附带locales文件夹。

Note: On Windows, you have to call it after the ready events gets emitted.在Windows上,您必须在ready事件发出后调用它。

app.getLocaleCountryCode()

Returns string - User operating system's locale two-letter ISO 3166 country code. 返回string - 用户操作系统的区域设置,由两个字母组成的ISO 3166国家代码。The value is taken from native OS APIs.该值取自本机操作系统API。

Note: When unable to detect locale country code, it returns empty string.当无法检测区域设置国家/地区代码时,它将返回空字符串。

app.addRecentDocument(path) macOS Windows

  • path string

Adds path to the recent documents list.path添加到最近的文档列表。

This list is managed by the OS. 此列表由操作系统管理。On Windows, you can visit the list from the task bar, and on macOS, you can visit it from dock menu.在Windows上,您可以从任务栏访问列表,在macOS上,您也可以从dock菜单访问列表。

app.clearRecentDocuments() macOS Windows

Clears the recent documents list.清除最近的文档列表。

app.setAsDefaultProtocolClient(protocol[, path, args])

  • protocol string - The name of your protocol, without ://. 您的协议名称,不带://For example, if you want your app to handle electron:// links, call this method with electron as the parameter.例如,如果您希望您的应用程序处理electron://链接,请使用electron作为参数调用此方法。
  • path string (optional) Windows - The path to the Electron executable. Electron可执行文件的路径。Defaults to 默认为process.execPath
  • args string[] (optional) Windows - Arguments passed to the executable. Defaults to an empty array传递给可执行文件的参数。默认为空数组

Returns boolean返回boolean - Whether the call succeeded.呼叫是否成功。

Sets the current executable as the default handler for a protocol (aka URI scheme). 将当前可执行文件设置为协议(又名URI方案)的默认处理程序。It allows you to integrate your app deeper into the operating system. 它允许您将应用程序更深入地集成到操作系统中。Once registered, all links with your-protocol:// will be opened with the current executable. 注册后,与your-protocol://的所有链接都将使用当前可执行文件打开。The whole link, including protocol, will be passed to your application as a parameter.整个链接,包括协议,将作为参数传递给您的应用程序。

Note: On macOS, you can only register protocols that have been added to your app's info.plist, which cannot be modified at runtime. 在macOS上,您只能注册已添加到应用程序info.plist的协议,该协议在运行时无法修改。However, you can change the file during build time via Electron Forge, Electron Packager, or by editing info.plist with a text editor. 但是,您可以在构建期间通过Electron ForgeElectron Packager或使用文本编辑器编辑info.plist来更改文件。Please refer to Apple's documentation for details.有关详细信息,请参阅苹果公司的文档

Note: In a Windows Store environment (when packaged as an appx) this API will return true for all calls but the registry key it sets won't be accessible by other applications. 在Windows应用商店环境中(打包为appx时),此API将为所有调用返回true,但其他应用程序无法访问它设置的注册表项。In order to register your Windows Store application as a default protocol handler you must declare the protocol in your manifest.为了将Windows应用商店应用程序注册为默认协议处理程序,您必须在清单中声明该协议

The API uses the Windows Registry and LSSetDefaultHandlerForURLScheme internally.API在内部使用Windows注册表和LSSetDefaultHandlerForURLScheme

app.removeAsDefaultProtocolClient(protocol[, path, args]) macOS Windows

  • protocol string - The name of your protocol, without ://.您的协议名称,不带://
  • path string (optional) Windows - Defaults to 默认为process.execPath
  • args string[] (optional) Windows - Defaults to an empty array默认为空数组

Returns 返回boolean - Whether the call succeeded.呼叫是否成功。

This method checks if the current executable as the default handler for a protocol (aka URI scheme). 此方法检查当前可执行文件是否作为协议(又名URI方案)的默认处理程序。If so, it will remove the app as the default handler.如果是这样,它将删除该应用程序作为默认处理程序。

app.isDefaultProtocolClient(protocol[, path, args])

  • protocol string - The name of your protocol, without ://.您的协议名称,不带://
  • path string (optional) Windows - Defaults to 默认为process.execPath
  • args string[] (optional) Windows - Defaults to an empty array默认为空数组

Returns 返回boolean - Whether the current executable is the default handler for a protocol (aka URI scheme).当前可执行文件是否是协议(又名URI方案)的默认处理程序。

Note: On macOS, you can use this method to check if the app has been registered as the default protocol handler for a protocol. 在macOS上,您可以使用此方法检查应用程序是否已注册为协议的默认协议处理程序。You can also verify this by checking ~/Library/Preferences/com.apple.LaunchServices.plist on the macOS machine. 您也可以通过检查macOS机器上的~/Library/Preferences/com.apple.LaunchServices.plist来验证这一点。Please refer to Apple's documentation for details.有关详细信息,请参阅苹果公司的文档

The API uses the Windows Registry and LSCopyDefaultHandlerForURLScheme internally.API在内部使用Windows注册表和LSCopyDefaultHandlerForURLScheme

app.getApplicationNameForProtocol(url)

  • url string - a URL with the protocol name to check. 带有要检查的协议名称的URL。Unlike the other methods in this family, this accepts an entire URL, including :// at a minimum (e.g. https://).与该系列中的其他方法不同,它接受整个URL,至少包括://(例如https://)。

Returns 返回string - Name of the application handling the protocol, or an empty string if there is no handler. 处理协议的应用程序的名称,如果没有处理程序,则为空字符串。For instance, if Electron is the default handler of the URL, this could be Electron on Windows and Mac. 例如,如果Electron是URL的默认处理程序,那么它可能是Windows和Mac上的ElectronHowever, don't rely on the precise format which is not guaranteed to remain unchanged. 然而,不要依赖精确的格式,因为它不能保证保持不变。Expect a different format on Linux, possibly with a .desktop suffix.在Linux上预期会有不同的格式,可能带有.desktop后缀。

This method returns the application name of the default handler for the protocol (aka URI scheme) of a URL.此方法返回URL的协议(又名URI方案)的默认处理程序的应用程序名称。

app.getApplicationInfoForProtocol(url) macOS Windows

  • url string - a URL with the protocol name to check. Unlike the other methods in this family, this accepts an entire URL, including :// at a minimum (e.g. https://).带有要检查的协议名称的URL。与该系列中的其他方法不同,它接受整个URL,至少包括://(例如https://)。

Returns 返回Promise<Object> - Resolve with an object containing the following:使用包含以下内容的对象进行解析:

  • icon NativeImage - the display icon of the app handling the protocol.处理协议的应用程序的显示图标。
  • path string - installation path of the app handling the protocol.处理协议的应用程序的安装路径。
  • name string - display name of the app handling the protocol.处理协议的应用程序的显示名称。

This method returns a promise that contains the application name, icon and path of the default handler for the protocol (aka URI scheme) of a URL.此方法返回一个promise,其中包含URL的协议(又名URI方案)的默认处理程序的应用程序名称、图标和路径。

app.setUserTasks(tasks) Windows

  • tasks Task[] - Array of Task objectsTask对象数组

Adds tasks to the Tasks category of the Jump List on Windows.tasks添加到Windows上“跳转列表”的Tasks类别中。

tasks is an array of Task objects.tasksTask对象的数组。

Returns 返回boolean - Whether the call succeeded.呼叫是否成功。

Note: If you'd like to customize the Jump List even more use app.setJumpList(categories) instead.如果您想自定义跳转列表,请使用app.setJumpList(categories)

app.getJumpListSettings() Windows

Returns 返回Object:

  • minItems Integer - The minimum number of items that will be shown in the Jump List (for a more detailed description of this value see the MSDN docs).将在跳转列表中显示的最小项目数(有关此值的详细描述,请参阅MSDN文档)。
  • removedItems JumpListItem[] - Array of JumpListItem objects that correspond to items that the user has explicitly removed from custom categories in the Jump List. JumpListItem对象的数组,这些对象对应于用户已从跳转列表中的自定义类别中明确删除的项目。These items must not be re-added to the Jump List in the next call to app.setJumpList(), Windows will not display any custom category that contains any of the removed items.下一次调用app.setJumpList()时,这些项目不得重新添加到跳转列表中,Windows将不会显示任何包含任何已删除项目的自定义类别。

app.setJumpList(categories) Windows

  • categories JumpListCategory[] | null - Array of JumpListCategory objects.JumpListCategory对象的数组。

Returns 返回string

Sets or removes a custom Jump List for the application, and returns one of the following strings:设置或删除应用程序的自定义跳转列表,并返回以下字符串之一:

  • ok - Nothing went wrong.没有出什么问题。
  • error - One or more errors occurred, enable runtime logging to figure out the likely cause.出现一个或多个错误,请启用运行时日志记录以找出可能的原因。
  • invalidSeparatorError - An attempt was made to add a separator to a custom category in the Jump List. 试图在跳转列表中的自定义类别中添加分隔符。Separators are only allowed in the standard Tasks category.分隔符只允许出现在标准的Tasks类别中。
  • fileTypeRegistrationError - An attempt was made to add a file link to the Jump List for a file type the app isn't registered to handle.试图为应用程序未注册处理的文件类型向跳转列表添加文件链接。
  • customCategoryAccessDeniedError - Custom categories can't be added to the Jump List due to user privacy or group policy settings.由于用户隐私或组策略设置的原因,无法将自定义类别添加到跳转列表中。

If categories is null the previously set custom Jump List (if any) will be replaced by the standard Jump List for the app (managed by Windows).如果categoriesnull,则之前设置的自定义跳转列表(如果有)将被应用程序的标准跳转列表(由Windows管理)所取代。

Note: If a JumpListCategory object has neither the type nor the name property set then its type is assumed to be tasks. 如果JumpListCategory对象既没有type也没有name属性集,则假定其typetasksIf the name property is set but the type property is omitted then the type is assumed to be custom.如果设置了name属性,但省略了type属性,则假定该typecustom

Note: Users can remove items from custom categories, and Windows will not allow a removed item to be added back into a custom category until after the next successful call to app.setJumpList(categories). 用户可以从自定义类别中删除项目,在下一次成功调用app.setJumpList(categories)之前,Windows不允许将已删除的项目添加回自定义类别。Any attempt to re-add a removed item to a custom category earlier than that will result in the entire custom category being omitted from the Jump List. 任何提前将已删除的项目重新添加到自定义类别的尝试都将导致整个自定义类别从跳转列表中被省略。The list of removed items can be obtained using app.getJumpListSettings().可以使用app.getJumpListSettings()获取已删除项目的列表。

Note: The maximum length of a Jump List item's description property is 260 characters. 跳转列表项的description属性的最大长度为260个字符。Beyond this limit, the item will not be added to the Jump List, nor will it be displayed.超过此限制,该项目将不会添加到跳转列表中,也不会显示。

Here's a very simple example of creating a custom Jump List:下面是一个创建自定义跳转列表的非常简单的示例:

const { app } = require('electron')

app.setJumpList([
{
type: 'custom',
name: 'Recent Projects',
items: [
{ type: 'file', path: 'C:\\Projects\\project1.proj' },
{ type: 'file', path: 'C:\\Projects\\project2.proj' }
]
},
{ // has a name so `type` is assumed to be "custom"
name: 'Tools',
items: [
{
type: 'task',
title: 'Tool A',
program: process.execPath,
args: '--run-tool-a',
icon: process.execPath,
iconIndex: 0,
description: 'Runs Tool A'
},
{
type: 'task',
title: 'Tool B',
program: process.execPath,
args: '--run-tool-b',
icon: process.execPath,
iconIndex: 0,
description: 'Runs Tool B'
}
]
},
{ type: 'frequent' },
{ // has no name and no type so `type` is assumed to be "tasks"
items: [
{
type: 'task',
title: 'New Project',
program: process.execPath,
args: '--new-project',
description: 'Create a new project.'
},
{ type: 'separator' },
{
type: 'task',
title: 'Recover Project',
program: process.execPath,
args: '--recover-project',
description: 'Recover Project'
}
]
}
])

app.requestSingleInstanceLock([additionalData])

  • additionalData Record<any, any> (optional) - A JSON object containing additional data to send to the first instance.一个JSON对象,包含要发送到第一个实例的附加数据。

Returns 返回boolean

The return value of this method indicates whether or not this instance of your application successfully obtained the lock. 此方法的返回值指示应用程序的此实例是否成功获取了锁。If it failed to obtain the lock, you can assume that another instance of your application is already running with the lock and exit immediately.如果它未能获得锁,您可以假设您的应用程序的另一个实例已经在使用锁运行,然后立即退出。

I.e. This method returns true if your process is the primary instance of your application and your app should continue loading. 如果您的进程是应用程序的主要实例,并且您的应用程序应该继续加载,则此方法返回trueIt returns false if your process should immediately quit as it has sent its parameters to another instance that has already acquired the lock.如果您的进程在将其参数发送到另一个已获取锁的实例时应立即退出,则返回false

On macOS, the system enforces single instance automatically when users try to open a second instance of your app in Finder, and the open-file and open-url events will be emitted for that. 在macOS上,当用户试图在Finder中打开应用程序的第二个实例时,系统会自动强制执行单个实例,并为此发出open-fileopen-url事件。However when users start your app in command line, the system's single instance mechanism will be bypassed, and you have to use this method to ensure single instance.然而,当用户在命令行中启动你的应用程序时,系统的单实例机制将被绕过,你必须使用这种方法来确保单实例。

An example of activating the window of primary instance when a second instance starts:当第二个实例启动时激活主实例窗口的示例:

const { app } = require('electron')
let myWindow = null

const additionalData = { myKey: 'myValue' }
const gotTheLock = app.requestSingleInstanceLock(additionalData)

if (!gotTheLock) {
app.quit()
} else {
app.on('second-instance', (event, commandLine, workingDirectory, additionalData) => {
// Print out data received from the second instance.
console.log(additionalData)

// Someone tried to run a second instance, we should focus our window.
if (myWindow) {
if (myWindow.isMinimized()) myWindow.restore()
myWindow.focus()
}
})

// Create myWindow, load the rest of the app, etc...
app.whenReady().then(() => {
myWindow = createWindow()
})
}

app.hasSingleInstanceLock()

Returns 返回boolean

This method returns whether or not this instance of your app is currently holding the single instance lock. 此方法返回应用程序的此实例当前是否持有单实例锁。You can request the lock with app.requestSingleInstanceLock() and release with app.releaseSingleInstanceLock()您可以使用app.requestSingleInstanceLock()请求锁定,并使用app.releaseSingleInstanceLock()释放

app.releaseSingleInstanceLock()

Releases all locks that were created by requestSingleInstanceLock. 释放requestSingleInstanceLock创建的所有锁。This will allow multiple instances of the application to once again run side by side.这将允许应用程序的多个实例再次并行运行。

app.setUserActivity(type, userInfo[, webpageURL]) macOS

  • type string - Uniquely identifies the activity. 唯一标识活动。Maps to NSUserActivity.activityType.映射到NSUserActivity.activityType
  • userInfo any - App-specific state to store for use by another device.要存储以供其他设备使用的应用程序特定状态。
  • webpageURL string (optional) - The webpage to load in a browser if no suitable app is installed on the resuming device. 如果恢复设备上没有安装合适的应用程序,则要在浏览器中加载的网页。The scheme must be http or https.方案必须是httphttps

Creates an NSUserActivity and sets it as the current activity. 创建NSUserActivity并将其设置为当前活动。The activity is eligible for Handoff to another device afterward.活动之后有资格切换到另一个设备。

app.getCurrentActivityType() macOS

Returns 返回string - The type of the currently running activity.当前正在运行的活动的类型。

app.invalidateCurrentActivity() macOS

Invalidates the current Handoff user activity.使当前切换用户活动无效。

app.resignCurrentActivity() macOS

Marks the current Handoff user activity as inactive without invalidating it.将当前切换用户活动标记为非活动,而不使其无效。

app.updateCurrentActivity(type, userInfo) macOS

  • type string - Uniquely identifies the activity. 唯一标识活动。Maps to NSUserActivity.activityType.映射到NSUserActivity.activityType
  • userInfo any - App-specific state to store for use by another device.要存储以供其他设备使用的应用程序特定状态。

Updates the current activity if its type matches type, merging the entries from userInfo into its current userInfo dictionary.如果当前活动的类型与type匹配,则更新当前活动,将userInfo中的条目合并到其当前userInfo字典中。

app.setAppUserModelId(id) Windows

  • id string

Changes the Application User Model ID to id.应用程序用户模型ID更改为id

app.setActivationPolicy(policy) macOS

  • policy string - Can be 'regular', 'accessory', or 'prohibited'.可以是'regular'、'accessory'或'prohibited'。

Sets the activation policy for a given app.设置给定应用程序的激活策略。

Activation policy types:激活策略类型:

  • 'regular' - The application is an ordinary app that appears in the Dock and may have a user interface.该应用程序是一个出现在Dock中的普通应用程序,可能有一个用户界面。
  • 'accessory' - The application doesn’t appear in the Dock and doesn’t have a menu bar, but it may be activated programmatically or by clicking on one of its windows.该应用程序不会出现在Dock中,也没有菜单栏,但它可以通过编程或单击其中一个窗口来激活。
  • 'prohibited' - The application doesn’t appear in the Dock and may not create windows or be activated.该应用程序不会出现在Dock中,可能不会创建窗口或被激活。

app.importCertificate(options, callback) Linux

  • options Object
    • certificate string - Path for the pkcs12 file.pkcs12文件的路径。
    • password string - Passphrase for the certificate.证书的密码短语。
  • callback Function
    • result Integer - Result of import.导入的结果。

Imports the certificate in pkcs12 format into the platform certificate store. 将pkcs12格式的证书导入到平台证书存储中。callback is called with the result of import operation, a value of 0 indicates success while any other value indicates failure according to Chromium net_error_list.根据Chromium net_error_list,使用导入操作的result调用callback,值为0表示成功,而任何其他值表示失败。

app.configureHostResolver(options)

  • options Object
    • enableBuiltInResolver boolean (optional) - Whether the built-in host resolver is used in preference to getaddrinfo. 是否优先使用内置主机解析程序而不是getaddrinfo。When enabled, the built-in resolver will attempt to use the system's DNS settings to do DNS lookups itself. 启用后,内置解析程序将尝试使用系统的DNS设置自行进行DNS查找。Enabled by default on macOS, disabled by default on Windows and Linux.在macOS上默认启用,在Windows和Linux上默认禁用。
    • secureDnsMode string (optional) - Can be "off", "automatic" or "secure". 可以是"off"、自动"automatic"或是"secure"。Configures the DNS-over-HTTP mode. 配置DNS over HTTP模式。When "off", no DoH lookups will be performed. 当"off"时,将不会执行任何DoH查找。When "automatic", DoH lookups will be performed first if DoH is available, and insecure DNS lookups will be performed as a fallback. 当"automatic"时,如果DoH可用,将首先执行DoH查找,并且将执行不安全的DNS查找作为后备。When "secure", only DoH lookups will be performed. Defaults to "automatic".当"secure"时,将只执行DoH查找。默认为"automatic"。
    • secureDnsServers string[] (optional) - A list of DNS-over-HTTP server templates. DNS over HTTP服务器模板的列表。See RFC8484 § 3 for details on the template format. 有关模板格式的详细信息,请参阅RFC8484 § 3Most servers support the POST method; the template for such servers is simply a URI. 大多数服务器都支持POST方法;这种服务器的模板只是一个URI。Note that for some DNS providers, the resolver will automatically upgrade to DoH unless DoH is explicitly disabled, even if there are no DoH servers provided in this list.请注意,对于某些DNS提供商,解析程序将自动升级到DoH,除非明确禁用了DoH,即使此列表中没有提供DoH服务器。
    • enableAdditionalDnsQueryTypes boolean (optional) - Controls whether additional DNS query types, e.g. HTTPS (DNS type 65) will be allowed besides the traditional A and AAAA queries when a request is being made via insecure DNS. 控制当通过不安全的DNS进行请求时,除了传统的A和AAAA查询外,是否允许其他DNS查询类型,例如HTTPS(DNS类型65)。Has no effect on Secure DNS which always allows additional types. 对始终允许附加类型的安全DNS没有影响。Defaults to true.默认为true

Configures host resolution (DNS and DNS-over-HTTPS). 配置主机解析(DNS和HTTPS上的DNS)。By default, the following resolvers will be used, in order:默认情况下,将按顺序使用以下解析器:

  1. DNS-over-HTTPS, if the DNS provider supports it, thenHTTPS上的DNS,如果DNS提供商支持它,那么
  2. the built-in resolver (enabled on macOS only by default), then内置解析器(仅在macOS上默认启用),然后
  3. the system's resolver (e.g. getaddrinfo).系统的解析器(例如getaddrinfo)。

This can be configured to either restrict usage of non-encrypted DNS (secureDnsMode: "secure"), or disable DNS-over-HTTPS (secureDnsMode: "off"). 可以将其配置为限制使用未加密的DNS(secureDnsMode: "secure"),或禁用HTTPS上的DNS(secureDnsMode: "off")。It is also possible to enable or disable the built-in resolver.也可以启用或禁用内置解析器。

To disable insecure DNS, you can specify a secureDnsMode of "secure". 要禁用不安全的DNS,可以将secureDnsMode指定为"secure"If you do so, you should make sure to provide a list of DNS-over-HTTPS servers to use, in case the user's DNS configuration does not include a provider that supports DoH.如果您这样做,您应该确保提供一个使用HTTPS服务器的DNS列表,以防用户的DNS配置不包括支持DoH的提供商。

app.configureHostResolver({
secureDnsMode: 'secure',
secureDnsServers: [
'https://cloudflare-dns.com/dns-query'
]
})

This API must be called after the ready event is emitted.必须在发出ready事件之后调用此API。

app.disableHardwareAcceleration()

Disables hardware acceleration for current app.禁用当前应用程序的硬件加速。

This method can only be called before app is ready.此方法只能在应用程序准备就绪之前调用。

app.disableDomainBlockingFor3DAPIs()

By default, Chromium disables 3D APIs (e.g. WebGL) until restart on a per domain basis if the GPU processes crashes too frequently. 默认情况下,如果GPU进程过于频繁地崩溃,Chromium会禁用3D API(例如WebGL),直到按域重新启动。This function disables that behavior.此函数将禁用该行为。

This method can only be called before app is ready.此方法只能在应用程序准备就绪之前调用。

app.getAppMetrics()

Returns ProcessMetric[]: Array of ProcessMetric objects that correspond to memory and CPU usage statistics of all the processes associated with the app.返回ProcessMetric[]ProcessMetric对象的数组,这些对象对应于与应用程序关联的所有进程的内存和CPU使用情况统计信息。

app.getGPUFeatureStatus()

Returns GPUFeatureStatus - The Graphics Feature Status from chrome://gpu/.返回GPUFeatureStatus - 来自chrome://gpu/的图形功能状态。

Note: This information is only usable after the gpu-info-update event is emitted.此信息仅在发出gpu-info-update事件后可用。

app.getGPUInfo(infoType)

  • infoType string - Can be basic or complete.可以是basic,也可以是complete

Returns 返回Promise<unknown>

For infoType equal to complete: Promise is fulfilled with Object containing all the GPU Information as in chromium's GPUInfo object. 对于等于completeinfoType:Promise是通过包含chrome的GPUInfo对象中所有GPU信息的Object来实现的。This includes the version and driver information that's shown on chrome://gpu page.这包括上显示的版本和驱动程序信息chrome://gpu

For infoType equal to basic: Promise is fulfilled with Object containing fewer attributes than when requested with complete. 对于等于basicinfoType:Promise是用Object实现的,与用complete请求时相比,Object包含的属性更少。Here's an example of basic response:以下是一个基本响应示例:

{
auxAttributes:
{
amdSwitchable: true,
canSupportThreadedTextureMailbox: false,
directComposition: false,
directRendering: true,
glResetNotificationStrategy: 0,
inProcessGpu: true,
initializationTime: 0,
jpegDecodeAcceleratorSupported: false,
optimus: false,
passthroughCmdDecoder: false,
sandboxed: false,
softwareRendering: false,
supportsOverlays: false,
videoDecodeAcceleratorFlags: 0
},
gpuDevice:
[{ active: true, deviceId: 26657, vendorId: 4098 },
{ active: false, deviceId: 3366, vendorId: 32902 }],
machineModelName: 'MacBookPro',
machineModelVersion: '11.5'
}

Using basic should be preferred if only basic information like vendorId or driverId is needed.如果只需要vendorIddriverId等基本信息,则应优先使用basic

app.setBadgeCount([count]) Linux macOS

  • count Integer (optional) - If a value is provided, set the badge to the provided value otherwise, on macOS, display a plain white dot (e.g. unknown number of notifications). 如果提供了值,请将徽章设置为提供的值,否则,在macOS上,显示一个纯白点(例如未知数量的通知)。On Linux, if a value is not provided the badge will not display.在Linux上,如果没有提供值,徽章将不会显示。

Returns 返回boolean - Whether the call succeeded.呼叫是否成功。

Sets the counter badge for current app. Setting the count to 0 will hide the badge.设置当前应用程序的计数器徽章。将计数设置为0将隐藏徽章。

On macOS, it shows on the dock icon. On Linux, it only works for Unity launcher.在macOS上,它显示在dock图标上。在Linux上,它只适用于Unity启动器。

Note: Unity launcher requires a .desktop file to work. Unity启动器需要一个.desktop文件才能工作。For more information, please read the Unity integration documentation.有关更多信息,请阅读Unity集成文档

app.getBadgeCount() Linux macOS

Returns 返回Integer - The current value displayed in the counter badge.计数器徽章中显示的当前值。

app.isUnityRunning() Linux

Returns 返回boolean - Whether the current desktop environment is Unity launcher.当前桌面环境是否为Unity启动器。

app.getLoginItemSettings([options]) macOS Windows

  • options Object (optional)
    • path string (optional) Windows - The executable path to compare against. 要进行比较的可执行路径。Defaults to process.execPath.默认为process.execPath
    • args string[] (optional) Windows - The command-line arguments to compare against. 要进行比较的命令行参数。Defaults to an empty array.默认为空数组。

If you provided path and args options to app.setLoginItemSettings, then you need to pass the same arguments here for openAtLogin to be set correctly.如果您为app.setLoginItemSettings提供了pathargs选项,那么您需要在此处传递相同的参数才能正确设置openAtLogin

Returns Object:返回Object

  • openAtLogin boolean - true if the app is set to open at login.如果应用程序设置为在登录时打开,则为true
  • openAsHidden boolean macOS - true if the app is set to open as hidden at login. 如果应用程序设置为在登录时以隐藏方式打开,则为trueThis setting is not available on MAS builds.此设置在MAS生成上不可用。
  • wasOpenedAtLogin boolean macOS - true if the app was opened at login automatically. 如果应用程序在登录时自动打开,则为trueThis setting is not available on MAS builds.此设置在MAS生成上不可用。
  • wasOpenedAsHidden boolean macOS - true if the app was opened as a hidden login item. 如果应用程序是作为隐藏登录项打开的,则为trueThis indicates that the app should not open any windows at startup. 这表示应用程序在启动时不应打开任何窗口。This setting is not available on MAS builds.此设置在MAS生成上不可用。
  • restoreState boolean macOS - true if the app was opened as a login item that should restore the state from the previous session. 如果应用程序是作为登录项打开的,应该从上一个会话恢复状态,则为trueThis indicates that the app should restore the windows that were open the last time the app was closed. 这表示应用程序应恢复上次关闭应用程序时打开的窗口。This setting is not available on MAS builds.此设置在MAS生成上不可用。
  • executableWillLaunchAtLogin boolean Windows - true if app is set to open at login and its run key is not deactivated. 如果应用程序设置为在登录时打开,并且其运行密钥未被停用,则为trueThis differs from openAtLogin as it ignores the args option, this property will be true if the given executable would be launched at login with any arguments.这与openAtLogin不同,因为它忽略了args选项,如果给定的可执行文件在登录时使用任何参数启动,则此属性将为true
  • launchItems Object[]Windows
    • name stringWindows - name value of a registry entry.注册表项的名称值。
    • path stringWindows - The executable to an app that corresponds to a registry entry.对应于注册表项的应用程序的可执行文件。
    • args string[]Windows - the command-line arguments to pass to the executable.要传递给可执行文件的命令行参数。
    • scope stringWindows - one of user or machine. usermachine之一。Indicates whether the registry entry is under HKEY_CURRENT USER or HKEY_LOCAL_MACHINE.指示注册表项是在HKEY_CURRENT USER还是HKEY_LOCAL_MACHINE下。
    • enabled boolean Windows - true if the app registry key is startup approved and therefore shows as enabled in Task Manager and Windows settings.如果应用程序注册表项已批准启动,因此在任务管理器和Windows设置中显示为enabled,则为true

app.setLoginItemSettings(settings) macOS Windows

  • settings Object
    • openAtLogin boolean (optional) - true to open the app at login, false to remove the app as a login item. true表示在登录时打开应用程序,false表示将应用程序作为登录项删除。Defaults to false.默认为false
    • openAsHidden boolean (optional) macOS - true to open the app as hidden. true以隐藏方式打开应用程序。Defaults to false. 默认为falseThe user can edit this setting from the System Preferences so app.getLoginItemSettings().wasOpenedAsHidden should be checked when the app is opened to know the current value. 用户可以从系统首选项编辑此设置,因此在打开应用程序时应检查app.getLoginItemSettings().wasOpenedAsHidden以了解当前值。This setting is not available on MAS builds.此设置在MAS生成上不可用。
    • path string (optional) Windows - The executable to launch at login. 登录时要启动的可执行文件。Defaults to process.execPath.默认为process.execPath
    • args string[] (optional) Windows - The command-line arguments to pass to the executable. 要传递给可执行文件的命令行参数。Defaults to an empty array. 默认为空数组。Take care to wrap paths in quotes.注意将路径用引号括起来。
    • enabled boolean (optional) Windows - true will change the startup approved registry key and enable / disable the App in Task Manager and Windows Settings. true将更改启动批准的注册表项,并在任务管理器和Windows设置中enable / disable应用程序。Defaults to true.默认为true
    • name string (optional) Windows - value name to write into registry. 要写入注册表的值名称。Defaults to the app's AppUserModelId(). 默认为应用程序的AppUserModelId()Set the app's login item settings.设置应用程序的登录项目设置。

To work with Electron's autoUpdater on Windows, which uses Squirrel, you'll want to set the launch path to Update.exe, and pass arguments that specify your application name. 要在使用Squirrel的Windows上使用Electron的autoUpdater,您需要将启动路径设置为Updateexe,并传递指定应用程序名称的参数。For example:例如:

const appFolder = path.dirname(process.execPath)
const updateExe = path.resolve(appFolder, '..', 'Update.exe')
const exeName = path.basename(process.execPath)

app.setLoginItemSettings({
openAtLogin: true,
path: updateExe,
args: [
'--processStart', `"${exeName}"`,
'--process-start-args', `"--hidden"`
]
})

app.isAccessibilitySupportEnabled() macOS Windows

Returns 返回boolean - true if Chrome's accessibility support is enabled, false otherwise. 如果启用了Chrome的辅助功能支持,则为true,否则为falseThis API will return true if the use of assistive technologies, such as screen readers, has been detected. 如果检测到屏幕阅读器等辅助技术的使用,则此API将返回trueSee https://www.chromium.org/developers/design-documents/accessibility for more details.请参阅https://www.chromium.org/developers/design-documents/accessibility以了解更多详细信息。

app.setAccessibilitySupportEnabled(enabled) macOS Windows

Manually enables Chrome's accessibility support, allowing to expose accessibility switch to users in application settings. 手动启用Chrome的辅助功能支持,允许在应用程序设置中向用户公开辅助功能开关。See Chromium's accessibility docs for more details. 有关更多详细信息,请参阅Chromium的辅助功能文档Disabled by default.默认情况下已禁用。

This API must be called after the ready event is emitted.必须在发出ready事件之后调用此API。

Note: Rendering accessibility tree can significantly affect the performance of your app. 渲染辅助功能树会显著影响应用程序的性能。It should not be enabled by default.默认情况下不应启用它。

app.showAboutPanel()

Show the app's about panel options. 显示应用程序的关于面板选项。These options can be overridden with app.setAboutPanelOptions(options).这些选项可以用app.setAboutPanelOptions(options)覆盖。

app.setAboutPanelOptions(options)

  • options Object
    • applicationName string (optional) - The app's name.应用程序的名称。
    • applicationVersion string (optional) - The app's version.应用程序的版本。
    • copyright string (optional) - Copyright information.版权信息。
    • version string (optional) macOS - The app's build version number.应用程序的内部版本号。
    • credits string (optional) macOS Windows - Credit information.信用信息。
    • authors string[] (optional) Linux - List of app authors.应用程序作者列表。
    • website string (optional) Linux - The app's website.应用程序的网站。
    • iconPath string (optional) Linux Windows - Path to the app's icon in a JPEG or PNG file format. JPEG或PNG文件格式的应用程序图标的路径。On Linux, will be shown as 64x64 pixels while retaining aspect ratio.在Linux上,将显示为64x64像素,同时保留纵横比。

Set the about panel options. 设置“关于”面板选项。This will override the values defined in the app's .plist file on macOS. 这将覆盖macOS上应用程序的.plist文件中定义的值。See the Apple docs for more details. 有关更多详细信息,请参阅Apple文档On Linux, values must be set in order to be shown; there are no defaults.在Linux上,必须设置值才能显示;没有默认值。

If you do not set credits but still wish to surface them in your app, AppKit will look for a file named "Credits.html", "Credits.rtf", and "Credits.rtfd", in that order, in the bundle returned by the NSBundle class method main. 如果您没有设置credits,但仍希望在应用程序中显示信用,AppKit将在NSBundle类方法main返回的bundle中按顺序查找名为“Credits.html”、“Credits.rtf”和“Credits.rtfd”的文件。The first file found is used, and if none is found, the info area is left blank. 使用找到的第一个文件,如果没有找到,则信息区域为空。See Apple documentation for more information.有关更多信息,请参阅Apple文档

app.isEmojiPanelSupported()

Returns 返回boolean - whether or not the current OS version allows for native emoji pickers.当前操作系统版本是否允许使用本机表情符号选择器。

app.showEmojiPanel() macOS Windows

Show the platform's native emoji picker.显示平台的本地表情符号选取器。

app.startAccessingSecurityScopedResource(bookmarkData) mas

  • bookmarkData string - The base64 encoded security scoped bookmark data returned by the dialog.showOpenDialog or dialog.showSaveDialog methods.dialog.showOpenDialogdialog.showSaveDialog方法返回的base64编码的安全范围书签数据。

Returns 返回Function - This function must be called once you have finished accessing the security scoped file. 访问完安全范围的文件后,必须调用此函数。If you do not remember to stop accessing the bookmark, kernel resources will be leaked and your app will lose its ability to reach outside the sandbox completely, until your app is restarted.如果你不记得停止访问书签,内核资源将被泄露,你的应用程序将完全失去访问沙盒之外的能力,直到你的应用重新启动。

// Start accessing the file.
const stopAccessingSecurityScopedResource = app.startAccessingSecurityScopedResource(data)
// You can now access the file outside of the sandbox 🎉

// Remember to stop accessing the file once you've finished with it.
stopAccessingSecurityScopedResource()

Start accessing a security scoped resource. 开始访问安全范围内的资源。With this method Electron applications that are packaged for the Mac App Store may reach outside their sandbox to access files chosen by the user. 通过这种方法,为Mac应用商店打包的Electron应用程序可以访问其沙箱之外的用户选择的文件。See Apple's documentation for a description of how this system works.有关此系统如何工作的描述,请参阅苹果公司的文档

app.enableSandbox()

Enables full sandbox mode on the app. 在应用程序上启用完全沙箱模式。This means that all renderers will be launched sandboxed, regardless of the value of the sandbox flag in WebPreferences.这意味着,无论WebPreferences中sandbox标志的值如何,所有渲染器都将启动沙箱。

This method can only be called before app is ready.此方法只能在应用程序准备就绪之前调用。

app.isInApplicationsFolder() macOS

Returns 返回boolean - Whether the application is currently running from the systems Application folder. 应用程序当前是否在系统应用程序文件夹中运行。Use in combination with app.moveToApplicationsFolder()app.moveToApplicationsFolder()组合使用

app.moveToApplicationsFolder([options]) macOS

  • options Object (optional)
    • conflictHandler Function\<boolean> (optional) - A handler for potential conflict in move failure.移动失败中潜在冲突的处理程序。
      • conflictType string - The type of move conflict encountered by the handler; can be exists or existsAndRunning, where exists means that an app of the same name is present in the Applications directory and existsAndRunning means both that it exists and that it's presently running.处理程序遇到的移动冲突的类型;可以是existsexistsAndRunning,其中exists表示Applications目录中存在同名应用程序,existsAndRunning表示该应用程序存在并且当前正在运行。

Returns 返回boolean - Whether the move was successful. 此举是否成功。Please note that if the move is successful, your application will quit and relaunch.请注意,如果移动成功,您的应用程序将退出并重新启动。

No confirmation dialog will be presented by default. 默认情况下不会显示任何确认对话框。If you wish to allow the user to confirm the operation, you may do so using the dialog API.如果您希望允许用户确认操作,可以使用dialogAPI进行确认。

NOTE: This method throws errors if anything other than the user causes the move to fail. 如果除用户之外的任何其他原因导致移动失败,此方法将抛出错误。For instance if the user cancels the authorization dialog, this method returns false. 例如,如果用户取消了授权对话框,此方法将返回falseIf we fail to perform the copy, then this method will throw an error. 如果我们无法执行复制,那么这个方法将抛出一个错误。The message in the error should be informative and tell you exactly what went wrong.错误中的信息应该是有信息的,并准确地告诉你出了什么问题。

By default, if an app of the same name as the one being moved exists in the Applications directory and is not running, the existing app will be trashed and the active app moved into its place. 默认情况下,如果应用程序目录中存在与要移动的应用程序同名的应用程序,并且该应用程序运行,则现有应用程序将被销毁,活动应用程序将移动到其位置。If it is running, the pre-existing running app will assume focus and the previously active app will quit itself. 如果它正在运行,预先存在的正在运行的应用程序将占据焦点,而之前活动的应用程序则会自行退出。This behavior can be changed by providing the optional conflict handler, where the boolean returned by the handler determines whether or not the move conflict is resolved with default behavior. i.e. returning false will ensure no further action is taken, returning true will result in the default behavior and the method continuing.可以通过提供可选的冲突处理程序来更改此行为,其中处理程序返回的布尔值决定是否使用默认行为解决移动冲突。例如,返回false将确保不采取进一步的操作,返回true将导致默认行为和方法继续。

For example:

app.moveToApplicationsFolder({
conflictHandler: (conflictType) => {
if (conflictType === 'exists') {
return dialog.showMessageBoxSync({
type: 'question',
buttons: ['Halt Move', 'Continue Move'],
defaultId: 0,
message: 'An app of this name already exists'
}) === 1
}
}
})

Would mean that if an app already exists in the user directory, if the user chooses to 'Continue Move' then the function would continue with its default behavior and the existing app will be trashed and the active app moved into its place.这意味着,如果用户目录中已经存在应用程序,如果用户选择“继续移动”,则该功能将继续其默认行为,现有应用程序将被丢弃,活动应用程序将移动到其位置。

app.isSecureKeyboardEntryEnabled() macOS

Returns boolean - whether Secure Keyboard Entry is enabled.返回boolean - 是否启用了安全键盘输入

By default this API will return false.默认情况下,此API将返回false

app.setSecureKeyboardEntryEnabled(enabled) macOS

  • enabled boolean - Enable or disable Secure Keyboard Entry启用或禁用安全键盘输入

Set the Secure Keyboard Entry is enabled in your application.设置应用程序中启用的安全键盘输入

By using this API, important information such as password and other sensitive information can be prevented from being intercepted by other processes.通过使用此API,可以防止密码等重要信息和其他敏感信息被其他进程截获。

See Apple's documentation for more details.有关更多详细信息,请参阅苹果公司的文档

Note: Enable Secure Keyboard Entry only when it is needed and disable it when it is no longer needed.仅在需要时启用安全键盘输入,在不再需要时禁用安全键盘输入。

Properties属性

app.accessibilitySupportEnabled macOS Windows

A boolean property that's true if Chrome's accessibility support is enabled, false otherwise. 一个boolean属性,如果启用Chrome的可访问性支持,则为true,否则为falseThis property will be true if the use of assistive technologies, such as screen readers, has been detected. 如果检测到使用了辅助技术(如屏幕阅读器),则此属性为trueSetting this property to true manually enables Chrome's accessibility support, allowing developers to expose accessibility switch to users in application settings.手动将此属性设置为true将启用Chrome的辅助功能支持,允许开发人员在应用程序设置中将辅助功能开关公开给用户。

See Chromium's accessibility docs for more details. 有关更多详细信息,请参阅Chromium的辅助功能文档Disabled by default.默认情况下已禁用。

This API must be called after the ready event is emitted.必须在发出ready事件之后调用此API。

Note: Rendering accessibility tree can significantly affect the performance of your app. 渲染辅助功能树会显著影响应用程序的性能。It should not be enabled by default.默认情况下不应启用它。

app.applicationMenu

A Menu | null property that returns Menu if one has been set and null otherwise. Menu|null属性,如果设置了菜单,则返回Menu,否则返回nullUsers can pass a Menu to set this property.用户可以传递Menu来设置此属性。

app.badgeCount Linux macOS

An Integer property that returns the badge count for current app. Integer属性,用于返回当前应用程序的徽章计数。Setting the count to 0 will hide the badge.将计数设置为0将隐藏徽章。

On macOS, setting this with any nonzero integer shows on the dock icon. 在macOS上,使用任何非零整数进行设置都会显示在dock图标上。On Linux, this property only works for Unity launcher.在Linux上,此属性仅适用于Unity启动器。

Note: Unity launcher requires a .desktop file to work. Unity启动器需要一个.desktop文件才能工作。For more information, please read the Unity integration documentation.有关更多信息,请阅读Unity集成文档

Note: On macOS, you need to ensure that your application has the permission to display notifications for this property to take effect.在macOS上,您需要确保您的应用程序具有显示此属性生效通知的权限。

app.commandLine Readonly

A CommandLine object that allows you to read and manipulate the command line arguments that Chromium uses.一个CommandLine对象,允许您读取和操作Chromium使用的命令行参数。

app.dock macOS Readonly

A Dock | undefined object that allows you to perform actions on your app icon in the user's dock on macOS.Dock | undefined的对象,允许您在macOS上的用户Dock中对应用程序图标执行操作。

app.isPackaged Readonly

A boolean property that returns true if the app is packaged, false otherwise. 一个boolean性,如果应用程序已打包,则返回true,否则返回falseFor many apps, this property can be used to distinguish development and production environments.对于许多应用程序,此属性可用于区分开发环境和生产环境。

app.name

A string property that indicates the current application's name, which is the name in the application's package.json file.一个string属性,指示当前应用程序的名称,即应用程序的package.json文件中的名称。

Usually the name field of package.json is a short lowercase name, according to the npm modules spec. 根据npm模块规范,package.jsonname字段通常是一个小写的短名称。You should usually also specify a productName field, which is your application's full capitalized name, and which will be preferred over name by Electron.您通常还应该指定一个productName字段,这是您的应用程序的大写全名,它将优先于Electron的name

app.userAgentFallback

A string which is the user agent string Electron will use as a global fallback.作为用户代理字符串的stringElectron将用作全局回退。

This is the user agent that will be used when no user agent is set at the webContents or session level. 这是在webContentssession级别未设置用户代理时将使用的用户代理。It is useful for ensuring that your entire app has the same user agent. 它有助于确保您的整个应用程序具有相同的用户代理。Set to a custom value as early as possible in your app's initialization to ensure that your overridden value is used.在应用程序的初始化中尽早设置为自定义值,以确保使用覆盖的值。

app.runningUnderRosettaTranslation macOS Readonly Deprecated

A boolean which when true indicates that the app is currently running under the Rosetta Translator Environment.一个boolean,当为true时,表示应用程序当前正在Rosetta Translator环境下运行。

You can use this property to prompt users to download the arm64 version of your application when they are running the x64 version under Rosetta incorrectly.当用户在Rosetta下错误地运行x64版本时,您可以使用此属性提示用户下载应用程序的arm64版本。

Deprecated: This property is superceded by the runningUnderARM64Translation property which detects when the app is being translated to ARM64 in both macOS and Windows.此属性被runningUnderARM64Translation属性取代,该属性检测应用程序何时在macOS和Windows中被转换为ARM64。

app.runningUnderARM64Translation Readonly macOS Windows

A boolean which when true indicates that the app is currently running under an ARM64 translator (like the macOS Rosetta Translator Environment or Windows WOW).一个boolean,当为true时,表示应用程序当前正在ARM64翻译器(如macOS Rosetta翻译器环境或Windows WOW)下运行。

You can use this property to prompt users to download the arm64 version of your application when they are running the x64 version under Rosetta incorrectly.当用户在Rosetta下错误地运行x64版本时,您可以使用此属性提示用户下载应用程序的arm64版本。