2021-02-12 03:50:39 +03:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html>
|
2022-11-03 15:27:43 +03:00
|
|
|
<head>
|
|
|
|
<style>
|
|
|
|
#response {
|
|
|
|
white-space: pre-wrap;
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
</head>
|
2021-02-16 19:52:07 +03:00
|
|
|
|
2022-11-03 15:27:43 +03:00
|
|
|
<body>
|
|
|
|
<div id="window-label"></div>
|
|
|
|
<div id="container"></div>
|
|
|
|
<div id="response"></div>
|
2021-02-16 19:52:07 +03:00
|
|
|
|
2022-11-03 15:27:43 +03:00
|
|
|
<script>
|
2023-07-12 14:44:26 +03:00
|
|
|
const WebviewWindow = window.__TAURI__.window.WebviewWindow
|
|
|
|
const appWindow = window.__TAURI__.window.appWindow
|
|
|
|
const windowLabel = appWindow.label
|
|
|
|
const windowLabelContainer = document.getElementById('window-label')
|
2022-11-03 15:27:43 +03:00
|
|
|
windowLabelContainer.innerText = 'This is the ' + windowLabel + ' window.'
|
2021-02-16 19:52:07 +03:00
|
|
|
|
2023-07-12 14:44:26 +03:00
|
|
|
const container = document.getElementById('container')
|
2021-02-16 19:52:07 +03:00
|
|
|
|
2022-11-03 15:27:43 +03:00
|
|
|
function createWindowMessageBtn(label) {
|
2023-07-12 14:44:26 +03:00
|
|
|
const tauriWindow = WebviewWindow.getByLabel(label)
|
|
|
|
const button = document.createElement('button')
|
2022-11-03 15:27:43 +03:00
|
|
|
button.innerText = 'Send message to ' + label
|
|
|
|
button.addEventListener('click', function () {
|
|
|
|
tauriWindow.emit('clicked', 'message from ' + windowLabel)
|
|
|
|
})
|
|
|
|
container.appendChild(button)
|
|
|
|
}
|
2021-02-16 19:52:07 +03:00
|
|
|
|
2022-11-03 15:27:43 +03:00
|
|
|
// global listener
|
2023-07-12 14:44:26 +03:00
|
|
|
const responseContainer = document.getElementById('response')
|
2022-11-03 15:27:43 +03:00
|
|
|
window.__TAURI__.event.listen('clicked', function (event) {
|
|
|
|
responseContainer.innerHTML +=
|
|
|
|
'Got ' + JSON.stringify(event) + ' on global listener\n\n'
|
|
|
|
})
|
|
|
|
window.__TAURI__.event.listen('tauri://window-created', function (event) {
|
|
|
|
createWindowMessageBtn(event.payload.label)
|
2021-02-24 05:30:14 +03:00
|
|
|
})
|
2021-02-16 19:52:07 +03:00
|
|
|
|
2022-11-03 15:27:43 +03:00
|
|
|
// listener tied to this window
|
|
|
|
appWindow.listen('clicked', function (event) {
|
|
|
|
responseContainer.innerText +=
|
|
|
|
'Got ' + JSON.stringify(event) + ' on window listener\n\n'
|
2022-10-19 15:20:17 +03:00
|
|
|
})
|
2022-11-03 15:27:43 +03:00
|
|
|
|
2023-07-12 14:44:26 +03:00
|
|
|
const createWindowButton = document.createElement('button')
|
2022-11-03 15:27:43 +03:00
|
|
|
createWindowButton.innerHTML = 'Create window'
|
|
|
|
createWindowButton.addEventListener('click', function () {
|
2023-07-12 14:44:26 +03:00
|
|
|
const webviewWindow = new WebviewWindow(
|
2022-11-03 15:27:43 +03:00
|
|
|
Math.random().toString().replace('.', ''),
|
|
|
|
{
|
|
|
|
tabbingIdentifier: windowLabel
|
|
|
|
}
|
|
|
|
)
|
|
|
|
webviewWindow.once('tauri://created', function () {
|
|
|
|
responseContainer.innerHTML += 'Created new webview'
|
|
|
|
})
|
|
|
|
webviewWindow.once('tauri://error', function (e) {
|
|
|
|
responseContainer.innerHTML += 'Error creating new webview'
|
|
|
|
})
|
2022-09-18 15:16:35 +03:00
|
|
|
})
|
2022-11-03 15:27:43 +03:00
|
|
|
container.appendChild(createWindowButton)
|
2022-01-09 20:35:30 +03:00
|
|
|
|
2023-07-12 14:44:26 +03:00
|
|
|
const globalMessageButton = document.createElement('button')
|
2022-11-03 15:27:43 +03:00
|
|
|
globalMessageButton.innerHTML = 'Send global message'
|
|
|
|
globalMessageButton.addEventListener('click', function () {
|
|
|
|
// emit to all windows
|
|
|
|
window.__TAURI__.event.emit('clicked', 'message from ' + windowLabel)
|
|
|
|
})
|
|
|
|
container.appendChild(globalMessageButton)
|
2022-10-19 15:20:17 +03:00
|
|
|
|
2023-07-12 14:44:26 +03:00
|
|
|
const allWindows = window.__TAURI__.window.getAll()
|
|
|
|
for (const index in allWindows) {
|
|
|
|
const label = allWindows[index].label
|
2022-11-03 15:27:43 +03:00
|
|
|
if (label === windowLabel) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
createWindowMessageBtn(label)
|
2021-02-12 03:50:39 +03:00
|
|
|
}
|
2022-11-03 15:27:43 +03:00
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>
|