Skip to content
Tauri
Releases

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 build.withGlobalTauri in tauri.conf.json is set to true.

Enumerations

TauriEvent

Since

1.1.0

Enumeration Members

CHECK_UPDATE
CHECK_UPDATE: 'tauri://update';

Source: event.ts:34


DOWNLOAD_PROGRESS
DOWNLOAD_PROGRESS: 'tauri://update-download-progress';

Source: event.ts:38


INSTALL_UPDATE
INSTALL_UPDATE: 'tauri://update-install';

Source: event.ts:36


MENU: 'tauri://menu';

Source: event.ts:33


STATUS_UPDATE
STATUS_UPDATE: 'tauri://update-status';

Source: event.ts:37


UPDATE_AVAILABLE
UPDATE_AVAILABLE: 'tauri://update-available';

Source: event.ts:35


WINDOW_BLUR
WINDOW_BLUR: 'tauri://blur';

Source: event.ts:27


WINDOW_CLOSE_REQUESTED
WINDOW_CLOSE_REQUESTED: 'tauri://close-requested';

Source: event.ts:23


WINDOW_CREATED
WINDOW_CREATED: 'tauri://window-created';

Source: event.ts:24


WINDOW_DESTROYED
WINDOW_DESTROYED: 'tauri://destroyed';

Source: event.ts:25


WINDOW_FILE_DROP
WINDOW_FILE_DROP: 'tauri://file-drop';

Source: event.ts:30


WINDOW_FILE_DROP_CANCELLED
WINDOW_FILE_DROP_CANCELLED: 'tauri://file-drop-cancelled';

Source: event.ts:32


WINDOW_FILE_DROP_HOVER
WINDOW_FILE_DROP_HOVER: 'tauri://file-drop-hover';

Source: event.ts:31


WINDOW_FOCUS
WINDOW_FOCUS: 'tauri://focus';

Source: event.ts:26


WINDOW_MOVED
WINDOW_MOVED: 'tauri://move';

Source: event.ts:22


WINDOW_RESIZED
WINDOW_RESIZED: 'tauri://resize';

Source: event.ts:21


WINDOW_SCALE_FACTOR_CHANGED
WINDOW_SCALE_FACTOR_CHANGED: 'tauri://scale-change';

Source: event.ts:28


WINDOW_THEME_CHANGED
WINDOW_THEME_CHANGED: 'tauri://theme-changed';

Source: event.ts:29

Interfaces

Event

Type parameters

Parameter
T

Properties

PropertyTypeDescription
eventEventNameEvent name
idnumberEvent identifier used to unlisten
payloadTEvent payload
windowLabelstringThe label of the window that emitted this event.

Type Aliases

EventCallback

EventCallback: <T> (event) => void

Type parameters

Parameter
T

Parameters

ParameterType
eventEvent< T >

Returns

void

Source: helpers/event.ts:21


EventName

EventName: \${TauriEvent}\ | string & Record< never, never >

Source: event.ts:15


UnlistenFn

UnlistenFn: () => void

Returns

void

Source: helpers/event.ts:23

Functions

emit()

emit(event, payload?): Promise< void >

Emits an event to the backend and all Tauri windows.

Example

import { emit } from '@tauri-apps/api/event';
await emit('frontend-loaded', { loggedIn: true, token: 'authToken' });

Since

1.0.0

Parameters

ParameterTypeDescription
eventstringEvent name. Must include only alphanumeric characters, -, /, : and _.
payload?unknown-

Returns

Promise< void >

Source: event.ts:113


listen()

listen<T>(event, handler): Promise< UnlistenFn >

Listen to an event. The event can be either global or window-specific. See Event.windowLabel to check the event source.

Example

import { listen } from '@tauri-apps/api/event';
const unlisten = await listen<string>('error', (event) => {
console.log(`Got error in window ${event.windowLabel}, payload: ${event.payload}`);
});
// you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
unlisten();

Since

1.0.0

Type parameters

Parameter
T

Parameters

ParameterTypeDescription
eventEventNameEvent name. Must include only alphanumeric characters, -, /, : and _.
handlerEventCallback< T >Event handler callback.

Returns

Promise< UnlistenFn >

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.

Source: event.ts:63


once()

once<T>(event, handler): Promise< UnlistenFn >

Listen to an one-off event. See listen for more information.

Example

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 unmounted
unlisten();

Since

1.0.0

Type parameters

Parameter
T

Parameters

ParameterTypeDescription
eventEventNameEvent name. Must include only alphanumeric characters, -, /, : and _.
handlerEventCallback< T >-

Returns

Promise< UnlistenFn >

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.

Source: event.ts:94


© 2024 Tauri Contributors. CC-BY / MIT