@tauri-apps/api/tray
Create and manipulate system tray (menu bar / notification area) icons.
Tray icons are created with TrayIcon.new and live on the Rust side,
the frontend only holds a handle to them.
This package is also accessible with window.__TAURI__.tray when app.withGlobalTauri in tauri.conf.json is set to true.
Remarks
Section titled “Remarks”All commands used by this module are part of the core:tray:default
permission set, which is enabled by default, so no extra capability
configuration is needed. Loading an icon from a path or from bytes additionally
requires the image-png / image-ico Cargo features of the tauri crate.
Classes
Section titled “Classes”TrayIcon
Section titled “TrayIcon”Defined in: packages/api/src/tray.ts:182
Tray icon class and associated methods. This type constructor is private,
instead, you should use the static method TrayIcon.new.
Warning
Unlike Rust, JavaScript does not have any way to run cleanup code
when an object is being removed by garbage collection, but this tray icon
will be cleaned up when the tauri app exists, however if you want to cleanup
and remove the tray early, you need to call TrayIcon.close.
Example
Section titled “Example”import { TrayIcon } from '@tauri-apps/api/tray';const tray = await TrayIcon.new({ tooltip: 'awesome tray tooltip' });await tray.setTooltip('new tooltip');Extends
Section titled “Extends”Properties
Section titled “Properties”| Property | Modifier | Type | Description | Defined in |
|---|---|---|---|---|
id |
public |
string |
The id associated with this tray icon. | packages/api/src/tray.ts:184 |
Accessors
Section titled “Accessors”Get Signature
Section titled “Get Signature”get rid(): number;Defined in: packages/api/src/core.ts:560
Returns
Section titled “Returns”number
Inherited from
Section titled “Inherited from”Methods
Section titled “Methods”[asyncDispose]()
Section titled “[asyncDispose]()”asyncDispose: Promise<void>;Defined in: packages/api/src/core.ts:581
Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”close()
Section titled “close()”close(): Promise<void>;Defined in: packages/api/src/core.ts:575
Destroys and cleans up this resource from memory. You should not call any method on this object anymore and should drop any reference to it.
Returns
Section titled “Returns”Remarks
Section titled “Remarks”Uses the core:resources:allow-close permission, which is part of
the core:resources:default permission set enabled by default.
Inherited from
Section titled “Inherited from”setIcon()
Section titled “setIcon()”setIcon(icon: JsImage | null): Promise<void>;Defined in: packages/api/src/tray.ts:299
Sets a new tray icon. If null is provided, it will remove the icon.
Note that you may need the image-ico or image-png Cargo features to use this API.
To enable it, change your Cargo.toml file:
[dependencies]tauri = { version = "...", features = ["...", "image-png"] }Example
Section titled “Example”import { Image } from '@tauri-apps/api/image';await tray.setIcon(await Image.fromPath('icons/active.png'));// remove the iconawait tray.setIcon(null);Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
icon |
JsImage | null |
Returns
Section titled “Returns”setIconAsTemplate()
Section titled “setIconAsTemplate()”setIconAsTemplate(asTemplate: boolean): Promise<void>;Defined in: packages/api/src/tray.ts:405
Sets the current icon as a template. macOS only
A template image is recolored by the system so it matches the menu bar appearance in light and dark mode.
Example
Section titled “Example”await tray.setIconAsTemplate(true);Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
asTemplate |
boolean |
Returns
Section titled “Returns”setIconWithAsTemplate()
Section titled “setIconWithAsTemplate()”setIconWithAsTemplate(icon: JsImage | null, asTemplate: boolean): Promise<void>;Defined in: packages/api/src/tray.ts:432
Sets a new tray icon and template status atomically. macOS only.
Note that you may need the image-ico or image-png Cargo features to use this API.
To enable it, change your Cargo.toml file:
[dependencies]tauri = { version = "...", features = ["...", "image-png"] }Prefer this over calling TrayIcon.setIcon and
TrayIcon.setIconAsTemplate in sequence, which can briefly show the
new icon with the previous template setting.
Example
Section titled “Example”import { Image } from '@tauri-apps/api/image';await tray.setIconWithAsTemplate(await Image.fromPath('icons/active.png'), true);Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
icon |
JsImage | null |
asTemplate |
boolean |
Returns
Section titled “Returns”setMenu()
Section titled “setMenu()”setMenu(menu: Submenu | Menu | null): Promise<void>;Defined in: packages/api/src/tray.ts:321
Sets a new tray menu.
Platform-specific
- Linux: once a menu is set it cannot be removed so
nullhas no effect
Example
Section titled “Example”import { Menu } from '@tauri-apps/api/menu';await using menu = await Menu.new({ items: [{ id: 'quit', text: 'Quit' }] });await tray.setMenu(menu);Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
menu |
| Submenu | Menu | null |
Returns
Section titled “Returns”setMenuOnLeftClick()
Section titled “setMenuOnLeftClick()”setMenuOnLeftClick(onLeft: boolean): Promise<void>;Defined in: packages/api/src/tray.ts:461
Disable or enable showing the tray menu on left click.
Platform-specific
- Linux: Unsupported.
Example
Section titled “Example”await tray.setShowMenuOnLeftClick(false);Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
onLeft |
boolean |
Returns
Section titled “Returns”setShowMenuOnLeftClick()
Section titled “setShowMenuOnLeftClick()”setShowMenuOnLeftClick(onLeft: boolean): Promise<void>;Defined in: packages/api/src/tray.ts:486
Disable or enable showing the tray menu on left click.
Platform-specific
- Linux: Unsupported.
Disable it to handle left clicks yourself through the
TrayIconOptions.action handler while still showing the menu on
right click.
Example
Section titled “Example”await tray.setShowMenuOnLeftClick(false);Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
onLeft |
boolean |
Returns
Section titled “Returns”2.2.0
setTempDirPath()
Section titled “setTempDirPath()”setTempDirPath(path: string | null): Promise<void>;Defined in: packages/api/src/tray.ts:390
Sets the tray icon temp dir path. Linux only.
On Linux, we need to write the icon to the disk and usually it will
be $XDG_RUNTIME_DIR/tray-icon or $TEMP/tray-icon.
Example
Section titled “Example”import { appCacheDir } from '@tauri-apps/api/path';await tray.setTempDirPath(await appCacheDir());Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
path |
string | null |
Returns
Section titled “Returns”setTitle()
Section titled “setTitle()”setTitle(title: string | null): Promise<void>;Defined in: packages/api/src/tray.ts:362
Sets the title shown next to this tray icon.
Example
Section titled “Example”await tray.setTitle('42');Platform-specific
- Linux: The title will not be shown unless there is an icon as well. The title is useful for numerical and other frequently updated information. In general, it shouldn’t be shown unless a user requests it as it can take up a significant amount of space on the user’s panel. This may not be shown in all visualizations.
- Windows: Unsupported
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
title |
string | null |
Returns
Section titled “Returns”setTooltip()
Section titled “setTooltip()”setTooltip(tooltip: string | null): Promise<void>;Defined in: packages/api/src/tray.ts:341
Sets the tooltip for this tray icon, shown when the cursor hovers it.
Platform-specific
- Linux: Unsupported
Example
Section titled “Example”await tray.setTooltip('3 unread messages');Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
tooltip |
string | null |
Returns
Section titled “Returns”setVisible()
Section titled “setVisible()”setVisible(visible: boolean): Promise<void>;Defined in: packages/api/src/tray.ts:374
Show or hide this tray icon.
Example
Section titled “Example”await tray.setVisible(false);Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
visible |
boolean |
Returns
Section titled “Returns”getById()
Section titled “getById()”static getById(id: string): Promise<TrayIcon | null>;Defined in: packages/api/src/tray.ts:206
Gets a tray icon using the provided id.
Use it to get a handle from the frontend to a tray icon that was created on the Rust side with an explicit id.
Example
Section titled “Example”import { TrayIcon } from '@tauri-apps/api/tray';const tray = await TrayIcon.getById('main-tray');await tray?.setTooltip('still here');Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
id |
string |
Returns
Section titled “Returns”The tray icon, or null if no tray icon with that id exists.
static new(options?: TrayIconOptions): Promise<TrayIcon>;Defined in: packages/api/src/tray.ts:259
Creates a new TrayIcon
Platform-specific
- Linux: Sometimes the icon won’t be visible unless a menu is set.
Setting an empty
Menuis enough.
Example
Section titled “Example”import { TrayIcon } from '@tauri-apps/api/tray';import { Menu } from '@tauri-apps/api/menu';import { defaultWindowIcon } from '@tauri-apps/api/app';
await using menu = await Menu.new({ items: [{ id: 'quit', text: 'Quit', action: () => console.log('quit') }]});
const tray = await TrayIcon.new({ id: 'main-tray', icon: (await defaultWindowIcon()) ?? undefined, menu, tooltip: 'My app', action: (event) => { if (event.type === 'Click') { console.log('tray clicked with', event.button); } }});Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
options? |
TrayIconOptions |
Returns
Section titled “Returns”removeById()
Section titled “removeById()”static removeById(id: string): Promise<void>;Defined in: packages/api/src/tray.ts:224
Removes a tray icon using the provided id from tauri’s internal state.
Note that this may cause the tray icon to disappear if it wasn’t cloned somewhere else or referenced by JS.
Example
Section titled “Example”import { TrayIcon } from '@tauri-apps/api/tray';await TrayIcon.removeById('main-tray');Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
id |
string |
Returns
Section titled “Returns”Interfaces
Section titled “Interfaces”TrayIconOptions
Section titled “TrayIconOptions”Defined in: packages/api/src/tray.ts:98
TrayIcon creation options
Properties
Section titled “Properties”| Property | Type | Description | Defined in |
|---|---|---|---|
action? |
(event: TrayIconEvent) => void |
A handler for an event on the tray icon. | packages/api/src/tray.ts:161 |
icon? |
JsImage |
The tray icon which could be icon bytes or path to the icon file. Note that you may need the image-ico or image-png Cargo features to use this API. To enable it, change your Cargo.toml file: [dependencies] tauri = { version = "...", features = ["...", "image-png"] } |
packages/api/src/tray.ts:113 |
iconAsTemplate? |
boolean |
Use the icon as a template. macOS only. | packages/api/src/tray.ts:139 |
id? |
string |
The tray icon id. If undefined, a random one will be assigned | packages/api/src/tray.ts:100 |
menu? |
| Submenu | Menu |
The tray icon menu | packages/api/src/tray.ts:102 |
menuOnLeftClick? |
boolean |
Whether to show the tray menu on left click or not, default is true. Platform-specific - Linux: Unsupported. Deprecated use TrayIconOptions.showMenuOnLeftClick instead. |
packages/api/src/tray.ts:149 |
showMenuOnLeftClick? |
boolean |
Whether to show the tray menu on left click or not, default is true. Platform-specific - Linux: Unsupported. Since 2.2.0 |
packages/api/src/tray.ts:159 |
tempDirPath? |
string |
The tray icon temp dir path. Linux only. On Linux, we need to write the icon to the disk and usually it will be $XDG_RUNTIME_DIR/tray-icon or $TEMP/tray-icon. |
packages/api/src/tray.ts:135 |
title? |
string |
The tray title Platform-specific - Linux: The title will not be shown unless there is an icon as well. The title is useful for numerical and other frequently updated information. In general, it shouldn’t be shown unless a user requests it as it can take up a significant amount of space on the user’s panel. This may not be shown in all visualizations. - Windows: Unsupported. | packages/api/src/tray.ts:128 |
tooltip? |
string |
The tray icon tooltip | packages/api/src/tray.ts:115 |
Type Aliases
Section titled “Type Aliases”MouseButton
Section titled “MouseButton”type MouseButton = "Left" | "Right" | "Middle";Defined in: packages/api/src/tray.ts:30
The mouse button that triggered a tray icon event.
MouseButtonState
Section titled “MouseButtonState”type MouseButtonState = "Up" | "Down";Defined in: packages/api/src/tray.ts:27
Whether the mouse button was pressed (Down) or released (Up).
TrayIconClickEvent
Section titled “TrayIconClickEvent”type TrayIconClickEvent = { button: MouseButton; buttonState: MouseButtonState;};Defined in: packages/api/src/tray.ts:64
The extra fields of the Click and DoubleClick TrayIconEvent variants.
Properties
Section titled “Properties”| Property | Type | Description | Defined in |
|---|---|---|---|
button |
MouseButton |
Mouse button that triggered this event. | packages/api/src/tray.ts:66 |
buttonState |
MouseButtonState |
Mouse button state when this event was triggered. | packages/api/src/tray.ts:68 |
TrayIconEvent
Section titled “TrayIconEvent”type TrayIconEvent = | TrayIconEventBase<"Click"> & TrayIconClickEvent | TrayIconEventBase<"DoubleClick"> & Omit<TrayIconClickEvent, "buttonState"> | TrayIconEventBase<"Enter"> | TrayIconEventBase<"Move">| TrayIconEventBase<"Leave">;Defined in: packages/api/src/tray.ts:79
Describes a tray icon event.
Platform-specific
- Linux: Unsupported. The event is not emitted even though the icon is shown, the icon will still show a context menu on right click.
TrayIconEventBase
Section titled “TrayIconEventBase”type TrayIconEventBase<T extends TrayIconEventType> = { id: string; position: PhysicalPosition; rect: { position: PhysicalPosition; size: PhysicalSize; }; type: T;};Defined in: packages/api/src/tray.ts:49
The fields shared by every TrayIconEvent.
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
T extends TrayIconEventType |
Properties
Section titled “Properties”| Property | Type | Description | Defined in |
|---|---|---|---|
id |
string |
Id of the tray icon which triggered this event. | packages/api/src/tray.ts:53 |
position |
PhysicalPosition |
Physical position of the click the triggered this event. | packages/api/src/tray.ts:55 |
rect |
{ position: PhysicalPosition; size: PhysicalSize; } |
Position and size of the tray icon. | packages/api/src/tray.ts:57 |
rect.position |
PhysicalPosition |
- | packages/api/src/tray.ts:58 |
rect.size |
PhysicalSize |
- | packages/api/src/tray.ts:59 |
type |
T |
The tray icon event type | packages/api/src/tray.ts:51 |
TrayIconEventType
Section titled “TrayIconEventType”type TrayIconEventType = "Click" | "DoubleClick" | "Enter" | "Move" | "Leave";Defined in: packages/api/src/tray.ts:41
The kind of a TrayIconEvent.
Click: a mouse button was pressed or released over the icon.DoubleClick: the icon was double clicked.Enter: the cursor entered the icon area.Move: the cursor moved inside the icon area.Leave: the cursor left the icon area.
© 2026 Tauri Contributors. CC-BY / MIT