Skip to content
github-actions[bot] edited this page Oct 15, 2025 · 2 revisions

Control your app in the macOS dock.

Overview

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.

Key Methods

Dock Icon Animation

BounceAsync(DockBounceType, CancellationToken)

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.

CancelBounce(int)

Parameters:

  • id - Id of the request

Description: Cancel the bounce of id.

Badge Management

SetBadge(string)

Parameters:

  • text - Badge text to display

Description: Sets the string to be displayed in the dock's badging area.

GetBadgeAsync(CancellationToken)

Returns: The badge string of the dock.

Description: Gets the string to be displayed in the dock's badging area.

Dock Menu

SetMenu(MenuItem[])

Parameters:

  • menuItems - Array of menu items for the dock menu

Description: Sets the application's dock menu.

GetMenu(CancellationToken)

Returns: The application's dock menu.

Description: Gets the application's dock menu.

Icon Management

SetIcon(string)

Parameters:

  • image - Icon image path

Description: Sets the image associated with this dock icon.

Visibility Control

Hide()

Description: Hides the dock icon.

Show()

Description: Shows the dock icon.

IsVisibleAsync(CancellationToken)

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.

Download Notifications

DownloadFinished(string)

Parameters:

  • filePath - Path to the downloaded file

Description: Bounces the Downloads stack if the filePath is inside the Downloads folder.

Properties

MenuItems

Type: IReadOnlyCollection

Description: Gets a read-only collection of all current dock menu items.

Usage Examples

Basic Dock Operations

// 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}");

Badge Notifications

// 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("");

Dock Icon Animation

// 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);

Dock Menu

// 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}");

Download Notifications

// Notify about completed download
var downloadPath = "/Users/username/Downloads/document.pdf";
Electron.Dock.DownloadFinished(downloadPath);

Custom Dock Icon

// 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");
}

Application Integration

// 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());
}

Related APIs

Additional Resources

Clone this wiki locally