fix: 优化升级进度条体验,每行日志递增进度并显示阶段提示

This commit is contained in:
晴天
2026-02-28 12:50:42 +08:00
parent 3fd98623c0
commit 434cc5eccd
2 changed files with 10 additions and 4 deletions

View File

@@ -158,17 +158,20 @@ pub async fn upgrade_openclaw(app: tauri::AppHandle, source: String) -> Result<S
.spawn()
.map_err(|e| format!("执行升级命令失败: {e}"))?;
// 读取 stderrnpm 主要输出在 stderr
let stderr = child.stderr.take();
let stdout = child.stdout.take();
let _ = app.emit("upgrade-progress", 30);
// stderr 每行递增进度10→80 区间),让用户看到进度在动
let app2 = app.clone();
let handle = std::thread::spawn(move || {
let mut progress: u32 = 15;
if let Some(pipe) = stderr {
for line in BufReader::new(pipe).lines().map_while(Result::ok) {
let _ = app2.emit("upgrade-log", &line);
if progress < 75 {
progress += 2;
let _ = app2.emit("upgrade-progress", progress);
}
}
}
});

View File

@@ -176,7 +176,10 @@ export function showUpgradeModal() {
},
setProgress(pct) {
fill.style.width = pct + '%'
text.textContent = pct >= 100 ? '完成' : `升级中... ${pct}%`
if (pct >= 100) text.textContent = '完成'
else if (pct >= 75) text.textContent = '正在安装...'
else if (pct >= 30) text.textContent = '正在下载依赖...'
else text.textContent = '准备中...'
},
setDone(msg) {
text.textContent = msg || '升级完成'