OS Info usage

This commit is contained in:
Greg Shuflin 2024-10-02 20:24:51 -07:00
parent 48dd9f5e0a
commit 5bf2c3d0ff
3 changed files with 26 additions and 1 deletions

View File

@ -4,12 +4,19 @@ fn greet(name: &str) -> String {
format!("Gamarjoba, {name}! This is coming from Rust!")
}
#[tauri::command]
fn os_info() -> String {
println!("MAKING A REQUEST");
let platform = tauri_plugin_os::platform();
format!("Platform Info: {}", platform)
}
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
tauri::Builder::default()
.plugin(tauri_plugin_os::init())
.plugin(tauri_plugin_shell::init())
.invoke_handler(tauri::generate_handler![greet])
.invoke_handler(tauri::generate_handler![greet, os_info])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}

View File

@ -36,6 +36,12 @@
</form>
<p id="greet-msg"></p>
<br/>
<form class="row" id="os-info-form">
<button type="submit">Get Info About OS</button>
</form>
<p id="os-msg"></p>
</div>
</body>
</html>

View File

@ -8,6 +8,12 @@ async function greet() {
greetMsgEl.textContent = await invoke("greet", { name: greetInputEl.value });
}
async function os_info(elem) {
elem.textContent = await invoke("os_info", {});
}
window.addEventListener("DOMContentLoaded", () => {
greetInputEl = document.querySelector("#greet-input");
greetMsgEl = document.querySelector("#greet-msg");
@ -15,4 +21,10 @@ window.addEventListener("DOMContentLoaded", () => {
e.preventDefault();
greet();
});
document.querySelector("#os-info-form").addEventListener("submit", (e) => {
e.preventDefault();
const elem = document.querySelector("#os-msg");
os_info(elem);
});
});