app.badgeCount property macOS
An Integer property that returns the badge count for the current app. Setting the count to 0 will hide the badge. Setting this with any nonzero integer shows the count on the Dock icon. You need to ensure that your application has the permission to display notifications for this property to take effect.
app.dock property macOS readonly
A read-only Dock | undefined property that is Dock on macOS and undefined on all other platforms. Allows you to perform actions on your app icon in the user's dock.
Dock class overview
The Dock class controls the app in the macOS dock. It is available as a return value from other Electron API methods, not exported directly from the 'electron' module. It is only available in the main process.
dock.bounce() method
Bounces the dock icon. The method signature is dock.bounce([type]) where type is an optional string that can be 'critical' or 'informational', defaulting to 'informational'. It returns an Integer representing the request ID. When 'critical' is passed, the dock icon bounces until the application becomes active or the request is canceled. When 'informational' is passed, the dock icon bounces for one second, but the request remains active until the application becomes active or the request is canceled. This method can only be used while the app is not focused; when the app is focused it returns -1. macOS only.
dock.cancelBounce() method
Cancels the bounce animation for a dock icon. The method signature is dock.cancelBounce(id) where id is an Integer representing the bounce request ID returned by dock.bounce(). macOS only.
dock.downloadFinished() method
Bounces the Downloads stack if the provided file path is inside the Downloads folder. The method signature is dock.downloadFinished(filePath) where filePath is a string. macOS only.
dock.setBadge() method
Sets the string to be displayed in the dock's badging area. The method signature is dock.setBadge(text) where text is a string. The application must have permission to display notifications for this method to work. macOS only.
dock.getBadge() method
Returns the badge string currently displayed in the dock's badging area. The method signature is dock.getBadge() and returns a string. macOS only.
dock.hide() method
Hides the dock icon. The method signature is dock.hide(). There is a known issue where calling dock.hide() within one second of a previous call will have no effect. As a workaround, ensure at least one second has elapsed between calls, for example by deferring with a setTimeout of 1100ms or more after a previous call. macOS only.
dock.show() method
Shows the dock icon. The method signature is dock.show() and returns a Promise<void> that resolves when the dock icon is shown. macOS only.
dock.isVisible() method
Returns whether the dock icon is currently visible. The method signature is dock.isVisible() and returns a boolean. macOS only.
dock.setMenu() method
Sets the application's dock menu. The method signature is dock.setMenu(menu) where menu is a Menu object. macOS only.
dock.getMenu() method
Returns the application's dock menu. The method signature is dock.getMenu() and returns either a Menu object or null. macOS only.
dock.setIcon() method
Sets the image associated with the dock icon. The method signature is dock.setIcon(image) where image is either a NativeImage object or a string (file path). macOS only.
dock.bounce() requires notification permission
The dock.bounce() method requires the application to have permission to display notifications in order to work properly.
app.dock property access and availability
The Dock API is exposed via the app.dock property. There is a single Dock instance per Electron application, and this property only exists on macOS. The property is read-only.
dock.setMenu() method for custom Dock menu
The dock.setMenu() method accepts a Menu instance to set an app-defined custom Dock menu. It only works after the 'ready' event is fired. Unlike context menus, Dock context menus do not need to be manually instrumented using the menu.popup API; the Dock object handles click events automatically.
Dock menu triggered by right-click or Ctrl-click
The Dock menu is triggered by right-clicking or Ctrl-clicking the app icon. By default, the app's Dock menu includes system-provided window management utilities, such as the ability to show all windows, hide the app, and switch between different open windows.
Example: Setting a custom Dock menu
const { app, BrowserWindow, Menu } = require('electron/main')
app.whenReady().then(() => {
const dockMenu = Menu.buildFromTemplate([
{
label: 'New Window',
click: () => { const win = new BrowserWindow() }
}
])
app.dock?.setMenu(dockMenu)
})
Cross-platform features accessible via Dock on macOS
On macOS, the Dock is the entry point for certain cross-platform features like Recent Documents and Application Progress.