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]]
|
[[package]]
|
||||||
name = "qsv-easy-installer"
|
name = "qsv-easy-installer"
|
||||||
version = "0.1.0"
|
version = "1.0.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"reqwest",
|
"reqwest",
|
||||||
"serde",
|
"serde",
|
||||||
|
|
|
||||||
|
|
@ -1,30 +1,35 @@
|
||||||
|
use std::io::Write;
|
||||||
|
|
||||||
use tauri::Manager;
|
use tauri::Manager;
|
||||||
use tempfile::tempfile;
|
use tempfile::tempfile;
|
||||||
use winreg::{enums::HKEY_CURRENT_USER, RegKey};
|
use winreg::{enums::HKEY_CURRENT_USER, RegKey};
|
||||||
|
|
||||||
#[tauri::command]
|
#[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
|
// Get app local data dir path
|
||||||
let app_local_data_dir = app_handle.path().app_local_data_dir().unwrap();
|
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
|
// Download qsv to bin dir if it doesn't exist and overwrite any existing qsv
|
||||||
// Get the version of qsv
|
// Get the version of qsv
|
||||||
let latest_release_endpoint = "https://api.github.com/repos/dathere/qsv/releases/latest";
|
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
|
let res = client
|
||||||
.get(latest_release_endpoint)
|
.get(latest_release_endpoint)
|
||||||
.header(reqwest::header::USER_AGENT, "qsv easy installer")
|
.header(reqwest::header::USER_AGENT, "qsv easy installer")
|
||||||
.send()
|
.send()
|
||||||
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.json::<serde_json::Value>()
|
.json::<serde_json::Value>()
|
||||||
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let release_version = res.get("name").unwrap().as_str().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)
|
// 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 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();
|
let mut temp_zip_file = tempfile().unwrap();
|
||||||
reqwest::blocking::get(zip_download_url)
|
let zip_bytes = reqwest::get(zip_download_url)
|
||||||
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.copy_to(&mut temp_zip_file)
|
.bytes().await.unwrap();
|
||||||
.unwrap();
|
temp_zip_file.write_all(&zip_bytes).unwrap();
|
||||||
let mut zip = zip::ZipArchive::new(temp_zip_file).unwrap();
|
let mut zip = zip::ZipArchive::new(temp_zip_file).unwrap();
|
||||||
let mut qsvp = zip.by_name("qsvp.exe").unwrap();
|
let mut qsvp = zip.by_name("qsvp.exe").unwrap();
|
||||||
// Create a bin folder in app_local_data_dir if it doesn't exist
|
// 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}");
|
let updated_path_var = format!("{bin_dir_str};{path_var}");
|
||||||
reg_key.set_value("Path", &updated_path_var).unwrap();
|
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)]
|
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||||
|
|
|
||||||
13
src/App.tsx
13
src/App.tsx
|
|
@ -22,9 +22,14 @@ function App() {
|
||||||
disabled={loading}
|
disabled={loading}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
invoke("run_path_update").finally(() => {
|
invoke("run_path_update")
|
||||||
setLoading(false);
|
.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"
|
className="mx-auto w-full flex justify-center bg-blue-400"
|
||||||
>
|
>
|
||||||
|
|
@ -36,7 +41,7 @@ function App() {
|
||||||
</button>
|
</button>
|
||||||
{loading && (
|
{loading && (
|
||||||
<p className="mt-4 text-center">
|
<p className="mt-4 text-center">
|
||||||
Downloading and installing to PATH. This may take a few seconds...
|
Downloading and installing qsv to PATH. This may take a few seconds...
|
||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
</main>
|
</main>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue