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.
1.1.0
DRAG_DROP: "tauri://drag-drop";Source: undefined
DRAG_ENTER: "tauri://drag-enter";Source: undefined
DRAG_LEAVE: "tauri://drag-leave";Source: undefined
DRAG_OVER: "tauri://drag-over";Source: undefined
WEBVIEW_CREATED: "tauri://webview-created";Source: undefined
WINDOW_BLUR: "tauri://blur";Source: undefined
WINDOW_CLOSE_REQUESTED: "tauri://close-requested";Source: undefined
WINDOW_CREATED: "tauri://window-created";Source: undefined
WINDOW_DESTROYED: "tauri://destroyed";Source: undefined
WINDOW_FOCUS: "tauri://focus";Source: undefined
WINDOW_MOVED: "tauri://move";Source: undefined
WINDOW_RESIZED: "tauri://resize";Source: undefined
WINDOW_SCALE_FACTOR_CHANGED: "tauri://scale-change";Source: undefined
WINDOW_THEME_CHANGED: "tauri://theme-changed";Source: undefined
| Type Parameter |
|---|
T |
| Property | Type | Description | Defined in |
|---|---|---|---|
event | EventName | Event name | Source: undefined |
id | number | Event identifier used to unlisten | Source: undefined |
payload | T | Event payload | Source: undefined |
| Property | Type | Description | Defined in |
|---|---|---|---|
target? | string | EventTarget | The event target to listen to, defaults to { kind: 'Any' }, see EventTarget. If a string is provided, EventTarget.AnyLabel is used. | Source: undefined |
type EventCallback<T>: (event) => void;| Type Parameter |
|---|
T |
| Parameter | Type |
|---|---|
event | Event<T> |
void
Source: undefined
type EventName: `${TauriEvent}` | string & Record<never, never>;Source: undefined
type EventTarget: | object | object | object | object | object | object;Source: undefined
type UnlistenFn: () => void;void
Source: undefined
function emit<T>(event, payload?): Promise<void>Emits an event to all targets.
| Type Parameter |
|---|
T |
| Parameter | Type | Description |
|---|---|---|
event | string | Event name. Must include only alphanumeric characters, -, /, : and _. |
payload? | T | Event payload. |
Promise<void>
import { emit } from '@tauri-apps/api/event';await emit('frontend-loaded', { loggedIn: true, token: 'authToken' });1.0.0
Source: undefined
function emitTo<T>( target, event,payload?): Promise<void>Emits an event to all targets matching the given target.
| Type Parameter |
|---|
T |
| 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? | T | Event payload. |
Promise<void>
import { emitTo } from '@tauri-apps/api/event';await emitTo('main', 'frontend-loaded', { loggedIn: true, token: 'authToken' });2.0.0
Source: undefined
function listen<T>( event, handler,options?): Promise<UnlistenFn>Listen to an emitted event to any target.
| Type Parameter |
|---|
T |
| Parameter | Type | Description |
|---|---|---|
event | EventName | Event name. Must include only alphanumeric characters, -, /, : and _. |
handler | EventCallback<T> | Event handler callback. |
options? | Options | Event listening options. |
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.
import { listen } from '@tauri-apps/api/event';const unlisten = await listen<string>('error', (event) => { console.log(`Got error, payload: ${event.payload}`);});
// you need to call unlisten if your handler goes out of scope e.g. the component is unmountedunlisten();1.0.0
Source: undefined
function once<T>( event, handler,options?): Promise<UnlistenFn>Listens once to an emitted event to any target.
| Type Parameter |
|---|
T |
| Parameter | Type | Description |
|---|---|---|
event | EventName | Event name. Must include only alphanumeric characters, -, /, : and _. |
handler | EventCallback<T> | Event handler callback. |
options? | Options | Event listening options. |
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.
import { once } from '@tauri-apps/api/event';interface LoadedPayload { loggedIn: boolean, token: string}const unlisten = await once<LoadedPayload>('loaded', (event) => { console.log(`App is loaded, loggedIn: ${event.payload.loggedIn}, token: ${event.payload.token}`);});
// you need to call unlisten if your handler goes out of scope e.g. the component is unmountedunlisten();1.0.0
Source: undefined
Tauri v2.9 中文网 - 粤ICP备13048890号
Nodejs.cn 旗下网站