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
Extends
Constructors
new TrayIcon()
Parameters
Parameter | Type |
---|---|
rid | number |
id | string |
Returns
Overrides
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/tray.ts#L169
Properties
Property | Modifier | Type | Description | Inherited from |
---|---|---|---|---|
#rid | private | number | - | Resource .#rid |
id | public | string | The id associated with this tray icon. | - |
Accessors
rid
Returns
number
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/core.ts#L222
Methods
close()
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
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/core.ts#L234
setIcon()
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:
Parameters
Parameter | Type |
---|---|
icon | | null | string | number [] | ArrayBuffer | Uint8Array | Image |
Returns
Promise
<void
>
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/tray.ts#L230
setIconAsTemplate()
Sets the current icon as a template. macOS only
Parameters
Parameter | Type |
---|---|
asTemplate | boolean |
Returns
Promise
<void
>
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/tray.ts#L298
setMenu()
Sets a new tray menu.
Platform-specific:
- Linux: once a menu is set it cannot be removed so
null
has no effect
Parameters
Parameter | Type |
---|---|
menu | null | Submenu | Menu |
Returns
Promise
<void
>
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/tray.ts#L247
setMenuOnLeftClick()
Disable or enable showing the tray menu on left click. macOS only.
Parameters
Parameter | Type |
---|---|
onLeft | boolean |
Returns
Promise
<void
>
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/tray.ts#L306
setTempDirPath()
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
Parameter | Type |
---|---|
path | null | string |
Returns
Promise
<void
>
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/tray.ts#L293
setTitle()
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
Parameter | Type |
---|---|
title | null | string |
Returns
Promise
<void
>
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/tray.ts#L278
setTooltip()
Sets the tooltip for this tray icon.
Platform-specific:
- Linux: Unsupported
Parameters
Parameter | Type |
---|---|
tooltip | null | string |
Returns
Promise
<void
>
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/tray.ts#L262
setVisible()
Show or hide this tray icon.
Parameters
Parameter | Type |
---|---|
visible | boolean |
Returns
Promise
<void
>
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/tray.ts#L283
getById()
Gets a tray icon using the provided id.
Parameters
Parameter | Type |
---|---|
id | string |
Returns
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/tray.ts#L175
new()
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
Parameter | Type |
---|---|
options ? | TrayIconOptions |
Returns
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/tray.ts#L199
removeById()
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
Parameter | Type |
---|---|
id | string |
Returns
Promise
<void
>
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/tray.ts#L187
Interfaces
TrayIconClickEvent
A click happened on the tray icon.
Properties
Property | Type | Description |
---|---|---|
button | MouseButton | Mouse button that triggered this event. |
button_state | MouseButtonState | Mouse button state when this event was triggered. |
id | string | Id of the tray icon which triggered this event. |
rect | object | Position and size of the tray icon. |
rect.position | PhysicalPosition | - |
rect.size | PhysicalSize | - |
x | number | Physical X Position of the click the triggered this event. |
y | number | Physical Y Position of the click the triggered this event. |
TrayIconEnterEvent
The mouse entered the tray icon region.
Properties
Property | Type | Description |
---|---|---|
id | string | Id of the tray icon which triggered this event. |
rect | object | Position and size of the tray icon. |
rect.position | PhysicalPosition | - |
rect.size | PhysicalSize | - |
x | number | Physical X Position of the click the triggered this event. |
y | number | Physical Y Position of the click the triggered this event. |
TrayIconLeaveEvent
The mouse left the tray icon region.
Properties
Property | Type | Description |
---|---|---|
id | string | Id of the tray icon which triggered this event. |
rect | object | Position and size of the tray icon. |
rect.position | PhysicalPosition | - |
rect.size | PhysicalSize | - |
x | number | Physical X Position of the click the triggered this event. |
y | number | Physical Y Position of the click the triggered this event. |
TrayIconMoveEvent
The mouse moved over the tray icon region.
Properties
Property | Type | Description |
---|---|---|
id | string | Id of the tray icon which triggered this event. |
rect | object | Position and size of the tray icon. |
rect.position | PhysicalPosition | - |
rect.size | PhysicalSize | - |
x | number | Physical X Position of the click the triggered this event. |
y | number | Physical Y Position of the click the triggered this event. |
TrayIconOptions
TrayIcon
creation options
Properties
Property | Type | Description |
---|---|---|
action? | (event : TrayIconEvent ) => void | A handler for an event on the tray icon. |
icon? | | string | number [] | ArrayBuffer | Uint8Array | Image | The tray icon which could be icon bytes or path to the icon file. Note that you need the [dependencies] |
iconAsTemplate? | boolean | Use the icon as a template. macOS only. |
id? | string | The tray icon id. If undefined, a random one will be assigned |
menu? | Submenu | Menu | The tray icon menu |
menuOnLeftClick? | boolean | Whether to show the tray menu on left click or not, default is true . macOS only. |
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 |
title? | string | The tray title Platform-specific
|
tooltip? | string | The tray icon tooltip |
Type Aliases
MouseButton
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/tray.ts#L11
MouseButtonState
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/tray.ts#L10
TrayIconEvent
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/tooling/api/src/tray.ts#L85
© 2024 Tauri Contributors. CC-BY / MIT