Skip to main content

Class: Dock

Class: Dock

Control your app in the macOS dock在macOS dock中控制您的应用程序

Process:进程:Main
This class is not exported from the 'electron' module. 此类不是从'electron'模块导出的。It is only available as a return value of other methods in the Electron API.它只能作为Electron API中其他方法的返回值使用。

The following example shows how to bounce your icon on the dock.以下示例显示了如何在dock上弹出图标。

const { app } = require('electron')
app.dock.bounce()

Instance Methods实例方法

dock.bounce([type]) macOS

  • type string (optional) - Can be critical or informational. 可以是criticalinformationalThe default is 默认值为informational

Returns返回Integer - an ID representing the request.表示该请求的ID。

When critical is passed, the dock icon will bounce until either the application becomes active or the request is canceled.当传入critical时,停靠图标将弹出,直到应用程序变为活动状态或请求被取消。

When informational is passed, the dock icon will bounce for one second. 当传入informational时,停靠图标将反弹一秒钟。However, the request remains active until either the application becomes active or the request is canceled.但是,在应用程序变为活动状态或请求被取消之前,请求一直处于活动状态。

Note: This method can only be used while the app is not focused; when the app is focused it will return -1.此方法只能在应用程序未聚焦时使用;当应用程序聚焦时,它将返回-1。

dock.cancelBounce(id) macOS

  • id Integer

Cancel the bounce of id.取消id的反弹。

dock.downloadFinished(filePath) macOS

  • filePath string

Bounces the Downloads stack if the filePath is inside the Downloads folder.如果文件路径位于下载文件夹中,则会跳出下载堆栈。

dock.setBadge(text) macOS

  • text string

Sets the string to be displayed in the dock’s badging area.设置要在驳接的徽标区域中显示的字符串。

dock.getBadge() macOS

Returns返回string - The badge string of the dock.dock的徽章字符串。

dock.hide() macOS

Hides the dock icon.隐藏停靠图标。

dock.show() macOS

Returns返回Promise<void> - Resolves when the dock icon is shown.显示dock图标时解决。

dock.isVisible() macOS

Returns返回boolean - Whether the dock icon is visible.停靠图标是否可见。

dock.setMenu(menu) macOS

Sets the application's [dock menu][dock-menu].设置应用程序的dock-menu

dock.getMenu() macOS

Returns返回Menu | null - The application's [dock menu][dock-menu].应用程序的dock-menu

dock.setIcon(image) macOS

Sets the image associated with this dock icon.设置与此停靠图标关联的image