修复更新安装提权启动
通过 Windows UAC 启动 NSIS 静默安装 释放临时安装包句柄后再提交并启动 同步更新客户端升级技术方案
This commit is contained in:
@@ -57,6 +57,45 @@ struct AgcUpdateDownloadProgress {
|
||||
total_bytes: Option<u64>,
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
fn launch_agc_installer(path: &Path) -> Result<(), String> {
|
||||
use std::os::windows::process::CommandExt;
|
||||
|
||||
let executable = path.to_string_lossy().replace('\'', "''");
|
||||
let script = format!(
|
||||
"$ErrorActionPreference = 'Stop'; Start-Process -Verb RunAs -FilePath '{executable}' -ArgumentList @('/S')"
|
||||
);
|
||||
let status = Command::new("powershell.exe")
|
||||
.args([
|
||||
"-NoProfile",
|
||||
"-NonInteractive",
|
||||
"-WindowStyle",
|
||||
"Hidden",
|
||||
"-Command",
|
||||
script.as_str(),
|
||||
])
|
||||
.creation_flags(0x0800_0000)
|
||||
.status()
|
||||
.map_err(|error| format!("无法启动更新安装程序:{error}"))?;
|
||||
if status.success() {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(format!(
|
||||
"无法启动更新安装程序(exit code {:?})",
|
||||
status.code()
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(windows))]
|
||||
fn launch_agc_installer(path: &Path) -> Result<(), String> {
|
||||
Command::new(path)
|
||||
.arg("/S")
|
||||
.spawn()
|
||||
.map(|_| ())
|
||||
.map_err(|error| format!("无法启动更新安装程序:{error}"))
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
async fn download_agc_update(
|
||||
app: tauri::AppHandle,
|
||||
@@ -154,6 +193,7 @@ async fn download_agc_update(
|
||||
let _ = fs::remove_file(&temporary);
|
||||
return Err("保存更新文件失败".to_string());
|
||||
}
|
||||
drop(file);
|
||||
if let Some(expected_size) = expected_size {
|
||||
if downloaded_bytes != expected_size {
|
||||
let _ = fs::remove_file(&temporary);
|
||||
@@ -181,10 +221,7 @@ async fn download_agc_update(
|
||||
let _ = fs::remove_file(&temporary);
|
||||
return Err(format!("提交更新文件失败:{error}"));
|
||||
}
|
||||
Command::new(&target)
|
||||
.arg("/S")
|
||||
.spawn()
|
||||
.map_err(|_| "无法启动更新安装程序".to_string())?;
|
||||
launch_agc_installer(&target)?;
|
||||
app.exit(0);
|
||||
Ok(target.to_string_lossy().into_owned())
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ AGC 每次启动时由根窗口检查一次公开 OSS 更新清单。清单默
|
||||
}
|
||||
```
|
||||
|
||||
`downloadUrl` 必须是 HTTPS;如提供 `sha256` / `size`,Tauri 下载时会校验摘要和字节数。点击“下载更新”后,客户端将安装包流式写入系统临时目录并显示进度,校验成功后自动启动 NSIS 静默安装并退出旧客户端。
|
||||
`downloadUrl` 必须是 HTTPS;如提供 `sha256` / `size`,Tauri 下载时会校验摘要和字节数。点击“下载更新”后,客户端将安装包流式写入系统临时目录并显示进度,校验成功后通过 Windows UAC 提权启动 NSIS 静默安装并退出旧客户端。
|
||||
|
||||
## 启动与失败策略
|
||||
|
||||
|
||||
Reference in New Issue
Block a user