The event system allows you to emit events to the backend and listen to events from it.
DRAG_DROP: " tauri://drag-drop " ;
DRAG_ENTER: " tauri://drag-enter " ;
DRAG_LEAVE: " tauri://drag-leave " ;
DRAG_OVER: " tauri://drag-over " ;
WEBVIEW_CREATED: " tauri://webview-created " ;
WINDOW_BLUR: " tauri://blur " ;
WINDOW_CLOSE_REQUESTED: " tauri://close-requested " ;
WINDOW_CREATED: " tauri://window-created " ;
WINDOW_DESTROYED: " tauri://destroyed " ;
WINDOW_FOCUS: " tauri://focus " ;
WINDOW_MOVED: " tauri://move " ;
WINDOW_RESIZED: " tauri://resize " ;
WINDOW_SCALE_FACTOR_CHANGED: " tauri://scale-change " ;
WINDOW_THEME_CHANGED: " tauri://theme-changed " ;
Property Type Description Defined in event
EventName
Event name id
number
Event identifier used to unlisten payload
T
Event payload
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.
type EventCallback< T >: (event) = > void ;
Parameter Type event
Event
<T
>
void
type EventName: ` ${ TauriEvent } ` | string & Record< never , never >;
type UnlistenFn: () = > void ;
void
function emit < T > ( event , payload ? ) : Promise < void >
Emits an event to all targets .
Parameter Type Description event
string
Event name. Must include only alphanumeric characters, -
, /
, :
and _
. payload
?T
Event payload.
Promise
<void
>
import { emit } from ' @crabnebula/taurify-api/event ' ;
await emit ( ' frontend-loaded ' , { loggedIn: true , token: ' authToken ' });
Emits an event to all targets matching the given target.
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 ' @crabnebula/taurify-api/event ' ;
await emitTo ( ' main ' , ' frontend-loaded ' , { loggedIn: true , token: ' authToken ' });
options ? ) : Promise < UnlistenFn >
Listen to an emitted event to any target .
Parameter Type Description event
EventName
Event name. Must include only alphanumeric characters, -
, /
, :
and _
. handler
EventCallback
<T
>Event handler callback. options
?Options
Event listening options.
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.
import { listen } from ' @crabnebula/taurify-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 unmounted
options ? ) : Promise < UnlistenFn >
Listens once to an emitted event to any target .
Parameter Type Description event
EventName
Event name. Must include only alphanumeric characters, -
, /
, :
and _
. handler
EventCallback
<T
>Event handler callback. options
?Options
Event listening options.
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.
import { once } from ' @crabnebula/taurify-api/event ' ;
interface LoadedPayload {
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