Skip to content

tray

Defined in: packages/api/src/tray.ts:158

Tray icon class and associated methods. This type constructor is private, instead, you should use the static method TrayIcon.new.

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 this object early, you need to call TrayIcon.close.

import { TrayIcon } from '@tauri-apps/api/tray';
const tray = await TrayIcon.new({ tooltip: 'awesome tray tooltip' });
tray.set_tooltip('new tooltip');
Property Modifier Type Description Defined in
id public string The id associated with this tray icon. packages/api/src/tray.ts:160

get rid(): number;

Defined in: packages/api/src/core.ts:318

number

Resource.rid

close(): Promise<void>;

Defined in: packages/api/src/core.ts:330

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.

Promise<void>

Resource.close

setIcon(icon): Promise<void>;

Defined in: packages/api/src/tray.ts:224

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"] }
Parameter Type
icon | string | Image | Uint8Array | ArrayBuffer | number[] | null

Promise<void>

setIconAsTemplate(asTemplate): Promise<void>;

Defined in: packages/api/src/tray.ts:292

Sets the current icon as a template. macOS only

Parameter Type
asTemplate boolean

Promise<void>

setIconWithAsTemplate(icon, asTemplate): Promise<void>;

Defined in: packages/api/src/tray.ts:309

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"] }
Parameter Type
icon | string | Image | Uint8Array | ArrayBuffer | number[] | null
asTemplate boolean

Promise<void>

setMenu(menu): Promise<void>;

Defined in: packages/api/src/tray.ts:241

Sets a new tray menu.

Platform-specific

  • Linux: once a menu is set it cannot be removed so null has no effect
Parameter Type
menu | Submenu | Menu | null

Promise<void>

setMenuOnLeftClick(onLeft): Promise<void>;

Defined in: packages/api/src/tray.ts:333

Disable or enable showing the tray menu on left click.

Platform-specific

  • Linux: Unsupported.
Parameter Type
onLeft boolean

Promise<void>

setShowMenuOnLeftClick(onLeft): Promise<void>;

Defined in: packages/api/src/tray.ts:349

Disable or enable showing the tray menu on left click.

Platform-specific

  • Linux: Unsupported.
Parameter Type
onLeft boolean

Promise<void>

2.2.0

setTempDirPath(path): Promise<void>;

Defined in: packages/api/src/tray.ts:287

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.

Parameter Type
path string | null

Promise<void>

setTitle(title): Promise<void>;

Defined in: packages/api/src/tray.ts:272

Sets the tooltip for this tray icon.

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
Parameter Type
title string | null

Promise<void>

setTooltip(tooltip): Promise<void>;

Defined in: packages/api/src/tray.ts:256

Sets the tooltip for this tray icon.

Platform-specific

  • Linux: Unsupported
Parameter Type
tooltip string | null

Promise<void>

setVisible(visible): Promise<void>;

Defined in: packages/api/src/tray.ts:277

Show or hide this tray icon.

Parameter Type
visible boolean

Promise<void>

static getById(id): Promise<TrayIcon | null>;

Defined in: packages/api/src/tray.ts:168

Gets a tray icon using the provided id.

Parameter Type
id string

Promise<TrayIcon | null>

static new(options?): Promise<TrayIcon>;

Defined in: packages/api/src/tray.ts:192

Creates a new TrayIcon

Platform-specific

  • Linux: Sometimes the icon won’t be visible unless a menu is set. Setting an empty Menu is enough.
Parameter Type
options? TrayIconOptions

Promise<TrayIcon>

static removeById(id): Promise<void>;

Defined in: packages/api/src/tray.ts:180

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.

Parameter Type
id string

Promise<void>

Defined in: packages/api/src/tray.ts:74

TrayIcon creation options

Property Type Description Defined in
action? (event) => void A handler for an event on the tray icon. packages/api/src/tray.ts:137
icon? | string | Image | Uint8Array | ArrayBuffer | number[] 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:89
iconAsTemplate? boolean Use the icon as a template. macOS only. packages/api/src/tray.ts:115
id? string The tray icon id. If undefined, a random one will be assigned packages/api/src/tray.ts:76
menu? | Submenu | Menu The tray icon menu packages/api/src/tray.ts:78
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:125
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:135
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:111
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:104
tooltip? string The tray icon tooltip packages/api/src/tray.ts:91

type MouseButton = "Left" | "Right" | "Middle";

Defined in: packages/api/src/tray.ts:11


type MouseButtonState = "Up" | "Down";

Defined in: packages/api/src/tray.ts:10


type TrayIconClickEvent = object;

Defined in: packages/api/src/tray.ts:33

Property Type Description Defined in
button MouseButton Mouse button that triggered this event. packages/api/src/tray.ts:35
buttonState MouseButtonState Mouse button state when this event was triggered. packages/api/src/tray.ts:37

type TrayIconEvent =
| TrayIconEventBase<"Click"> & TrayIconClickEvent
| TrayIconEventBase<"DoubleClick"> & Omit<TrayIconClickEvent, "buttonState">
| TrayIconEventBase<"Enter">
| TrayIconEventBase<"Move">
| TrayIconEventBase<"Leave">;

Defined in: packages/api/src/tray.ts:48

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.

type TrayIconEventBase<T> = object;

Defined in: packages/api/src/tray.ts:19

Type Parameter
T extends TrayIconEventType
Property Type Description Defined in
id string Id of the tray icon which triggered this event. packages/api/src/tray.ts:23
position PhysicalPosition Physical position of the click the triggered this event. packages/api/src/tray.ts:25
rect object Position and size of the tray icon. packages/api/src/tray.ts:27
rect.position PhysicalPosition - packages/api/src/tray.ts:28
rect.size PhysicalSize - packages/api/src/tray.ts:29
type T The tray icon event type packages/api/src/tray.ts:21

type TrayIconEventType = "Click" | "DoubleClick" | "Enter" | "Move" | "Leave";

Defined in: packages/api/src/tray.ts:12


© 2026 Tauri Contributors. CC-BY / MIT