Updates
This commit is contained in:
parent
eeff2134d9
commit
264d9aa2fe
@ -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");
|
||||
}
|
||||
|
@ -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>
|
||||
|
12
src/main.js
12
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);
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user