diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 3d3d0dc..effc37c 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -7,9 +7,14 @@ fn greet(name: &str) -> String { format!("Gokigen'you, {}-san! You've been greeted from Rust!", name) } +#[tauri::command] +fn bash(name: &str) -> String { + format!("/me bashes {name} with a hammer!") +} + fn main() { tauri::Builder::default() - .invoke_handler(tauri::generate_handler![greet]) + .invoke_handler(tauri::generate_handler![greet, bash]) .run(tauri::generate_context!()) .expect("error while running tauri application"); } diff --git a/src/index.html b/src/index.html index 3b7e70d..0bb97a0 100644 --- a/src/index.html +++ b/src/index.html @@ -28,13 +28,18 @@ -

Click on the Tauri logo to learn more about the framework

+

Always be closin'

+
+ + +
+

diff --git a/src/main.js b/src/main.js index 1b1aa0a..fad71f7 100644 --- a/src/main.js +++ b/src/main.js @@ -7,11 +7,23 @@ async function greet(greetMsgEl) { greetMsgEl.textContent = await invoke("greet", { name: greetInputEl.value }); } +async function bash(bashNameEl, resultEl) { + resultEl.textContent = await invoke("bash", { name: bashNameEl.value }); +} + window.addEventListener("DOMContentLoaded", () => { greetInputEl = document.querySelector("#greet-input"); const greetMsgEl = document.querySelector("#greet-msg"); + document.querySelector("#greet-form").addEventListener("submit", (e) => { e.preventDefault(); greet(greetMsgEl); }); + + document.querySelector("#bash-form").addEventListener("submit", (e) => { + e.preventDefault(); + let bashNameEl = document.querySelector("#bash-input"); + const resultEl = document.querySelector("#greet-msg"); + bash(bashNameEl, resultEl); + }); });