update download + apply flow

This commit is contained in:
2026-05-12 01:59:39 +03:00
parent 953263028b
commit 61fbe68251
4 changed files with 233 additions and 16 deletions
+49
View File
@@ -227,6 +227,52 @@ struct DownloadProgress {
total: Option<u64>,
}
#[derive(Clone, Serialize)]
struct UpdateDownloadProgress {
downloaded: u64,
total: Option<u64>,
}
#[tauri::command]
async fn download_update(
app: AppHandle,
state: State<'_, AppState>,
url: String,
) -> Result<(), String> {
let dest = updates::pending_update_path(&state.app_dir);
let app_handle = app.clone();
updates::download_to(&url, &dest, move |downloaded, total| {
let _ = app_handle.emit(
"update-download-progress",
UpdateDownloadProgress { downloaded, total },
);
})
.await
.map_err(|e| format!("{e:#}"))
}
#[tauri::command]
fn apply_update(app: AppHandle, state: State<'_, AppState>) -> Result<(), String> {
use std::os::windows::process::CommandExt;
use std::process::Command;
if !updates::has_pending_update(&state.app_dir) {
return Err("no pending update to apply".to_string());
}
let bat = updates::write_apply_script(&state.app_dir).map_err(|e| format!("{e:#}"))?;
Command::new("cmd")
.args(["/c", "start", "", ""])
.raw_arg(format!("\"{}\"", bat.to_string_lossy()))
.spawn()
.map_err(|e| format!("spawning apply script: {e}"))?;
app.exit(0);
Ok(())
}
#[tauri::command]
fn pending_update(state: State<'_, AppState>) -> bool {
updates::has_pending_update(&state.app_dir)
}
#[tauri::command]
async fn download_ffmpeg(app: AppHandle, state: State<'_, AppState>) -> Result<(), String> {
let app_dir = state.app_dir.clone();
@@ -999,6 +1045,9 @@ pub fn run() {
get_config,
save_config,
download_ffmpeg,
download_update,
apply_update,
pending_update,
start_capture,
pause_capture,
resume_capture,