2021-06-17 04:18:24 +03:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html lang="en">
|
2022-09-18 15:16:35 +03:00
|
|
|
<head>
|
|
|
|
<meta charset="UTF-8" />
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
|
|
<title>Sidecar</title>
|
|
|
|
<style>
|
|
|
|
.container {
|
|
|
|
display: flex;
|
|
|
|
}
|
|
|
|
.container > div {
|
|
|
|
flex: 1;
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
</head>
|
2021-06-17 04:18:24 +03:00
|
|
|
|
2022-09-18 15:16:35 +03:00
|
|
|
<body>
|
|
|
|
<div class="container">
|
|
|
|
<div id="backend"></div>
|
|
|
|
<div id="frontend"></div>
|
|
|
|
</div>
|
|
|
|
<script>
|
|
|
|
function addMessage(div, message) {
|
|
|
|
const p = document.createElement('p')
|
|
|
|
p.innerText = message
|
|
|
|
div.appendChild(p)
|
|
|
|
}
|
2022-03-02 16:21:36 +03:00
|
|
|
|
2022-09-18 15:16:35 +03:00
|
|
|
const backendDiv = document.getElementById('backend')
|
|
|
|
window.__TAURI__.event.listen('message', (event) => {
|
|
|
|
addMessage(backendDiv, event.payload)
|
|
|
|
})
|
2022-03-02 16:21:36 +03:00
|
|
|
|
2022-09-18 15:16:35 +03:00
|
|
|
const frontendDiv = document.getElementById('frontend')
|
|
|
|
const { Command } = window.__TAURI__.shell
|
|
|
|
const command = Command.sidecar('binaries/app')
|
|
|
|
command.on('close', (data) => {
|
|
|
|
addMessage(
|
|
|
|
frontendDiv,
|
|
|
|
`command finished with code ${data.code} and signal ${data.signal}`
|
|
|
|
)
|
|
|
|
})
|
|
|
|
command.on('error', (error) =>
|
|
|
|
addMessage(frontendDiv, `command error: "${error}"`)
|
|
|
|
)
|
|
|
|
command.stdout.on('data', (line) =>
|
|
|
|
addMessage(frontendDiv, `command stdout: "${line}"`)
|
|
|
|
)
|
|
|
|
command.stderr.on('data', (line) =>
|
|
|
|
addMessage(frontendDiv, `command stderr: "${line}"`)
|
|
|
|
)
|
|
|
|
command.spawn()
|
|
|
|
</script>
|
|
|
|
</body>
|
2021-06-17 04:18:24 +03:00
|
|
|
</html>
|