index.html 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <style>
  5. #response {
  6. white-space: pre-wrap;
  7. }
  8. </style>
  9. </head>
  10. <body>
  11. <div id="window-label"></div>
  12. <div id="container"></div>
  13. <div id="response"></div>
  14. <script>
  15. var WebviewWindow = window.__TAURI__.window.WebviewWindow
  16. var thisTauriWindow = window.__TAURI__.window.getCurrent()
  17. var windowLabel = thisTauriWindow.label
  18. var windowLabelContainer = document.getElementById('window-label')
  19. windowLabelContainer.innerText = 'This is the ' + windowLabel + ' window.'
  20. var container = document.getElementById('container')
  21. var responseContainer = document.getElementById('response')
  22. function runCommand(commandName, args, optional) {
  23. window.__TAURI__
  24. .invoke(commandName, args)
  25. .then((response) => {
  26. responseContainer.innerText += `Ok(${response})\n\n`
  27. })
  28. .catch((error) => {
  29. responseContainer.innerText += `Err(${error})\n\n`
  30. })
  31. }
  32. window.__TAURI__.event.listen('tauri://window-created', function (event) {
  33. responseContainer.innerText += 'Got window-created event\n\n'
  34. })
  35. var createWindowButton = document.createElement('button')
  36. var windowId = Math.random().toString().replace('.', '')
  37. var windowNumber = 1
  38. createWindowButton.innerHTML = 'Create child window ' + windowNumber
  39. createWindowButton.addEventListener('click', function () {
  40. runCommand('create_child_window', { id: `child-${windowId}-${windowNumber}` })
  41. windowNumber += 1
  42. createWindowButton.innerHTML = 'Create child window ' + windowNumber
  43. })
  44. container.appendChild(createWindowButton)
  45. </script>
  46. </body>
  47. </html>