mirror of
https://github.com/tauri-apps/tauri.git
synced 2024-12-19 08:31:35 +03:00
2681ad361b
Co-authored-by: Quentin Goinaud <armaldio@gmail.com> Co-authored-by: Lucas Fernandes Nogueira <lucasfernandesnog@gmail.com> Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
37 lines
662 B
TypeScript
37 lines
662 B
TypeScript
import { invoke, transformCallback } from './tauri'
|
|
import { EventCallback } from './types/event'
|
|
|
|
/**
|
|
* listen to an event from the backend
|
|
*
|
|
* @param event the event name
|
|
* @param handler the event handler callback
|
|
*/
|
|
function listen(event: string, handler: EventCallback, once = false): void {
|
|
invoke({
|
|
cmd: 'listen',
|
|
event,
|
|
handler: transformCallback(handler, once),
|
|
once
|
|
})
|
|
}
|
|
|
|
/**
|
|
* emits an event to the backend
|
|
*
|
|
* @param event the event name
|
|
* @param [payload] the event payload
|
|
*/
|
|
function emit(event: string, payload?: string): void {
|
|
invoke({
|
|
cmd: 'emit',
|
|
event,
|
|
payload
|
|
})
|
|
}
|
|
|
|
export {
|
|
listen,
|
|
emit
|
|
}
|