index.html 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4. <div id="window-label"></div>
  5. <div id="container"></div>
  6. <div id="response"></div>
  7. <script>
  8. var windowLabel = window.__TAURI__.window.getCurrentWindow().label;
  9. var windowLabelContainer = document.getElementById("window-label");
  10. windowLabelContainer.innerHTML =
  11. "This is the " + windowLabel + " window.";
  12. // global listener
  13. window.__TAURI__.event.listen("clicked", function (event) {
  14. responseContainer.innerHTML += "Got " + JSON.stringify(event) + " on global listener<br><br>";
  15. })
  16. var responseContainer = document.getElementById("response");
  17. var thisTauriWindow = window.__TAURI__.window.getTauriWindow()
  18. // listener tied to this window
  19. thisTauriWindow.listen("clicked", function (event) {
  20. responseContainer.innerHTML += "Got " + JSON.stringify(event) + " on window listener<br><br>";
  21. });
  22. var container = document.getElementById("container");
  23. var button = document.createElement("button");
  24. button.innerHTML = "Send global message";
  25. button.addEventListener("click", function () {
  26. // emit to all windows
  27. window.__TAURI__.event.emit("clicked", "message from " + windowLabel);
  28. });
  29. container.appendChild(button);
  30. for (var index in window.__TAURI__.window.getWindows()) {
  31. var label = window.__TAURI__.window.getWindows()[index].label;
  32. if (label === windowLabel) {
  33. continue;
  34. }
  35. var tauriWindow = window.__TAURI__.window.getTauriWindow(label)
  36. var button = document.createElement("button");
  37. button.innerHTML = "Send message to " + label;
  38. button.addEventListener("click", function () {
  39. tauriWindow.emit("clicked", "message from " + windowLabel);
  40. });
  41. container.appendChild(button);
  42. }
  43. </script>
  44. </body>
  45. </html>