event
The event system allows you to emit events to the backend and listen to events from it.
This package is also accessible with window.__TAURI__.event
when app.withGlobalTauri
in tauri.conf.json
is set to true
.
Enumerations
TauriEvent
Since
1.1.0
Enumeration Members
DRAG
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/event.ts#L60
DROP
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/event.ts#L61
DROP_CANCELLED
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/event.ts#L63
DROP_OVER
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/event.ts#L62
WEBVIEW_CREATED
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/event.ts#L59
WINDOW_BLUR
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/event.ts#L55
WINDOW_CLOSE_REQUESTED
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/event.ts#L52
WINDOW_CREATED
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/event.ts#L58
WINDOW_DESTROYED
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/event.ts#L53
WINDOW_FOCUS
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/event.ts#L54
WINDOW_MOVED
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/event.ts#L51
WINDOW_RESIZED
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/event.ts#L50
WINDOW_SCALE_FACTOR_CHANGED
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/event.ts#L56
WINDOW_THEME_CHANGED
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/event.ts#L57
Interfaces
Event<T>
Type parameters
Type parameter |
---|
T |
Properties
Property | Type | Description |
---|---|---|
event | EventName | Event name |
id | number | Event identifier used to unlisten |
payload | T | Event payload |
Options
Properties
Property | Type | Description |
---|---|---|
target? | string | EventTarget | The event target to listen to, defaults to If a string is provided, EventTarget.AnyLabel is used. |
Type Aliases
EventCallback()<T>
Type parameters
Type parameter |
---|
T |
Parameters
Parameter | Type |
---|---|
event | Event <T > |
Returns
void
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/event.ts#L31
EventName
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/event.ts#L35
EventTarget
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/event.ts#L14
UnlistenFn()
Returns
void
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/event.ts#L33
Functions
emit()
Emits an event to all targets.
Parameters
Parameter | Type | Description |
---|---|---|
event | string | Event name. Must include only alphanumeric characters, - , / , : and _ . |
payload ? | unknown | Event payload. |
Returns
Promise
<void
>
Example
Since
1.0.0
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/event.ts#L176
emitTo()
Emits an event to all targets matching the given target.
Parameters
Parameter | Type | Description |
---|---|---|
target | string | EventTarget | Label of the target Window/Webview/WebviewWindow or raw EventTarget object. |
event | string | Event name. Must include only alphanumeric characters, - , / , : and _ . |
payload ? | unknown | Event payload. |
Returns
Promise
<void
>
Example
Since
2.0.0
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/event.ts#L198
listen()
Listen to an emitted event to any target.
Type parameters
Type parameter |
---|
T |
Parameters
Parameter | Type | Description |
---|---|---|
event | EventName | Event name. Must include only alphanumeric characters, - , / , : and _ . |
handler | EventCallback <T > | Event handler callback. |
options ? | Options | Event listening options. |
Returns
A promise resolving to a function to unlisten to the event. Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.
Example
Since
1.0.0
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/event.ts#L103
once()
Listens once to an emitted event to any target.
Type parameters
Type parameter |
---|
T |
Parameters
Parameter | Type | Description |
---|---|---|
event | EventName | Event name. Must include only alphanumeric characters, - , / , : and _ . |
handler | EventCallback <T > | Event handler callback. |
options ? | Options | Event listening options. |
Returns
A promise resolving to a function to unlisten to the event. Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.
Example
Since
1.0.0
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/event.ts#L147
© 2024 Tauri Contributors. CC-BY / MIT