event.ts 749 B

1234567891011121314151617181920212223242526272829303132
  1. // Copyright 2019-2021 Tauri Programme within The Commons Conservancy
  2. // SPDX-License-Identifier: Apache-2.0
  3. // SPDX-License-Identifier: MIT
  4. import { WindowLabel } from '../window'
  5. import { invokeTauriCommand } from './tauri'
  6. /**
  7. * Emits an event to the backend.
  8. *
  9. * @param event Event name
  10. * @param [windowLabel] The label of the window to which the event is sent, if null/undefined the event will be sent to all windows
  11. * @param [payload] Event payload
  12. * @returns
  13. */
  14. async function emit(
  15. event: string,
  16. windowLabel: WindowLabel,
  17. payload?: string
  18. ): Promise<void> {
  19. await invokeTauriCommand({
  20. __tauriModule: 'Event',
  21. message: {
  22. cmd: 'emit',
  23. event,
  24. windowLabel,
  25. payload
  26. }
  27. })
  28. }
  29. export { emit }