-
Notifications
You must be signed in to change notification settings - Fork 0
Dock
Control your app in the macOS dock.
The Electron.Dock API provides control over your application's appearance and behavior in the macOS dock. This includes bouncing the dock icon, setting badges, managing menus, and controlling visibility.
Parameters:
-
type- Can be critical or informational -
cancellationToken(optional) - The cancellation token
Returns: An ID representing the request.
Description: When DockBounceType.Critical is passed, the dock icon will bounce until either the application becomes active or the request is canceled. When DockBounceType.Informational is passed, the dock icon will bounce for one second.
Parameters:
-
id- Id of the request
Description: Cancel the bounce of id.
Parameters:
-
text- Badge text to display
Description: Sets the string to be displayed in the dock's badging area.
Returns: The badge string of the dock.
Description: Gets the string to be displayed in the dock's badging area.
Parameters:
-
menuItems- Array of menu items for the dock menu
Description: Sets the application's dock menu.
Returns: The application's dock menu.
Description: Gets the application's dock menu.
Parameters:
-
image- Icon image path
Description: Sets the image associated with this dock icon.
Description: Hides the dock icon.
Description: Shows the dock icon.
Returns: Whether the dock icon is visible.
Description: Whether the dock icon is visible. The app.dock.show() call is asynchronous so this method might not return true immediately after that call.
Parameters:
-
filePath- Path to the downloaded file
Description: Bounces the Downloads stack if the filePath is inside the Downloads folder.
Type: IReadOnlyCollection
Description: Gets a read-only collection of all current dock menu items.
// Hide/Show dock icon
Electron.Dock.Hide();
await Task.Delay(2000);
Electron.Dock.Show();
// Check visibility
var isVisible = await Electron.Dock.IsVisibleAsync();
Console.WriteLine($"Dock visible: {isVisible}");// Set badge count
Electron.Dock.SetBadge("5");
// Get current badge
var badge = await Electron.Dock.GetBadgeAsync();
Console.WriteLine($"Current badge: {badge}");
// Clear badge
Electron.Dock.SetBadge("");// Bounce for attention
var bounceId = await Electron.Dock.BounceAsync(DockBounceType.Critical);
Console.WriteLine($"Bounce ID: {bounceId}");
// Cancel bounce after 3 seconds
await Task.Delay(3000);
Electron.Dock.CancelBounce(bounceId);
// Informational bounce
await Electron.Dock.BounceAsync(DockBounceType.Informational);// Create dock menu
var dockMenuItems = new[]
{
new MenuItem { Label = "Show Window", Click = () => ShowMainWindow() },
new MenuItem { Label = "Settings", Click = () => OpenSettings() },
new MenuItem { Type = MenuType.Separator },
new MenuItem { Label = "Exit", Click = () => Electron.App.Quit() }
};
// Set dock menu
Electron.Dock.SetMenu(dockMenuItems);
// Get current menu
var currentMenu = await Electron.Dock.GetMenu();
Console.WriteLine($"Menu items: {Electron.Dock.MenuItems.Count}");// Notify about completed download
var downloadPath = "/Users/username/Downloads/document.pdf";
Electron.Dock.DownloadFinished(downloadPath);// Set custom dock icon
Electron.Dock.SetIcon("assets/custom-dock-icon.png");
// Set icon based on status
if (isConnected)
{
Electron.Dock.SetIcon("assets/connected-icon.png");
}
else
{
Electron.Dock.SetIcon("assets/disconnected-icon.png");
}// Update dock badge based on unread count
UpdateDockBadge(unreadMessageCount);
void UpdateDockBadge(int count)
{
if (count > 0)
{
Electron.Dock.SetBadge(count.ToString());
}
else
{
Electron.Dock.SetBadge("");
}
}
// Animate dock when receiving message
private async void OnMessageReceived()
{
await Electron.Dock.BounceAsync(DockBounceType.Informational);
Electron.Dock.SetBadge((unreadCount + 1).ToString());
}- Electron.App - Application lifecycle events
- Electron.Notification - Desktop notifications
- Electron.Menu - Menu items for dock menu
- Electron Dock Documentation - Official Electron dock API
Want to contribute to this documentation? Please fork and create a PR! The Wiki is autogenerated from the /docs content in the repository.