Skip to content
Tauri

tray

Classes

TrayIcon

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

Example

import { TrayIcon } from '@tauri-apps/api/tray';
const tray = await TrayIcon.new({ tooltip: 'awesome tray tooltip' });
tray.set_tooltip('new tooltip');

Extends

Properties

PropertyModifierTypeDescriptionDefined in
idpublicstringThe id associated with this tray icon.Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/tray.ts#L167

Accessors

rid
get rid(): number
Returns

number

Inherited from

Resource.rid

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/core.ts#L242

Methods

close()
close(): Promise<void>

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

Promise<void>

Inherited from

Resource.close

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/core.ts#L254

setIcon()
setIcon(icon): Promise<void>

Sets a new tray icon. If null is provided, it will remove the icon.

Note that you 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"] }
Parameters
ParameterType
icon| null | string | number[] | ArrayBuffer | Uint8Array | Image
Returns

Promise<void>

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/tray.ts#L230

setIconAsTemplate()
setIconAsTemplate(asTemplate): Promise<void>

Sets the current icon as a template. macOS only

Parameters
ParameterType
asTemplateboolean
Returns

Promise<void>

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/tray.ts#L298

setMenu()
setMenu(menu): Promise<void>

Sets a new tray menu.

Platform-specific:

  • Linux: once a menu is set it cannot be removed so null has no effect
Parameters
ParameterType
menunull | Submenu | Menu
Returns

Promise<void>

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/tray.ts#L247

setMenuOnLeftClick()
setMenuOnLeftClick(onLeft): Promise<void>

Disable or enable showing the tray menu on left click. macOS only.

Parameters
ParameterType
onLeftboolean
Returns

Promise<void>

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/tray.ts#L306

setTempDirPath()
setTempDirPath(path): Promise<void>

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.

Parameters
ParameterType
pathnull | string
Returns

Promise<void>

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/tray.ts#L293

setTitle()
setTitle(title): Promise<void>

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
Parameters
ParameterType
titlenull | string
Returns

Promise<void>

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/tray.ts#L278

setTooltip()
setTooltip(tooltip): Promise<void>

Sets the tooltip for this tray icon.

Platform-specific:

  • Linux: Unsupported
Parameters
ParameterType
tooltipnull | string
Returns

Promise<void>

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/tray.ts#L262

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

Show or hide this tray icon.

Parameters
ParameterType
visibleboolean
Returns

Promise<void>

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/tray.ts#L283

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

Gets a tray icon using the provided id.

Parameters
ParameterType
idstring
Returns

Promise<null | TrayIcon>

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/tray.ts#L175

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

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.
Parameters
ParameterType
options?TrayIconOptions
Returns

Promise<TrayIcon>

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/tray.ts#L199

removeById()
static removeById(id): Promise<void>

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.

Parameters
ParameterType
idstring
Returns

Promise<void>

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/tray.ts#L187

Interfaces

TrayIconClickEvent

A click happened on the tray icon.

Properties

PropertyTypeDescriptionDefined in
buttonMouseButtonMouse button that triggered this event.Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/tray.ts#L27
button_stateMouseButtonStateMouse button state when this event was triggered.Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/tray.ts#L29
idstringId of the tray icon which triggered this event.Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/tray.ts#L16
rectobjectPosition and size of the tray icon.Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/tray.ts#L22
rect.positionPhysicalPosition-Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/tray.ts#L23
rect.sizePhysicalSize-Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/tray.ts#L24
xnumberPhysical X Position of the click the triggered this event.Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/tray.ts#L18
ynumberPhysical Y Position of the click the triggered this event.Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/tray.ts#L20

TrayIconEnterEvent

The mouse entered the tray icon region.

Properties

PropertyTypeDescriptionDefined in
idstringId of the tray icon which triggered this event.Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/tray.ts#L35
rectobjectPosition and size of the tray icon.Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/tray.ts#L41
rect.positionPhysicalPosition-Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/tray.ts#L42
rect.sizePhysicalSize-Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/tray.ts#L43
xnumberPhysical X Position of the click the triggered this event.Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/tray.ts#L37
ynumberPhysical Y Position of the click the triggered this event.Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/tray.ts#L39

TrayIconLeaveEvent

The mouse left the tray icon region.

Properties

PropertyTypeDescriptionDefined in
idstringId of the tray icon which triggered this event.Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/tray.ts#L65
rectobjectPosition and size of the tray icon.Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/tray.ts#L71
rect.positionPhysicalPosition-Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/tray.ts#L72
rect.sizePhysicalSize-Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/tray.ts#L73
xnumberPhysical X Position of the click the triggered this event.Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/tray.ts#L67
ynumberPhysical Y Position of the click the triggered this event.Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/tray.ts#L69

TrayIconMoveEvent

The mouse moved over the tray icon region.

Properties

PropertyTypeDescriptionDefined in
idstringId of the tray icon which triggered this event.Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/tray.ts#L50
rectobjectPosition and size of the tray icon.Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/tray.ts#L56
rect.positionPhysicalPosition-Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/tray.ts#L57
rect.sizePhysicalSize-Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/tray.ts#L58
xnumberPhysical X Position of the click the triggered this event.Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/tray.ts#L52
ynumberPhysical Y Position of the click the triggered this event.Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/tray.ts#L54

TrayIconOptions

TrayIcon creation options

Properties

PropertyTypeDescriptionDefined in
action?(event: TrayIconEvent) => voidA handler for an event on the tray icon.Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/tray.ts#L144
icon?| string | number[] | ArrayBuffer | Uint8Array | ImageThe tray icon which could be icon bytes or path to the icon file. Note that you 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"] }Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/tray.ts#L114
iconAsTemplate?booleanUse the icon as a template. macOS only.Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/tray.ts#L140
id?stringThe tray icon id. If undefined, a random one will be assignedSource: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/tray.ts#L101
menu?Submenu | MenuThe tray icon menuSource: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/tray.ts#L103
menuOnLeftClick?booleanWhether to show the tray menu on left click or not, default is true. macOS only.Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/tray.ts#L142
tempDirPath?stringThe 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.Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/tray.ts#L136
title?stringThe 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.Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/tray.ts#L129
tooltip?stringThe tray icon tooltipSource: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/tray.ts#L116

Type Aliases

MouseButton

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

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/tray.ts#L11


MouseButtonState

type MouseButtonState: "Up" | "Down";

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/tray.ts#L10


TrayIconEvent

type TrayIconEvent: object | object | object | object;

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.

Source: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/tray.ts#L85


© 2024 Tauri Contributors. CC-BY / MIT