12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- <!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.";
- var container = document.getElementById("container");
- function createWindowMessageBtn(label) {
- 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);
- }
- // global listener
- window.__TAURI__.event.listen("clicked", function (event) {
- responseContainer.innerHTML += "Got " + JSON.stringify(event) + " on global listener<br><br>";
- })
- window.__TAURI__.event.listen('tauri://window-created', function (event) {
- createWindowMessageBtn(event.payload.label)
- })
- 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 createWindowButton = document.createElement("button");
- createWindowButton.innerHTML = "Create window";
- createWindowButton.addEventListener("click", function () {
- window.__TAURI__.window.createWindow(Math.random().toString());
- });
- container.appendChild(createWindowButton);
- var globalMessageButton = document.createElement("button");
- globalMessageButton.innerHTML = "Send global message";
- globalMessageButton.addEventListener("click", function () {
- // emit to all windows
- window.__TAURI__.event.emit("clicked", "message from " + windowLabel);
- });
- container.appendChild(globalMessageButton);
- for (var index in window.__TAURI__.window.getWindows()) {
- var label = window.__TAURI__.window.getWindows()[index].label;
- if (label === windowLabel) {
- continue;
- }
- createWindowMessageBtn(label)
- }
- </script>
- </body>
- </html>
|