tauri/examples/commands/public/index.html
Lucas Fernandes Nogueira 8b6f3de0ad
feat(core): add state management, closes #1655 (#1665)
* feat(core): add state management, closes #1655

* fix(tests): ignore doc example

* use a trait to manage #[command] parameters

* add docs [skip ci]

* finish command before moving into respond_async

* Revert "finish command before moving into respond_async"

This reverts commit 4651bed5bf.

* refactor: split InvokeMessage into InvokeResolver, add InvokeResponse

* feat: add managed state to the plugin interface

* feat: add commands example

* add change file [skip ci]

* cleanup clones

Co-authored-by: chip reed <chip@chip.sh>
2021-05-02 15:34:15 -03:00

55 lines
1.7 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Tauri</title>
</head>
<body>
<h1>Tauri Commands</h1>
<div id="response">Response:</div>
<div id="container"></div>
<script>
const responseDiv = document.querySelector('#response')
function runCommand(commandName, args) {
window.__TAURI__.invoke(commandName, args).then(response => {
responseDiv.innerHTML = `Response: Ok(${response})`
}).catch(error => {
responseDiv.innerHTML = `Response: Err(${error})`
})
}
const container = document.querySelector('#container')
const commands = [
{ name: 'simple_command', required: true },
{ name: 'stateful_command', required: false },
{ name: 'async_simple_command', required: true },
{ name: 'async_stateful_command', required: false },
{ name: 'simple_command_with_result', required: true },
{ name: 'stateful_command_with_result', required: false },
{ name: 'async_simple_command_with_result', required: true },
{ name: 'async_stateful_command_with_result', required: false },
]
for (command of commands) {
const { name, required } = command
const button = document.createElement('button')
button.innerHTML = `Run ${name}`;
button.addEventListener("click", function () {
runCommand(name, { argument: 'value' })
if (!required) {
setTimeout(() => {
runCommand(name, {})
}, 1000)
}
});
container.appendChild(button);
}
</script>
</body>
</html>