index.html 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  7. <title>Tauri</title>
  8. </head>
  9. <body>
  10. <h1>Tauri Commands</h1>
  11. <div>Response: <span id="response"></span></div>
  12. <div>Without Args: <span id="response-optional"></span></div>
  13. <div id="container"></div>
  14. <script>
  15. function runCommand(commandName, args, optional) {
  16. const id = optional ? '#response-optional' : '#response'
  17. const result = document.querySelector(id)
  18. window.__TAURI__
  19. .invoke(commandName, args)
  20. .then((response) => {
  21. result.innerText = `Ok(${response})`
  22. })
  23. .catch((error) => {
  24. result.innerText = `Err(${error})`
  25. })
  26. }
  27. const container = document.querySelector('#container')
  28. const commands = [
  29. { name: 'borrow_cmd' },
  30. { name: 'window_label' },
  31. { name: 'simple_command' },
  32. { name: 'stateful_command' },
  33. { name: 'async_simple_command' },
  34. { name: 'future_simple_command' },
  35. { name: 'async_stateful_command' },
  36. { name: 'simple_command_with_result' },
  37. { name: 'stateful_command_with_result' },
  38. { name: 'async_simple_command_with_result' },
  39. { name: 'future_simple_command_with_return' },
  40. { name: 'future_simple_command_with_result' },
  41. { name: 'async_stateful_command_with_result' },
  42. { name: 'command_arguments_wild' },
  43. {
  44. name: 'command_arguments_struct',
  45. args: { Person: { name: 'ferris', age: 6 } }
  46. },
  47. {
  48. name: 'command_arguments_tuple_struct',
  49. args: { InlinePerson: ['ferris', 6] }
  50. }
  51. ]
  52. for (const command of commands) {
  53. const { name } = command
  54. const args = command.args ?? { argument: 'value' }
  55. const button = document.createElement('button')
  56. button.innerHTML = `Run ${name}`
  57. button.addEventListener('click', function () {
  58. runCommand(name, args, false)
  59. runCommand(name, Object.create(null), true)
  60. })
  61. container.appendChild(button)
  62. }
  63. </script>
  64. </body>
  65. </html>