Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 746
Tray
Add icons and context menus to the system's notification area.
The Electron.Tray API provides the ability to add icons and context menus to the system's notification area (system tray). This allows applications to provide quick access to common functions and maintain a presence in the system even when windows are closed.
Gets a read-only collection of all current tray menu items.
Destroys the tray icon immediately.
Windows: Displays a tray balloon notification.
Parameters:
options- Balloon notification options
Check if the tray icon has been destroyed.
Returns:
Whether the tray icon is destroyed.
Sets the image associated with this tray icon.
Parameters:
image- New image for the tray icon
Sets the image associated with this tray icon when pressed on macOS.
Parameters:
image- Image for pressed state
macOS: Sets the title displayed aside of the tray icon in the status bar.
Parameters:
title- Title text
Sets the hover text for this tray icon.
Parameters:
toolTip- Tooltip text
Shows the tray icon without a context menu.
Parameters:
image- The image to use for the tray icon
Shows the tray icon with a single menu item.
Parameters:
image- The image to use for the tray iconmenuItem- Single menu item for the tray context menu
Shows the tray icon with multiple menu items.
Parameters:
image- The image to use for the tray iconmenuItems- Array of menu items for the tray context menu
Windows: Emitted when the tray balloon is clicked.
Windows: Emitted when the tray balloon is closed because of timeout or user manually closes it.
Windows: Emitted when the tray balloon shows.
Emitted when the tray icon is clicked.
macOS, Windows: Emitted when the tray icon is double clicked.
macOS, Windows: Emitted when the tray icon is right clicked.
// Simple tray iconawaitElectron.Tray.Show("assets/tray-icon.png");// Tray icon with single menu itemawaitElectron.Tray.Show("assets/tray-icon.png",newMenuItem{Label="Show Window",Click=()=>ShowMainWindow()});// Tray with multiple menu itemsvartrayMenuItems=new[]{newMenuItem{Label="Show Window",Click=()=>ShowMainWindow()},newMenuItem{Label="Settings",Click=()=>OpenSettings()},newMenuItem{Type=MenuType.Separator},newMenuItem{Label="Exit",Click=()=>Electron.App.Quit()}};awaitElectron.Tray.Show("assets/tray-icon.png",trayMenuItems);// Update tray tooltip based on statusawaitElectron.Tray.SetToolTip("MyApp - Connected");// Change tray icon based on stateif(isConnected){awaitElectron.Tray.SetImage("assets/connected.png");}else{awaitElectron.Tray.SetImage("assets/disconnected.png");}// Handle tray clicksElectron.Tray.OnClick+=(clickArgs,bounds)=>{if(clickArgs.AltKey||clickArgs.ShiftKey){// Alt+Click or Shift+Click - show context menuElectron.Menu.ContextMenuPopup(Electron.WindowManager.BrowserWindows.First());}else{// Regular click - toggle main windowToggleMainWindow();}};Electron.Tray.OnRightClick+=(clickArgs,bounds)=>{// Show context menu on right clickElectron.Menu.ContextMenuPopup(Electron.WindowManager.BrowserWindows.First());};// Show Windows balloon notificationawaitElectron.Tray.DisplayBalloon(newDisplayBalloonOptions{Title="Background Task Complete",Content="Your file has been processed successfully.",Icon="assets/notification-icon.ico"});// Handle balloon eventsElectron.Tray.OnBalloonClick+=()=>{ShowMainWindow();Electron.WindowManager.BrowserWindows.First().Focus();};// macOS specific tray featuresif(RuntimeInformation.IsOSPlatform(OSPlatform.OSX)){awaitElectron.Tray.SetTitle("MyApp");// Use template image for dark mode supportawaitElectron.Tray.SetImage("assets/tray-template.png");awaitElectron.Tray.SetPressedImage("assets/tray-pressed-template.png");}// Integrate with application lifecycleElectron.App.WindowAllClosed+=()=>{// Keep app running in tray when windows are closedif(RuntimeInformation.IsOSPlatform(OSPlatform.OSX)){Electron.App.Hide();}};// Handle tray double-clickElectron.Tray.OnDoubleClick+=(clickArgs,bounds)=>{ShowMainWindow();Electron.WindowManager.BrowserWindows.First().Focus();};- Electron.Menu - Context menus for tray icons
- Electron.Notification - Desktop notifications
- Electron.App - Application lifecycle events
- Electron.WindowManager - Windows to show/hide from tray
- Electron Tray Documentation - Official Electron tray API
Want to contribute to this documentation? Please fork and create a PR! The Wiki is autogenerated from the /docs content in the repository.