Skip to content

@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.

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.

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.

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

get rid(): number;

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

number

Resource.rid

asyncDispose: Promise<void>;

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

Promise<void>

Resource.[asyncDispose]

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.

Promise<void>

Uses the core:resources:allow-close permission, which is part of the core:resources:default permission set enabled by default.

Resource.close

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"] }
import { Image } from '@tauri-apps/api/image';
await tray.setIcon(await Image.fromPath('icons/active.png'));
// remove the icon
await tray.setIcon(null);
Parameter Type
icon JsImage | null

Promise<void>

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.

await tray.setIconAsTemplate(true);
Parameter Type
asTemplate boolean

Promise<void>

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.

import { Image } from '@tauri-apps/api/image';
await tray.setIconWithAsTemplate(await Image.fromPath('icons/active.png'), true);
Parameter Type
icon JsImage | null
asTemplate boolean

Promise<void>

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 null has no effect
import { Menu } from '@tauri-apps/api/menu';
await using menu = await Menu.new({ items: [{ id: 'quit', text: 'Quit' }] });
await tray.setMenu(menu);
Parameter Type
menu | Submenu | Menu | null

Promise<void>

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.
await tray.setShowMenuOnLeftClick(false);
Parameter Type
onLeft boolean

Promise<void>

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.

await tray.setShowMenuOnLeftClick(false);
Parameter Type
onLeft boolean

Promise<void>

2.2.0

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.

import { appCacheDir } from '@tauri-apps/api/path';
await tray.setTempDirPath(await appCacheDir());
Parameter Type
path string | null

Promise<void>

setTitle(title: string | null): Promise<void>;

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

Sets the title shown next to this tray icon.

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

Promise<void>

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
await tray.setTooltip('3 unread messages');
Parameter Type
tooltip string | null

Promise<void>

setVisible(visible: boolean): Promise<void>;

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

Show or hide this tray icon.

await tray.setVisible(false);
Parameter Type
visible boolean

Promise<void>

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.

import { TrayIcon } from '@tauri-apps/api/tray';
const tray = await TrayIcon.getById('main-tray');
await tray?.setTooltip('still here');
Parameter Type
id string

Promise<TrayIcon | null>

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 Menu is enough.
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);
}
}
});
Parameter Type
options? TrayIconOptions

Promise<TrayIcon>

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.

import { TrayIcon } from '@tauri-apps/api/tray';
await TrayIcon.removeById('main-tray');
Parameter Type
id string

Promise<void>

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

TrayIcon creation options

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 MouseButton = "Left" | "Right" | "Middle";

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

The mouse button that triggered a tray icon event.


type MouseButtonState = "Up" | "Down";

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

Whether the mouse button was pressed (Down) or released (Up).


type TrayIconClickEvent = {
button: MouseButton;
buttonState: MouseButtonState;
};

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

The extra fields of the Click and DoubleClick TrayIconEvent variants.

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

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.

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 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: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

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