communication.js 806 B

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