event.ts 765 B

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