From 1d64fdcce7e08aac8033541213fbc68c7201d4a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=99=B4=E5=A4=A9?= Date: Sat, 28 Feb 2026 14:31:10 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BB=8E=20package.json=20=E8=AF=BB?= =?UTF-8?q?=E5=8F=96=E5=AE=8C=E6=95=B4=E7=89=88=E6=9C=AC=E5=8F=B7=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E6=B1=89=E5=8C=96=E7=89=88=E6=9B=B4=E6=96=B0=E8=AF=AF?= =?UTF-8?q?=E6=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 汉化版 CLI --version 输出不含 -zh.X 后缀,导致永远提示有更新。 改为从 npm 包 package.json 读取完整版本号。 --- src-tauri/src/commands/config.rs | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src-tauri/src/commands/config.rs b/src-tauri/src/commands/config.rs index 33ea39c..349e87d 100644 --- a/src-tauri/src/commands/config.rs +++ b/src-tauri/src/commands/config.rs @@ -74,19 +74,27 @@ pub fn write_mcp_config(config: Value) -> Result<(), String> { } /// 获取本地安装的 openclaw 版本号 +/// 优先从 npm 包的 package.json 读取(含完整后缀),fallback 到 CLI fn get_local_version() -> Option { - let output = Command::new("openclaw") - .arg("--version") - .output() - .ok()?; + // 通过 symlink 找到包目录,读 package.json 的 version + if let Ok(target) = fs::read_link("/opt/homebrew/bin/openclaw") { + let pkg_json = PathBuf::from("/opt/homebrew/bin") + .join(&target) + .parent()? + .join("package.json"); + if let Ok(content) = fs::read_to_string(&pkg_json) { + if let Some(ver) = serde_json::from_str::(&content) + .ok() + .and_then(|v| v.get("version")?.as_str().map(String::from)) + { + return Some(ver); + } + } + } + // fallback: CLI 输出 + let output = Command::new("openclaw").arg("--version").output().ok()?; let raw = String::from_utf8_lossy(&output.stdout).trim().to_string(); - // 格式可能是 "openclaw 2026.2.23" 或纯版本号 - let version = raw - .split_whitespace() - .last() - .filter(|s| !s.is_empty()) - .map(String::from)?; - Some(version) + raw.split_whitespace().last().filter(|s| !s.is_empty()).map(String::from) } /// 从 npm registry 获取最新版本号,超时 5 秒