index.html 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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__.invoke(commandName, args).then(response => {
  19. result.innerText = `Ok(${response})`
  20. }).catch(error => {
  21. result.innerText = `Err(${error})`
  22. })
  23. }
  24. const container = document.querySelector('#container')
  25. const commands = [
  26. { name: 'borrow_cmd' },
  27. { name: 'window_label' },
  28. { name: 'simple_command' },
  29. { name: 'stateful_command' },
  30. { name: 'async_simple_command' },
  31. { name: 'future_simple_command'},
  32. { name: 'async_stateful_command' },
  33. { name: 'simple_command_with_result' },
  34. { name: 'stateful_command_with_result' },
  35. { name: 'async_simple_command_with_result' },
  36. { name: 'future_simple_command_with_return' },
  37. { name: 'future_simple_command_with_result' },
  38. { name: 'async_stateful_command_with_result' },
  39. { name: 'command_arguments_wild' },
  40. { name: 'command_arguments_struct', args: { "Person": { "name": "ferris", age: 6 } } },
  41. { name: 'command_arguments_tuple_struct', args: { "InlinePerson": [ "ferris", 6 ] } },
  42. ]
  43. for (const command of commands) {
  44. const { name } = command
  45. const args = command.args ?? { argument: 'value' }
  46. const button = document.createElement('button')
  47. button.innerHTML = `Run ${name}`;
  48. button.addEventListener("click", function () {
  49. runCommand(name, args, false)
  50. runCommand(name, Object.create(null), true)
  51. });
  52. container.appendChild(button);
  53. }
  54. </script>
  55. </body>
  56. </html>