Skip to content

feat: 翻译模式 + Codex 后审修复 + 胶囊翻译指示器#113

Merged
appergb merged 1 commit into
mainfrom
fix/translation-mode-and-codex-fixes
May 1, 2026
Merged

feat: 翻译模式 + Codex 后审修复 + 胶囊翻译指示器#113
appergb merged 1 commit into
mainfrom
fix/translation-mode-and-codex-fixes

Conversation

@appergb
Copy link
Copy Markdown
Collaborator

@appergb appergb commented May 1, 2026

主要变更

翻译模式(issue #4

录音过程中任意时刻按一下 Shift(任一侧)→ 录音结束走"翻译输出"管线,把转写翻译为用户在新「翻译」页选定的目标语言,再插入到光标位置。

前端

  • 新一级 tab pages/Translation.tsx(在「风格」下方,图标是 stroke 翻译符号)
  • 工作语言多选(药丸样式,15 个内置自然语言原生名)
  • 翻译目标语言下拉(首项「不启用」= Shift 无效)
  • 完整使用指南:5 步触发流程 + 「正在翻译」指示器说明 + 安全兜底说明
  • 胶囊上"● 正在翻译"蓝色药丸:绝对定位 pill 上方 8px,opacity + translateY transition 平滑出入;capsule 窗口高度 96 → 110

后端

  • hotkey.rs 三平台(CGEventTap / Win32 hook / rdev)监听 Shift down 边沿,新事件 HotkeyEvent::TranslationModifierPressed
  • coordinator.rs::Innertranslation_modifier_seen: AtomicBoolbegin_session 重置;end_session 据此 + translation_target_language 选 polish 还是 translate
  • polish.rschat_completion(system_prompt, user_prompt) 共享方法;新 translate_to 走同通道;working_languages_premise 把"用户的工作语言:…"拼到 system prompt 头部,影响 polish + translate
  • UserPreferencesworking_languages: Vec<String>(默认 ["简体中文"])+ translation_target_language: String
  • CapsulePayloadtranslation: boolemit_capsule 自动带

Codex 后审修复(基于 main = 4f45dee 的整体审查)

  • decorations on macOSfix(windows): polish capsule and custom titlebar shell #108tauri.conf.json 主窗口 decorations 设为 false,连带把 macOS 原生红黄绿按钮关掉。还原为 true,Windows-only 在 lib.rs::setup 里 runtime set_decorations(false)
  • stale recorder error monitorSessionStatesession_id: u64begin_session 自增;spawn_recorder_error_monitor 捕获当前 id,处理时若 id 已变直接 drop(之前旧 session 的迟到 cpal 错误会误中止新 session)
  • Volcengine seq race(深度修复):之前 fix 仅在单次 consume_pcm_chunk 内部生效,跨调用仍可能 race。改成单 mpsc worker 串行 send 模式:consume_pcm_chunk 在 state 锁内分配 seq + 入队;open_session spawn 唯一 worker FIFO recv 后 send_binary。session 结束时 take audio_tx,worker 自然退出

附带修复

  • clipboard 还原 toggle(issue Windows/Linux 插入失败时听写文本丢失:增加'插入失败保留剪贴板'开关 #111insertion.rs Windows/Linux 路径加 restore_clipboard_after_paste: bool 开关,默认 true 保现行;关掉则听写文本留剪贴板,simulate_paste 没生效时用户能手动 Ctrl+V 找回
  • Settings modal 滚动:内容区 overflow:hidden + flex column,X 按钮 + section 标题固定不滚;嵌入 Settings 的右栏独立 overflow:auto
  • App Key → App ID:火山引擎凭据 UI 文案改名(keychain account volcengine.app_key 保持不变,老用户凭据不丢)
  • i18n:加 capsule.translating / nav.translation / 完整 translation.* 命名空间,删 settings.recording.workingLanguages* / translationTarget*

Files

19 changed, +776 / -88

Test plan

  • macOS:连按 5-10 次开停录音,无 error frame code=45000000 日志,volcengine.log 无 seq mismatch
  • 录音中按 Shift → 胶囊 pill 上方 8px 出现"● 正在翻译",pill 不挪窝
  • 翻译目标选 English,说一段中文后按 Shift → 输出英文
  • 翻译目标留空 → Shift 无效,正常润色
  • 主窗口红黄绿可点击关闭
  • Settings 弹窗滚动:X + 标题固定,section 右栏独立滚
  • 设置 → 提供商 → 火山引擎 → 字段名是"App ID"

翻译模式(issue #4)
  按住录音键时随时按一下 Shift(任一侧)→ 录音结束后走"翻译输出"管线,
  按"翻译"页中选定的目标语言翻译后插入到光标。
  - hotkey.rs 三平台(CGEventTap / Win32 hook / rdev)都监听 Shift down 边沿,
    通过新增的 HotkeyEvent::TranslationModifierPressed 上报
  - coordinator.rs 加 translation_modifier_seen 标志位(begin_session 重置);
    end_session 路径根据它 + 非空 target_language 选 polish 或 translate
  - polish.rs 抽 chat_completion 共享通道;新增 translate_to + translate_system_prompt;
    working_languages 作为 system prompt 头部前提注入两条管线
  - types.rs::UserPreferences 加 working_languages(默认 ["简体中文"])+
    translation_target_language(默认空)
  - Settings.tsx 删除原来的录音 section 翻译配置;新建 Translation.tsx 一级页(在风格下面),
    含工作语言多选 + 目标语言下拉 + 5 步使用指南
  - 新增 capsule.tsx 翻译徽章:"● 正在翻译" 蓝色药丸,绝对定位在 pill 上方 8px,
    opacity + translateY transition 平滑出入;CapsulePayload 加 translation: bool
  - capsule 窗口高度 96 → 110 给 badge 让出空间
  - 内置 SUPPORTED_LANGUAGES 列表(15 种自然语言原生名)

Codex 后审修复(基于 4f45dee main 上跑的整体审查)
  - tauri.conf.json 主窗口 decorations 由 #108 设的 false 还原为 true,
    Windows-only 在 lib.rs::setup 里 set_decorations(false),让 macOS 拿回原生红黄绿
  - coordinator.rs::SessionState 加 session_id;spawn_recorder_error_monitor
    捕获当前 id,迟到的 cpal 错误若 id 不匹配直接 drop,不会误中止后续 session
  - volcengine.rs 把 spawn-per-chunk 模式改成单 mpsc worker 串行 send,
    彻底消除跨 consume 调用的 writer 锁 race(之前的 fix 仅在 burst flush 内部有效)

附带修复
  - insertion.rs Windows/Linux 粘贴后剪贴板恢复加用户开关 restore_clipboard_after_paste
    (issue #111),默认 true 保留现行行为;关掉后听写文本留剪贴板,paste 失败时可手动 Ctrl+V 找回
  - SettingsModal 内容区改为 flex column + overflow:hidden,X 按钮 + 标题固定,
    只 section 内容区滚动;Settings.tsx 嵌入模式右栏独立 scroll
  - Settings → 提供商:火山引擎 "App Key" 文案改为 "App ID"
    (keychain account name 不变,老用户凭据不丢)
  - i18n 增加 capsule.translating / nav.translation / translation.* 完整命名空间
Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @appergb, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bf335da697

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

"title": "OpenLess Capsule",
"width": 220,
"height": 96,
"height": 110,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep capsule position in sync with new window height

After increasing the capsule window height to 110 in tauri.conf.json, the positioning logic still uses cap_h = 96.0 in position_capsule_bottom_center (src-tauri/src/lib.rs). On startup this computes y too low, so the capsule can sit ~14px lower than intended (partially clipped on smaller displays and inconsistent with the new layout). Please update the runtime position calculation to use the same height as config.

Useful? React with 👍 / 👎.

elapsed_ms,
message,
inserted_chars,
translation: inner.translation_modifier_seen.load(Ordering::SeqCst),
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Gate translation badge on enabled translation target

The capsule translation flag is emitted from translation_modifier_seen alone, but actual translation execution also requires a non-empty translation_target_language in end_session. This means when target is disabled (documented as “Shift does nothing”), pressing Shift still shows the blue “Translating” indicator even though the session will run normal polish. Please derive the emitted badge flag from the same predicate as the translation pipeline to avoid misleading status.

Useful? React with 👍 / 👎.

@appergb appergb merged commit b7e934a into main May 1, 2026
2 checks passed
@appergb appergb deleted the fix/translation-mode-and-codex-fixes branch May 1, 2026 02:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant