communication.js 667 B

12345678910111213141516171819202122
  1. document.getElementById('log').addEventListener('click', function () {
  2. window.__TAURI__.tauri.invoke({
  3. cmd: 'logOperation',
  4. event: 'tauri-click',
  5. payload: 'this payload is optional because we used Option in Rust'
  6. })
  7. })
  8. document.getElementById('request').addEventListener('click', function () {
  9. window.__TAURI__.tauri.promisified({
  10. cmd: 'performRequest',
  11. endpoint: 'dummy endpoint arg',
  12. body: {
  13. id: 5,
  14. name: 'test'
  15. }
  16. }).then(registerResponse).catch(registerResponse)
  17. })
  18. document.getElementById('event').addEventListener('click', function () {
  19. window.__TAURI__.event.emit('js-event', 'this is the payload string')
  20. })