fix: make silent updater produce logs reliably and release 0.1.26
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "desktop-client",
|
||||
"private": true,
|
||||
"version": "0.1.25",
|
||||
"version": "0.1.26",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
2
desktop-client/src-tauri/Cargo.lock
generated
2
desktop-client/src-tauri/Cargo.lock
generated
@@ -693,7 +693,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "desktop-client"
|
||||
version = "0.1.25"
|
||||
version = "0.1.26"
|
||||
dependencies = [
|
||||
"reqwest 0.12.28",
|
||||
"rusqlite",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "desktop-client"
|
||||
version = "0.1.25"
|
||||
version = "0.1.26"
|
||||
description = "A Tauri App"
|
||||
authors = ["you"]
|
||||
edition = "2021"
|
||||
|
||||
@@ -1353,6 +1353,11 @@ fn api_silent_install_and_restart(installer_path: String) -> Result<BridgeRespon
|
||||
return Err("安装包路径无效".to_string());
|
||||
}
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
let windows_log_file_path: String;
|
||||
#[cfg(target_os = "windows")]
|
||||
let windows_script_file_path: String;
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
{
|
||||
let current_exe = env::current_exe().map_err(|err| format!("获取当前程序路径失败: {}", err))?;
|
||||
@@ -1365,10 +1370,19 @@ fn api_silent_install_and_restart(installer_path: String) -> Result<BridgeRespon
|
||||
.unwrap_or_default();
|
||||
let script_path = temp_dir.join(format!("silent-update-{}.cmd", script_stamp));
|
||||
let log_path = temp_dir.join(format!("silent-update-{}.log", script_stamp));
|
||||
windows_log_file_path = log_path.to_string_lossy().to_string();
|
||||
windows_script_file_path = script_path.to_string_lossy().to_string();
|
||||
|
||||
let installer_text = installer.to_string_lossy().replace('"', "\"\"");
|
||||
let app_text = current_exe.to_string_lossy().replace('"', "\"\"");
|
||||
let log_text = log_path.to_string_lossy().replace('"', "\"\"");
|
||||
let bootstrap_content = format!(
|
||||
"[bootstrap] silent updater prepared\r\npid={}\r\ninstaller={}\r\nscript={}\r\n",
|
||||
current_pid,
|
||||
installer.to_string_lossy(),
|
||||
script_path.to_string_lossy()
|
||||
);
|
||||
fs::write(&log_path, bootstrap_content).map_err(|err| format!("写入更新日志失败: {}", err))?;
|
||||
let script_content = format!(
|
||||
"@echo off\r\n\
|
||||
setlocal enableextensions\r\n\
|
||||
@@ -1377,7 +1391,10 @@ set \"APP_EXE={app_exe}\"\r\n\
|
||||
set \"APP_PID={app_pid}\"\r\n\
|
||||
set \"LOG_FILE={log_file}\"\r\n\
|
||||
echo [%%date%% %%time%%] update script started > \"%LOG_FILE%\"\r\n\
|
||||
if not exist \"%INSTALLER%\" exit /b 1\r\n\
|
||||
if not exist \"%INSTALLER%\" (\r\n\
|
||||
echo [%%date%% %%time%%] installer not found: %INSTALLER% >> \"%LOG_FILE%\"\r\n\
|
||||
exit /b 2\r\n\
|
||||
)\r\n\
|
||||
timeout /t 1 /nobreak >nul\r\n\
|
||||
taskkill /PID %APP_PID% /F >nul 2>nul\r\n\
|
||||
timeout /t 1 /nobreak >nul\r\n\
|
||||
@@ -1394,17 +1411,27 @@ del \"%~f0\" >nul 2>nul\r\n",
|
||||
log_file = log_text
|
||||
);
|
||||
fs::write(&script_path, script_content).map_err(|err| format!("写入更新脚本失败: {}", err))?;
|
||||
let script_arg = format!("\"{}\"", script_path.to_string_lossy());
|
||||
|
||||
let mut updater_cmd = Command::new("cmd");
|
||||
updater_cmd
|
||||
let spawn_result = updater_cmd
|
||||
.arg("/D")
|
||||
.arg("/C")
|
||||
.arg(&script_arg)
|
||||
.arg("call")
|
||||
.arg(&script_path)
|
||||
.current_dir(&temp_dir)
|
||||
.creation_flags(CREATE_NO_WINDOW)
|
||||
.spawn()
|
||||
.map_err(|err| format!("启动静默更新流程失败: {}", err))?;
|
||||
.spawn();
|
||||
if let Err(err) = spawn_result {
|
||||
let _ = fs::OpenOptions::new()
|
||||
.create(true)
|
||||
.append(true)
|
||||
.open(&log_path)
|
||||
.and_then(|mut file| {
|
||||
writeln!(file, "[bootstrap] failed to spawn updater cmd: {}", err)?;
|
||||
Ok(())
|
||||
});
|
||||
return Err(format!("启动静默更新流程失败: {}", err));
|
||||
}
|
||||
|
||||
let mut cleanup_entries: Vec<PathBuf> = fs::read_dir(&temp_dir)
|
||||
.ok()
|
||||
@@ -1459,6 +1486,14 @@ del \"%~f0\" >nul 2>nul\r\n",
|
||||
.to_string(),
|
||||
),
|
||||
);
|
||||
data.insert(
|
||||
"logFilePath".to_string(),
|
||||
Value::String(windows_log_file_path),
|
||||
);
|
||||
data.insert(
|
||||
"scriptPath".to_string(),
|
||||
Value::String(windows_script_file_path),
|
||||
);
|
||||
}
|
||||
|
||||
Ok(BridgeResponse {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"$schema": "https://schema.tauri.app/config/2",
|
||||
"productName": "玩玩云",
|
||||
"version": "0.1.25",
|
||||
"version": "0.1.26",
|
||||
"identifier": "cn.workyai.wanwancloud.desktop",
|
||||
"build": {
|
||||
"beforeDevCommand": "npm run dev",
|
||||
|
||||
@@ -153,7 +153,7 @@ const syncState = reactive({
|
||||
nextRunAt: "",
|
||||
});
|
||||
const updateState = reactive({
|
||||
currentVersion: "0.1.25",
|
||||
currentVersion: "0.1.26",
|
||||
latestVersion: "",
|
||||
available: false,
|
||||
mandatory: false,
|
||||
|
||||
Reference in New Issue
Block a user