|
| 1 | +<!DOCTYPE html> |
| 2 | +<html> |
| 3 | + |
| 4 | +<head> |
| 5 | + <style> |
| 6 | + #response { |
| 7 | + white-space: pre-wrap; |
| 8 | + } |
| 9 | + </style> |
| 10 | +</head> |
| 11 | + |
| 12 | +<body> |
| 13 | + <div id="window-label"></div> |
| 14 | + <div id="container"></div> |
| 15 | + <div id="response"></div> |
| 16 | + |
| 17 | + <script> |
| 18 | + var WebviewWindow = window.__TAURI__.window.WebviewWindow |
| 19 | + var thisTauriWindow = window.__TAURI__.window.getCurrent() |
| 20 | + var windowLabel = thisTauriWindow.label |
| 21 | + var windowLabelContainer = document.getElementById('window-label') |
| 22 | + windowLabelContainer.innerText = 'This is the ' + windowLabel + ' window.' |
| 23 | + |
| 24 | + var container = document.getElementById('container') |
| 25 | + |
| 26 | + var responseContainer = document.getElementById('response') |
| 27 | + function runCommand(commandName, args, optional) { |
| 28 | + window.__TAURI__ |
| 29 | + .invoke(commandName, args) |
| 30 | + .then((response) => { |
| 31 | + responseContainer.innerText += `Ok(${response})\n\n` |
| 32 | + }) |
| 33 | + .catch((error) => { |
| 34 | + responseContainer.innerText += `Err(${error})\n\n` |
| 35 | + }) |
| 36 | + } |
| 37 | + window.__TAURI__.event.listen('tauri://window-created', function (event) { |
| 38 | + responseContainer.innerText += 'Got window-created event\n\n' |
| 39 | + }) |
| 40 | + |
| 41 | + var createWindowButton = document.createElement('button') |
| 42 | + var windowNumber = 1 |
| 43 | + createWindowButton.innerHTML = 'Create child window '+windowNumber |
| 44 | + createWindowButton.addEventListener('click', function () { |
| 45 | + runCommand('create_child_window', { id: 'child-'+windowNumber }) |
| 46 | + windowNumber += 1 |
| 47 | + createWindowButton.innerHTML = 'Create child window '+windowNumber |
| 48 | + }) |
| 49 | + container.appendChild(createWindowButton) |
| 50 | + </script> |
| 51 | +</body> |
| 52 | + |
| 53 | +</html> |
0 commit comments