From f776d7f29359a2667757b5ba940009347686b278 Mon Sep 17 00:00:00 2001 From: rzmk <30333942+rzmk@users.noreply.github.com> Date: Tue, 22 Apr 2025 10:45:50 -0400 Subject: [PATCH] feat: add alert, version info, and async run --- src-tauri/Cargo.lock | 2 +- src-tauri/src/lib.rs | 17 ++++++++++++----- src/App.tsx | 13 +++++++++---- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 889bf1e..c7b3fc0 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -3058,7 +3058,7 @@ dependencies = [ [[package]] name = "qsv-easy-installer" -version = "0.1.0" +version = "1.0.0" dependencies = [ "reqwest", "serde", diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 352dcf2..8fd6ed7 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -1,30 +1,35 @@ +use std::io::Write; + use tauri::Manager; use tempfile::tempfile; use winreg::{enums::HKEY_CURRENT_USER, RegKey}; #[tauri::command] -fn run_path_update(app_handle: tauri::AppHandle) { +async fn run_path_update(app_handle: tauri::AppHandle) -> String { // Get app local data dir path let app_local_data_dir = app_handle.path().app_local_data_dir().unwrap(); // Download qsv to bin dir if it doesn't exist and overwrite any existing qsv // Get the version of qsv let latest_release_endpoint = "https://api.github.com/repos/dathere/qsv/releases/latest"; - let client = reqwest::blocking::Client::new(); + let client = reqwest::Client::new(); let res = client .get(latest_release_endpoint) .header(reqwest::header::USER_AGENT, "qsv easy installer") .send() + .await .unwrap() .json::() + .await .unwrap(); let release_version = res.get("name").unwrap().as_str().unwrap(); // Download the zip file temporarily then extract the relevant qsvp file (we use qsvp instead of qsv for the broadest compatibility) let zip_download_url = format!("https://github.com/dathere/qsv/releases/download/{release_version}/qsv-{release_version}-x86_64-pc-windows-msvc.zip"); let mut temp_zip_file = tempfile().unwrap(); - reqwest::blocking::get(zip_download_url) + let zip_bytes = reqwest::get(zip_download_url) + .await .unwrap() - .copy_to(&mut temp_zip_file) - .unwrap(); + .bytes().await.unwrap(); + temp_zip_file.write_all(&zip_bytes).unwrap(); let mut zip = zip::ZipArchive::new(temp_zip_file).unwrap(); let mut qsvp = zip.by_name("qsvp.exe").unwrap(); // Create a bin folder in app_local_data_dir if it doesn't exist @@ -46,6 +51,8 @@ fn run_path_update(app_handle: tauri::AppHandle) { let updated_path_var = format!("{bin_dir_str};{path_var}"); reg_key.set_value("Path", &updated_path_var).unwrap(); } + drop(qsv_file); + String::from_utf8(std::process::Command::new(bin_dir.join("qsv.exe")).arg("--version").output().unwrap().stdout).unwrap() } #[cfg_attr(mobile, tauri::mobile_entry_point)] diff --git a/src/App.tsx b/src/App.tsx index 4f1da8b..ce12373 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -22,9 +22,14 @@ function App() { disabled={loading} onClick={() => { setLoading(true); - invoke("run_path_update").finally(() => { - setLoading(false); - }); + invoke("run_path_update") + .then((message) => { + setLoading(false); + alert("Successfully installed qsv. Try opening a new terminal and run a qsv command! Version info: " + message); + }) + .finally(() => { + setLoading(false); + }); }} className="mx-auto w-full flex justify-center bg-blue-400" > @@ -36,7 +41,7 @@ function App() { {loading && (

- Downloading and installing to PATH. This may take a few seconds... + Downloading and installing qsv to PATH. This may take a few seconds...

)}