From 9a23a8d68cfa3477b55778818d7d06b468f9b5ca Mon Sep 17 00:00:00 2001 From: GeckoEidechse Date: Mon, 29 Aug 2022 01:00:10 +0200 Subject: Get game install location on application load --- src-tauri/src/main.rs | 16 ++-------------- src-ui/src/main.ts | 12 +++++------- 2 files changed, 7 insertions(+), 21 deletions(-) diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 7fd7bf2e..79386ca6 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -36,20 +36,6 @@ fn main() { } }); - let app_handle = app.app_handle(); - tauri::async_runtime::spawn(async move { - // Checking install location inside a timed loop is a bad idea - // If the user has the game on a harddrive for example, it will prevent the harddrive from ever spinning down - // Instead, install location checks should be event based. - loop { - sleep(Duration::from_millis(5000)).await; - println!("sending install location"); - app_handle - .emit_all("install-location-result", find_game_install_location()) - .unwrap(); - } - }); - Ok(()) }) .manage(Counter(Default::default())) @@ -57,12 +43,14 @@ fn main() { hello_world, add_count, force_panic, + find_game_install_location, get_version_number ]) .run(tauri::generate_context!()) .expect("error while running tauri application"); } +#[tauri::command] fn find_game_install_location() -> String { // Attempt parsing Steam library directly match steamlocate::SteamDir::locate() { diff --git a/src-ui/src/main.ts b/src-ui/src/main.ts index e769a1b5..e5149bdd 100644 --- a/src-ui/src/main.ts +++ b/src-ui/src/main.ts @@ -13,13 +13,6 @@ document.addEventListener("DOMContentLoaded", async function () { let installLocationHolderEl = $("install-location-holder") as HTMLElement; let versionNumberHolderEl = $("version-number-holder") as HTMLElement; - // listen backend-ping event (from Tauri Rust App) - listen("install-location-result", function (evt: TauriEvent) { - // alert(evt.payload); - // result = evt as String; - installLocationHolderEl.textContent = evt.payload; - }) - // listen backend-ping event (from Tauri Rust App) listen("backend-ping", function (evt: TauriEvent) { pingEl.classList.add("on"); @@ -50,6 +43,11 @@ document.addEventListener("DOMContentLoaded", async function () { }); // Run the following on initial page load + // Get version number let version_number_string = await invoke("get_version_number") as string; versionNumberHolderEl.textContent = version_number_string; + + // Get install location + let install_location = await invoke("find_game_install_location") as string; + installLocationHolderEl.textContent = install_location; }) -- cgit v1.2.3