index.html 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. const { WebviewWindow } = window.__TAURI__.webviewWindow
  16. const thisTauriWindow = window.__TAURI__.window.getCurrent()
  17. const windowLabel = thisTauriWindow.label
  18. const windowLabelContainer = document.getElementById('window-label')
  19. windowLabelContainer.innerText = 'This is the ' + windowLabel + ' window.'
  20. const container = document.getElementById('container')
  21. const responseContainer = document.getElementById('response')
  22. function runCommand(commandName, args, optional) {
  23. window.__TAURI__.core
  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. const createWindowButton = document.createElement('button')
  36. const windowId = Math.random().toString().replace('.', '')
  37. let windowNumber = 1
  38. createWindowButton.innerHTML = 'Create child window ' + windowNumber
  39. createWindowButton.addEventListener('click', function () {
  40. new WebviewWindow(`child-${windowId}-${windowNumber}`, {
  41. title: 'Child',
  42. width: 400,
  43. height: 300,
  44. parent: thisTauriWindow
  45. })
  46. windowNumber += 1
  47. createWindowButton.innerHTML = 'Create child window ' + windowNumber
  48. })
  49. container.appendChild(createWindowButton)
  50. </script>
  51. </body>
  52. </html>