1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- <!DOCTYPE html>
- <html>
- <body>
- <div id="window-label"></div>
- <div id="container"></div>
- <div id="response"></div>
- <script>
- var windowLabel = window.__TAURI__.window.getCurrentWindow().label;
- var windowLabelContainer = document.getElementById("window-label");
- windowLabelContainer.innerHTML =
- "This is the " + windowLabel + " window.";
- // global listener
- window.__TAURI__.event.listen("clicked", function (event) {
- responseContainer.innerHTML += "Got " + JSON.stringify(event) + " on global listener<br><br>";
- })
- var responseContainer = document.getElementById("response");
- var thisTauriWindow = window.__TAURI__.window.getTauriWindow()
- // listener tied to this window
- thisTauriWindow.listen("clicked", function (event) {
- responseContainer.innerHTML += "Got " + JSON.stringify(event) + " on window listener<br><br>";
- });
- var container = document.getElementById("container");
- var button = document.createElement("button");
- button.innerHTML = "Send global message";
- button.addEventListener("click", function () {
- // emit to all windows
- window.__TAURI__.event.emit("clicked", "message from " + windowLabel);
- });
- container.appendChild(button);
- for (var index in window.__TAURI__.window.getWindows()) {
- var label = window.__TAURI__.window.getWindows()[index].label;
- if (label === windowLabel) {
- continue;
- }
- var tauriWindow = window.__TAURI__.window.getTauriWindow(label)
- var button = document.createElement("button");
- button.innerHTML = "Send message to " + label;
- button.addEventListener("click", function () {
- tauriWindow.emit("clicked", "message from " + windowLabel);
- });
- container.appendChild(button);
- }
- </script>
- </body>
- </html>
|