mirror of
https://github.com/dathere/qsv-easy-windows-installer.git
synced 2025-12-19 08:39:24 +00:00
feat: add alert, version info, and async run
This commit is contained in:
parent
ca5bc328fc
commit
f776d7f293
3 changed files with 22 additions and 10 deletions
2
src-tauri/Cargo.lock
generated
2
src-tauri/Cargo.lock
generated
|
|
@ -3058,7 +3058,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "qsv-easy-installer"
|
||||
version = "0.1.0"
|
||||
version = "1.0.0"
|
||||
dependencies = [
|
||||
"reqwest",
|
||||
"serde",
|
||||
|
|
|
|||
|
|
@ -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::<serde_json::Value>()
|
||||
.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)]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue