aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src-tauri/src/main.rs25
-rw-r--r--src-ui/src/main.ts9
2 files changed, 13 insertions, 21 deletions
diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs
index cbf10065..7fd7bf2e 100644
--- a/src-tauri/src/main.rs
+++ b/src-tauri/src/main.rs
@@ -50,28 +50,14 @@ fn main() {
}
});
- let app_handle = app.app_handle();
- tauri::async_runtime::spawn(async move {
- // Sending current version inside a timed loop is a bad idea as it shouldn't change at runtime
- // The reason this is currently done like this is cause I haven't figure out yet how to just send it once / read it in front-end
- let version = env!("CARGO_PKG_VERSION");
- loop {
- sleep(Duration::from_millis(1000)).await;
- println!("sending install location");
- println!("{}", version);
- app_handle
- .emit_all("current-version-ping", version)
- .unwrap();
- }
- });
-
Ok(())
})
.manage(Counter(Default::default()))
.invoke_handler(tauri::generate_handler![
hello_world,
add_count,
- force_panic
+ force_panic,
+ get_version_number
])
.run(tauri::generate_context!())
.expect("error while running tauri application");
@@ -113,3 +99,10 @@ fn add_count(num: i32, counter: State<'_, Counter>) -> String {
fn force_panic() {
panic!("Force panicked!");
}
+
+#[tauri::command]
+/// Returns the current version number as a string
+fn get_version_number() -> String {
+ let version = env!("CARGO_PKG_VERSION");
+ format!("v{}", version)
+}
diff --git a/src-ui/src/main.ts b/src-ui/src/main.ts
index fcd68cb4..e769a1b5 100644
--- a/src-ui/src/main.ts
+++ b/src-ui/src/main.ts
@@ -20,11 +20,6 @@ document.addEventListener("DOMContentLoaded", async function () {
installLocationHolderEl.textContent = evt.payload;
})
- // listen for version number ping
- listen("current-version-ping", function (evt: TauriEvent<string>) {
- versionNumberHolderEl.textContent = evt.payload;
- })
-
// listen backend-ping event (from Tauri Rust App)
listen("backend-ping", function (evt: TauriEvent<any>) {
pingEl.classList.add("on");
@@ -53,4 +48,8 @@ document.addEventListener("DOMContentLoaded", async function () {
await invoke("force_panic");
alert("Never should have been able to get here!");
});
+
+ // Run the following on initial page load
+ let version_number_string = await invoke("get_version_number") as string;
+ versionNumberHolderEl.textContent = version_number_string;
})