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!") 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)] #[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() { pub fn run() {
tauri::Builder::default() tauri::Builder::default()
.plugin(tauri_plugin_os::init()) .plugin(tauri_plugin_os::init())
.plugin(tauri_plugin_shell::init()) .plugin(tauri_plugin_shell::init())
.invoke_handler(tauri::generate_handler![greet]) .invoke_handler(tauri::generate_handler![greet, os_info])
.run(tauri::generate_context!()) .run(tauri::generate_context!())
.expect("error while running tauri application"); .expect("error while running tauri application");
} }

View File

@ -36,6 +36,12 @@
</form> </form>
<p id="greet-msg"></p> <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> </div>
</body> </body>
</html> </html>

View File

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