Skip to content

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 clean-up 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 '@crabnebula/taurify-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.

Accessors

rid
Get Signature
get rid(): number
Returns

number

Inherited from

Resource.rid

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

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

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

###### Parameters
| Parameter | Type |
| ------ | ------ |
| `icon` | \| `null` \| `string` \| `number`[] \| [`ArrayBuffer`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer) \| [`Uint8Array`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array)\<`ArrayBufferLike`\> \| [`Image`](/taurify/api/namespaceimage/#image) |
###### Returns
[`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<`void`\>
<a id="seticonastemplate" name="seticonastemplate"></a>
##### setIconAsTemplate()
```ts
setIconAsTemplate(asTemplate): Promise<void>

Sets the current icon as a template. macOS only

Parameters
ParameterType
asTemplateboolean
Returns

Promise<void>

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>

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

Disable or enable showing the tray menu on left click.

Platform-specific:

  • Linux: Unsupported.
Parameters
ParameterType
onLeftboolean
Returns

Promise<void>

Since

2.2.0

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>

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>

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

Sets the tooltip for this tray icon.

Platform-specific:

  • Linux: Unsupported
Parameters
ParameterType
tooltipnull | string
Returns

Promise<void>

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

Show or hide this tray icon.

Parameters
ParameterType
visibleboolean
Returns

Promise<void>

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

Gets a tray icon using the provided id.

Parameters
ParameterType
idstring
Returns

Promise<null | TrayIcon>

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>

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>

Interfaces

TrayIconOptions

TrayIcon creation options

Properties

PropertyTypeDescriptionDefined in
action?(event: TrayIconEvent) => voidA handler for an event on the tray icon.
icon?| string | number[] | ArrayBuffer | Uint8Array<ArrayBufferLike> | ImageThe tray icon which could be icon bytes or path to the icon file. ```
iconAsTemplate?booleanUse the icon as a template. macOS only.
id?stringThe tray icon id. If undefined, a random one will be assigned
menu?Submenu | MenuThe tray icon menu
showMenuOnLeftClick?booleanWhether to show the tray menu on left click or not, default is true. #### Platform-specific: - Linux: Unsupported. Since 2.2.0
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.
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.
tooltip?stringThe tray icon tooltip

Type Aliases

MouseButton

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

MouseButtonState

type MouseButtonState: "Up" | "Down";

TrayIconClickEvent

type TrayIconClickEvent: object;

Type declaration

NameTypeDescriptionDefined in
buttonMouseButtonMouse button that triggered this event.
buttonStateMouseButtonStateMouse button state when this event was triggered.

TrayIconEvent

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

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

type TrayIconEventBase<T>: object;

Type Parameters

Type Parameter
T extends TrayIconEventType

Type declaration

NameTypeDescriptionDefined in
idstringId of the tray icon which triggered this event.
positionPhysicalPositionPhysical position of the click the triggered this event.
rectobjectPosition and size of the tray icon.
rect.positionPhysicalPosition-
rect.sizePhysicalSize-
typeTThe tray icon event type

TrayIconEventType

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