fix: 修复 Tauri GUI 环境下安装源检测错误

Tauri 进程 PATH 不含 /opt/homebrew/bin,导致 npm list 命令
静默失败,始终返回 official。改为优先检查 openclaw bin 的
symlink 指向判断安装源,npm list 作为 fallback。
This commit is contained in:
晴天
2026-02-28 13:27:09 +08:00
parent ef2c6dfb1b
commit da8932a3e0

View File

@@ -85,13 +85,21 @@ async fn get_latest_version_for(source: &str) -> Option<String> {
}
/// 检测当前安装的是官方版还是汉化版
/// 优先检查文件系统(不依赖 npm 命令的 PATHfallback 到 npm list
fn detect_installed_source() -> String {
let output = Command::new("npm")
// 方法1直接检查 openclaw bin 的 symlink 指向
if let Ok(target) = std::fs::read_link("/opt/homebrew/bin/openclaw") {
if target.to_string_lossy().contains("openclaw-zh") {
return "chinese".into();
}
return "official".into();
}
// 方法2fallback 到 npm list
if let Ok(o) = Command::new("npm")
.args(["list", "-g", "@qingchencloud/openclaw-zh", "--depth=0"])
.output();
if let Ok(o) = output {
let text = String::from_utf8_lossy(&o.stdout);
if text.contains("openclaw-zh@") {
.output()
{
if String::from_utf8_lossy(&o.stdout).contains("openclaw-zh@") {
return "chinese".into();
}
}