2021-05-02 21:34:15 +03:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html lang="en">
|
2022-11-03 15:27:43 +03:00
|
|
|
<head>
|
|
|
|
<meta charset="UTF-8" />
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
|
|
<title>Tauri</title>
|
|
|
|
</head>
|
2021-05-02 21:34:15 +03:00
|
|
|
|
2022-11-03 15:27:43 +03:00
|
|
|
<body>
|
|
|
|
<h1>Tauri Commands</h1>
|
|
|
|
<div>Response: <span id="response"></span></div>
|
|
|
|
<div>Without Args: <span id="response-optional"></span></div>
|
|
|
|
<div id="container"></div>
|
|
|
|
<script>
|
|
|
|
function runCommand(commandName, args, optional) {
|
|
|
|
const id = optional ? '#response-optional' : '#response'
|
|
|
|
const result = document.querySelector(id)
|
|
|
|
window.__TAURI__
|
|
|
|
.invoke(commandName, args)
|
|
|
|
.then((response) => {
|
|
|
|
result.innerText = `Ok(${response})`
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
result.innerText = `Err(${error})`
|
|
|
|
})
|
2021-07-04 01:48:04 +03:00
|
|
|
}
|
2022-09-28 19:52:18 +03:00
|
|
|
|
2022-11-03 15:27:43 +03:00
|
|
|
const container = document.querySelector('#container')
|
|
|
|
const commands = [
|
|
|
|
{ name: 'borrow_cmd' },
|
|
|
|
{ name: 'window_label' },
|
|
|
|
{ name: 'simple_command' },
|
|
|
|
{ name: 'stateful_command' },
|
|
|
|
{ name: 'async_simple_command' },
|
|
|
|
{ name: 'async_simple_command_snake' },
|
|
|
|
{ name: 'future_simple_command' },
|
|
|
|
{ name: 'async_stateful_command' },
|
|
|
|
{ name: 'simple_command_with_result' },
|
|
|
|
// snake
|
|
|
|
{ name: 'future_simple_command_snake' },
|
|
|
|
{ name: 'future_simple_command_with_return_snake' },
|
|
|
|
{ name: 'future_simple_command_with_result_snake' },
|
|
|
|
{ name: 'force_async_snake' },
|
|
|
|
{ name: 'force_async_with_result_snake' },
|
|
|
|
{ name: 'simple_command_with_result_snake' },
|
|
|
|
{ name: 'stateful_command_with_result_snake' },
|
|
|
|
// state
|
|
|
|
{ name: 'stateful_command_with_result' },
|
|
|
|
{ name: 'async_simple_command_with_result' },
|
|
|
|
{ name: 'future_simple_command_with_return' },
|
|
|
|
{ name: 'future_simple_command_with_result' },
|
|
|
|
{ name: 'async_stateful_command_with_result' },
|
|
|
|
{ name: 'command_arguments_wild' },
|
|
|
|
{
|
|
|
|
name: 'command_arguments_struct',
|
2022-11-17 16:04:10 +03:00
|
|
|
args: { person: { name: 'ferris', age: 6 } }
|
2022-11-03 15:27:43 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'command_arguments_tuple_struct',
|
2022-11-17 16:04:10 +03:00
|
|
|
args: { inlinePerson: ['ferris', 6] }
|
2022-11-03 15:27:43 +03:00
|
|
|
}
|
|
|
|
]
|
2022-09-28 19:52:18 +03:00
|
|
|
|
2022-11-03 15:27:43 +03:00
|
|
|
for (const command of commands) {
|
|
|
|
const { name } = command
|
|
|
|
const args = command.args ?? {
|
|
|
|
[name.endsWith('snake') ? 'the_argument' : 'theArgument']: 'value'
|
|
|
|
}
|
|
|
|
const button = document.createElement('button')
|
|
|
|
button.innerHTML = `Run ${name}`
|
|
|
|
button.addEventListener('click', function () {
|
|
|
|
runCommand(name, args, false)
|
|
|
|
runCommand(name, Object.create(null), true)
|
|
|
|
})
|
|
|
|
container.appendChild(button)
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
</body>
|
2021-05-05 20:32:13 +03:00
|
|
|
</html>
|