This commit is contained in:
Greg Shuflin 2024-08-07 19:35:14 -07:00
parent eeff2134d9
commit 264d9aa2fe
3 changed files with 24 additions and 2 deletions

View File

@ -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");
}

View File

@ -28,13 +28,18 @@
</a>
</div>
<p>Click on the Tauri logo to learn more about the framework</p>
<p>Always be closin'</p>
<form class="row" id="greet-form">
<input id="greet-input" placeholder="Enter a name..." />
<button type="submit">Greet</button>
</form>
<form class="row" id="bash-form">
<input id="bash-input" placeholder="Enter a name..." />
<button type="submit">Bash with a hammer</button>
</form>
<p id="greet-msg"></p>
</div>
</body>

View File

@ -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);
});
});