From 06e5e52ef0afa6792491fe9db92670615318b3d2 Mon Sep 17 00:00:00 2001 From: fylorn <249551762+fylorn@users.noreply.github.com> Date: Thu, 17 Sep 2026 18:36:46 +0800 Subject: [PATCH] fix(copy): rewrite the strings the Rust side shows in a written register MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #36 rewrote the .tsx copy as statements without first or second person, but part of what users read never passes through a .tsx file: command errors shown as toasts, the menu bar menu, tool-call notifications, the uninstall log in Settings and the update window. Those strings still used the spoken tone #36 removed ("连不上控制面 …。core 可能还没起来, 或者已经挂了。", "设置存不下来", "ThinkWatch ○ 没在跑", "可以把应用拖进 废纸篓了。"), so one screen could mix both registers. They now follow the same rules: 无法/未能/尚未 instead of 连不上/没/ …不了, 此 instead of 这个/这一份, 开机启动 as the Settings page names it, and 已是最新版本 as the update section already says. A few changes go beyond word choice: - The dev-build autostart error explained that registering would write target/debug into the plist. The doc comments already say that; the toast now only says dev builds do not support autostart. - Restarting a core that is not running showed the supervisor's Debug output ("core 现在是 Restarting { attempt: 2, in_ms: 4000 },…"). It now says whether core is still starting or not running. - The dev-only "twcore not found" message had nine spaces before its last line, left by a lost line continuation. - Uninstall log lines join client and result with 「:」, as #36 does on the clients page, instead of an em dash. - The control-plane connection error loses its closing 「。」. Commands format errors with {:#}, which appends ": " after it. Left as they are: tracing lines, errors that only reach a log (the heartbeat timeout, report_wedged), the --measure-memory output, and the strategy names core sends. Co-Authored-By: Claude Opus 5 --- src-tauri/src/control.rs | 6 ++--- src-tauri/src/lib.rs | 48 ++++++++++++++++++--------------- src-tauri/src/supervisor/mod.rs | 5 +++- 3 files changed, 34 insertions(+), 25 deletions(-) diff --git a/src-tauri/src/control.rs b/src-tauri/src/control.rs index 5ac255aa..77eb6d33 100644 --- a/src-tauri/src/control.rs +++ b/src-tauri/src/control.rs @@ -69,7 +69,7 @@ impl ControlClient { .await .with_context(|| { format!( - "连不上控制面 {}。core 可能还没起来,或者已经挂了。", + "无法连接控制面 {},core 可能尚未启动或已退出", self.socket.display() ) })?; @@ -113,7 +113,7 @@ impl ControlClient { // 人话的时候。 if s.api_version != tw_api::CONTROL_API_VERSION { anyhow::bail!( - "控制面协议版本对不上:core 是 {},界面认的是 {}。两边版本不一致,请重新构建。", + "控制面协议版本不一致:core 为 {},界面为 {}。请重新构建。", s.api_version, tw_api::CONTROL_API_VERSION ); @@ -142,7 +142,7 @@ impl ControlClient { .await .with_context(|| { format!( - "连不上控制面 {}。core 可能还没起来,或者已经挂了。", + "无法连接控制面 {},core 可能尚未启动或已退出", self.socket.display() ) })?; diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index b8b3603f..7486a9e3 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -88,7 +88,7 @@ pub fn locate_core(app: &tauri::AppHandle) -> anyhow::Result { return Ok(inside); } // **不往下走。**这里不是「再找找别处」,是这份安装包缺东西。 - anyhow::bail!("安装包里缺少 twcore 组件。请重新下载安装一次。"); + anyhow::bail!("安装包缺少 twcore 组件,请重新下载并安装。"); } let mut tried = Vec::new(); @@ -145,7 +145,8 @@ pub fn locate_core(app: &tauri::AppHandle) -> anyhow::Result { } anyhow::bail!( - "找不到 twcore。找过这些位置(以及 PATH):\n{}\n\n 用 THINKWATCH_CORE_BIN 指一个绝对路径,或者在 core 仓库里跑一次 \ + "未找到 twcore。已查找以下位置及 PATH:\n{}\n\n\ + 可通过 THINKWATCH_CORE_BIN 指定绝对路径,或在 core 仓库中执行 \ `cargo build -p twcore`。", tried .iter() @@ -495,13 +496,13 @@ async fn save_diagnostics(state: tauri::State<'_, AppState>) -> Result Result, String> { let mut log = Vec::new(); for r in restore_all(state).await? { - log.push(format!("{} — {}", r.client, r.detail)); + log.push(format!("{}:{}", r.client, r.detail)); } // 注销 LaunchAgent。**失败只记一句**:它不该挡住卸载,而留下一个 // 开机自启项的后果,用户在系统设置里看得见、也删得掉 use tauri_plugin_autostart::ManagerExt; match app.autolaunch().disable() { - Ok(_) => log.push("开机自启已注销".into()), - Err(e) => log.push(format!("开机自启没注销掉(去系统设置里删):{e}")), + Ok(_) => log.push("已取消开机启动".into()), + Err(e) => log.push(format!( + "未能取消开机启动({e})。请在「系统设置 › 通用 › 登录项」中关闭 ThinkWatch Lite。" + )), } if drop_data { let dir = data_dir(); match std::fs::remove_dir_all(&dir) { Ok(_) => log.push(format!("数据目录已删除:{}", dir.display())), Err(e) if e.kind() == std::io::ErrorKind::NotFound => {} - Err(e) => log.push(format!("数据目录没删掉:{}({e})", dir.display())), + Err(e) => log.push(format!("未能删除数据目录:{}({e})", dir.display())), } } else { - log.push(format!("数据留着没动:{}", data_dir().display())); + log.push(format!("数据目录已保留:{}", data_dir().display())); } - log.push("可以把应用拖进废纸篓了。".into()); + log.push("现可将应用移到废纸篓。".into()); Ok(log) } @@ -798,7 +801,7 @@ fn update_state(app: tauri::AppHandle) -> UpdateView { #[tauri::command] fn set_update_check(app: tauri::AppHandle, on: bool) -> Result { update::save_prefs(&data_dir(), &update::Prefs { check_updates: on }) - .map_err(|e| format!("设置存不下来:{e:#}"))?; + .map_err(|e| format!("无法保存设置:{e:#}"))?; Ok(update_view(&app)) } @@ -881,7 +884,7 @@ async fn find(app: &tauri::AppHandle) -> Result, String> { let current = app.package_info().version.to_string(); let cask = fetch_text(update::CASK_URL).await?; let Some(version) = update::cask_version(&cask) else { - return Err("cask 里读不出版本号".into()); + return Err("无法从 Homebrew cask 中读取版本号".into()); }; if !update::newer(version, ¤t) { return Ok(None); @@ -1067,13 +1070,16 @@ async fn update_install( if !install.can_self_update() { return Err(match install { update::Install::Homebrew => { - format!("这一份由 Homebrew 管理,请执行:{}", update::BREW_UPGRADE) + format!( + "此应用由 Homebrew 管理,请在终端中执行:{}", + update::BREW_UPGRADE + ) } _ => "开发构建不执行自动更新".into(), }); } if hub.installing.swap(true, Ordering::SeqCst) { - return Err("更新已经在进行中".into()); + return Err("更新正在进行中".into()); } // 中途失败要把标记放回去,否则再点一次会被当成「已经在进行中」 struct Release<'a>(&'a std::sync::atomic::AtomicBool); @@ -1090,7 +1096,7 @@ async fn update_install( .check() .await .map_err(|e| e.to_string())? - .ok_or_else(|| "已经是最新版本".to_string())?; + .ok_or_else(|| "已是最新版本".to_string())?; let _ = app.emit("update-step", Step::Downloading); let h = app.clone(); @@ -1177,7 +1183,7 @@ fn autostart_enabled(app: tauri::AppHandle) -> bool { #[tauri::command] fn set_autostart(app: tauri::AppHandle, on: bool) -> Result { if !autostart::allowed_in_this_build() { - return Err("开发构建里不注册开机自启 —— 它会把 target/debug 下的二进制写进 plist".into()); + return Err("开发构建不支持开机启动".into()); } use tauri_plugin_autostart::ManagerExt; // **插件不建目录。**它把 plist 直接写进 `~/Library/LaunchAgents/`, @@ -1191,7 +1197,7 @@ fn set_autostart(app: tauri::AppHandle, on: bool) -> Result { && let Some(plist) = autostart::plist_path(&app.config().identifier) && let Some(dir) = plist.parent() { - std::fs::create_dir_all(dir).map_err(|e| format!("建不了 {}:{e}", dir.display()))?; + std::fs::create_dir_all(dir).map_err(|e| format!("无法创建目录 {}:{e}", dir.display()))?; } let mgr = app.autolaunch(); let r = if on { mgr.enable() } else { mgr.disable() }; @@ -1602,19 +1608,19 @@ fn notify_if_dangerous(app: &tauri::AppHandle, ev: &tw_api::Event) { let title = if *blocked { format!("已拦截 {provider} 返回的 {tool} 调用") } else { - format!("{provider} 返回了一个可疑的 {tool} 调用") + format!("{provider} 返回了可疑的 {tool} 调用") }; let body = if *blocked { format!( "{why} {excerpt} -这个上游标记为不受信任,响应流已切断。" +此上游标记为不受信任,响应流已切断。" ) } else { format!( "{why} {excerpt} -建议拒绝这个调用。" +建议拒绝此调用。" ) }; let _ = app.notification().builder().title(title).body(body).show(); @@ -1861,7 +1867,7 @@ fn build_tray_menu(app: &tauri::AppHandle, f: &TrayFacts) -> tauri::Result anyhow::Result<()> { let pid = match self.state() { CoreState::Running { pid } => pid, - other => anyhow::bail!("core 现在是 {other:?},没在跑,不用重启"), + CoreState::Starting | CoreState::Restarting { .. } => { + anyhow::bail!("core 正在启动,请稍后再试") + } + CoreState::SafeMode | CoreState::Stopped => anyhow::bail!("core 未运行,无法重启"), }; self.intentional.store(true, Ordering::SeqCst); // SIGTERM 而不是 SIGKILL:给它机会把 socket 和 lock 文件清掉。