tray
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. | Source: undefined |
get rid(): number
number
Source: undefined
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.
Promise
<void
>
Source: undefined
setIcon(icon): Promise<void>
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 | | null | string | Uint8Array | number [] | ArrayBuffer | Image |
Promise
<void
>
Source: undefined
setIconAsTemplate(asTemplate): Promise<void>
Sets the current icon as a template. macOS only
Parameter | Type |
---|---|
asTemplate | boolean |
Promise
<void
>
Source: undefined
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
Parameter | Type |
---|---|
menu | null | Submenu | Menu |
Promise
<void
>
Source: undefined
setMenuOnLeftClick(onLeft): Promise<void>
Disable or enable showing the tray menu on left click.
Platform-specific:
- Linux: Unsupported.
Parameter | Type |
---|---|
onLeft | boolean |
Promise
<void
>
use TrayIcon.setShowMenuOnLeftClick
instead.
Source: undefined
setShowMenuOnLeftClick(onLeft): Promise<void>
Disable or enable showing the tray menu on left click.
Platform-specific:
- Linux: Unsupported.
Parameter | Type |
---|---|
onLeft | boolean |
Promise
<void
>
2.2.0
Source: undefined
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
.
Parameter | Type |
---|---|
path | null | string |
Promise
<void
>
Source: undefined
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
Parameter | Type |
---|---|
title | null | string |
Promise
<void
>
Source: undefined
setTooltip(tooltip): Promise<void>
Sets the tooltip for this tray icon.
Platform-specific:
- Linux: Unsupported
Parameter | Type |
---|---|
tooltip | null | string |
Promise
<void
>
Source: undefined
setVisible(visible): Promise<void>
Show or hide this tray icon.
Parameter | Type |
---|---|
visible | boolean |
Promise
<void
>
Source: undefined
static getById(id): Promise<null | TrayIcon>
Gets a tray icon using the provided id.
Parameter | Type |
---|---|
id | string |
Source: undefined
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.
Parameter | Type |
---|---|
options ? | TrayIconOptions |
Source: undefined
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.
Parameter | Type |
---|---|
id | string |
Promise
<void
>
Source: undefined
TrayIcon
creation options
Property | Type | Description | Defined in |
---|---|---|---|
action? | (event : TrayIconEvent ) => void | A handler for an event on the tray icon. | Source: undefined |
icon? | | string | Uint8Array | number [] | ArrayBuffer | Image | 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"] } | Source: undefined |
iconAsTemplate? | boolean | Use the icon as a template. macOS only. | Source: undefined |
id? | string | The tray icon id. If undefined, a random one will be assigned | Source: undefined |
menu? | Submenu | Menu | The tray icon menu | Source: undefined |
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. | Source: undefined |
showMenuOnLeftClick? | boolean | Whether to show the tray menu on left click or not, default is true . Platform-specific: - Linux: Unsupported. Since 2.2.0 | Source: undefined |
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 . | Source: undefined |
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. | Source: undefined |
tooltip? | string | The tray icon tooltip | Source: undefined |
type MouseButton: "Left" | "Right" | "Middle";
Source: undefined
type MouseButtonState: "Up" | "Down";
Source: undefined
type TrayIconClickEvent: object;
Name | Type | Description | Defined in |
---|---|---|---|
button | MouseButton | Mouse button that triggered this event. | Source: undefined |
buttonState | MouseButtonState | Mouse button state when this event was triggered. | Source: undefined |
Source: undefined
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.
Source: undefined
type TrayIconEventBase<T>: object;
Type Parameter |
---|
T extends TrayIconEventType |
Name | Type | Description | Defined in |
---|---|---|---|
id | string | Id of the tray icon which triggered this event. | Source: undefined |
position | PhysicalPosition | Physical position of the click the triggered this event. | Source: undefined |
rect | object | Position and size of the tray icon. | Source: undefined |
rect.position | PhysicalPosition | - | Source: undefined |
rect.size | PhysicalSize | - | Source: undefined |
type | T | The tray icon event type | Source: undefined |
Source: undefined
type TrayIconEventType: | "Click" | "DoubleClick" | "Enter" | "Move" | "Leave";
Source: undefined
Tauri v2.8 中文网 - 粤ICP备13048890号
Nodejs.cn 旗下网站