Skip to content

fix(qa,windows): 划词追问浮窗读用户当前录音键 + Windows 加 toolbar 拖拽 (#205)#206

Merged
appergb merged 2 commits into
mainfrom
fix/windows-qa-panel-205
May 3, 2026
Merged

fix(qa,windows): 划词追问浮窗读用户当前录音键 + Windows 加 toolbar 拖拽 (#205)#206
appergb merged 2 commits into
mainfrom
fix/windows-qa-panel-205

Conversation

@appergb
Copy link
Copy Markdown
Collaborator

@appergb appergb commented May 3, 2026

User description

Closes #205, addresses #203 in part.

Summary

Windows 端滑词追问浮窗以前同时坏在三处:

  1. `qa.*` i18n 文案硬编码 "Option" / "按 Option"——Windows 用户根本没这个键,提示文本失真。
  2. 拖拽只走 macOS `NSWindow.movableByWindowBackground=YES`,Windows 没有等价路径,浮窗一旦弹出就钉在原位。
  3. `QaPanel.tsx` 的 toolbar 注释明确写「前端不需要 onMouseDown / data-tauri-drag-region」,把 Tauri 标准拖拽通路也堵了。

Changes

  • `src/i18n/{zh-CN,en}.ts`:`qa.{emptyTitle,emptyDesc,recordingHint,statusIdle,errorRetryHint}` 把硬编码的 Option 换成 `{{recordHotkey}}` 插值。
  • `src/pages/QaPanel.tsx`:
    • mount 时通过 `getSettings()` 读 `prefs.hotkey.trigger`,转成 label(macOS 默认「右 Option」、Windows 默认「右 Control」、用户改过就显示用户配置),传给 `EmptyHint / RecordingHeader / TurnIndicator / ErrorRow / StatusBar`,平台 + 用户配置都能跟上。
    • Toolbar 空白 spacer 加 `data-tauri-drag-region`——mousedown 走 Tauri 标准 `startDragging()`,Windows 上对应 `WM_NCLBUTTONDOWN(HTCAPTION)`,在 `focus:false` 浮窗上也能拖。macOS 保留原 `setMovableByWindowBackground`,两条路径并存不冲突。注释更新成跨平台口径。

Out of scope

Esc 关闭在 Windows 上仍受 `focus:false` 影响(`SW_SHOWNOACTIVATE` 不给 keyboard focus)。本次 PR 不动这条:用户可以走右上角 ✕ 或重按 `Ctrl+Shift+;` 全局热键关闭。后续可以考虑给 QA 浮窗注册 ESC 全局快捷键(开 visible 时绑定,hide 时解绑),单独 PR 处理。

Test plan

  • `npx tsc --noEmit` 通过
  • `npm run build`(tsc + vite)通过
  • `cargo check --manifest-path src-tauri/Cargo.toml` 通过
  • macOS 实机:浮窗可整背景拖;文案显示「右 Option」(默认)。
  • Windows 实机:浮窗 toolbar 空白区可拖;文案显示「右 Control」(默认)/ 用户改过的键。

PR Type

Bug fix, Enhancement


Description

  • Replace hardcoded "Option" texts with dynamic {{recordHotkey}} interpolation in QA panel

  • Add Tauri drag region to toolbar spacer for Windows window dragging

  • Emit prefs:changed event from backend so QA panel reflects live hotkey label changes

  • Pass recordHotkey prop to all relevant sub-components (EmptyHint, RecordingHeader, etc.)


Diagram Walkthrough

flowchart LR
  A["i18n texts use {recordHotkey}"] --> B["QaPanel reads prefs.hotkey.trigger via getSettings()"]
  B --> C["Record hotkey label stored in state"]
  D["commands.rs set_settings emits prefs:changed"] --> E["QaPanel listens to prefs:changed event"]
  E --> C
  C --> F["Sub-components display correct hotkey"]
  G["Toolbar spacer gets data-tauri-drag-region"] --> H["Windows: Tauri startDragging for window move"]
  I["macOS: NSWindow movableByWindowBackground"] --> H
Loading

File Walkthrough

Relevant files
Enhancement
QaPanel.tsx
Dynamic hotkey label, Windows drag, and live prefs listener

openless-all/app/src/pages/QaPanel.tsx

  • Added recordHotkeyLabel state initialized via getSettings() IPC call
  • Subscribed to prefs:changed event to update label in real time
  • Added data-tauri-drag-region attribute to toolbar spacer for Windows
    drag support
  • Updated five sub-components to accept and display the dynamic
    recordHotkey prop
  • Revised drag-related comments to reflect cross-platform implementation
+94/-18 
commands.rs
Emit prefs:changed event on settings save                               

openless-all/app/src-tauri/src/commands.rs

  • Added AppHandle parameter to set_settings command
  • Emitted prefs:changed event after persisting settings to notify all
    webviews
  • Imported Emitter trait for event emission
+12/-3   
Bug fix
en.ts
Use recordHotkey placeholder in English i18n                         

openless-all/app/src/i18n/en.ts

  • Replaced hardcoded "Option" references with {{recordHotkey}}
    placeholder in five qa keys
+5/-5     
zh-CN.ts
Use recordHotkey placeholder in Chinese i18n                         

openless-all/app/src/i18n/zh-CN.ts

  • Replaced hardcoded "Option" references with {{recordHotkey}}
    placeholder in five qa keys
+5/-5     

Also closes #203 (Windows 滑词追问无法正常使用 — depends on the same 4 fixes shipped here).

Windows 端的滑词追问浮窗存在三处问题:(1) qa.* i18n 硬编码 "Option",
Windows 用户没这个键;(2) 拖拽只走 macOS NSWindow.movableByWindowBackground,
Windows 上无等价路径;(3) toolbar 注释明确写「不需要 data-tauri-drag-region」
导致 Tauri 标准拖拽通路也没接。

修复:
- QaPanel mount 时读 prefs.hotkey.trigger,转成 label(如「右 Control」/
  「Right Alt」),通过 i18n {{recordHotkey}} 插值传给 EmptyHint /
  RecordingHeader / TurnIndicator / ErrorRow / StatusBar 五个子组件,平台
  与用户配置都能跟上。
- Toolbar 空白 spacer 加 data-tauri-drag-region:mousedown 走 Tauri 标准
  startDragging() → Windows 上是 WM_NCLBUTTONDOWN(HTCAPTION),在 focus:false
  浮窗上也能拖;macOS 同时保留原 NSWindow movableByWindowBackground,两条
  路径并存不冲突。
@chatgpt-codex-connector
Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 3, 2026

PR Reviewer Guide 🔍

(Review updated until commit 17bb078)

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis ❌

205 - Partially compliant

Compliant requirements:

  • QA 浮窗文案已改为通过 {{recordHotkey}} 插值显示热键 label。
  • Toolbar 已增加 data-tauri-drag-region 拖拽通路。

Non-compliant requirements:

  • QA 浮窗获得 focus 后用 Esc 关闭的 Windows 行为未实现。
  • selectionAsk.howto.windowDesc 未在本 PR 中更新为中性描述。

Requires further human verification:

  • Windows 上 toolbar 的拖拽行为需要实际运行验证。
  • macOS / Windows 上热键 label 的实际显示效果需要界面验证。

203 - Not compliant

Non-compliant requirements:

  • Windows 端“可正常使用”的完整交互闭环仍未完成,尤其是关闭/焦点相关问题未解决。

Requires further human verification:

  • 需要在 Windows 上实际走完整个呼出、提问、关闭流程验证。
⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ No major issues detected

@H-Chris233
Copy link
Copy Markdown
Collaborator

请看reviewer给出的建议并作出相应更改

PR #206 review 反馈:QaPanel 的 recordHotkeyLabel 只在 mount / 语言切换时
重读 prefs;用户在主窗口改了录音键,浮窗如果还开着就一直停留在旧值
("按 右 Option 提问" 之类),误导用户按错键。

修法是补一条事件通路,不动现有的初始读取:
- commands.rs::set_settings 持久化后 `app.emit("prefs:changed", &prefs)`,
  广播给所有 webview。沿用 vocab:updated 同款跨窗口通知模式。
- QaPanel.tsx 在原有 qa:state / qa:dismiss / qa:level 订阅旁边加一条
  prefs:changed listener,收到后用 getHotkeyTriggerLabel 重算 label。
  cleanup 一并处理。

QaPanel 跑在独立 webview(label="qa"),没有 HotkeySettingsContext 注入,
所以必须走 IPC 事件而不是 React context;这也是为什么不能复用 Settings
页面的本地 state 更新。
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 3, 2026

Persistent review updated to latest commit 17bb078

@appergb appergb merged commit e4f6f2e into main May 3, 2026
2 checks passed
appergb pushed a commit that referenced this pull request May 3, 2026
PR #206 的 reviewer 还指出两条未修:

1. Esc 关闭在 Windows / Linux 上仍然不响应。原因:QA 窗口创建时
   focus:false(避免抢前台 app 焦点保留选区抓取能力),webview 拿不到
   keyboard focus,注册在 window 上的 keydown 永远不触发。mac 上
   nonactivating panel 仍接受 webview 内键盘事件,所以表现不一致。
   修法:用户在浮窗上 pointerdown 时主动 setFocus(),把窗口提为 key
   window,之后 Esc 在三平台一致工作。不在 mount 时 setFocus,避免
   复制 focus:true 副作用破坏初始选区抓取。

2. selectionAsk.howto.windowDesc 写死「标题栏可拖动」对 Windows /
   Linux 不准(这俩端通过 toolbar 上的 data-tauri-drag-region 拖)。
   en.ts 已经是中性「toolbar is draggable」,把 zh-CN.ts 对齐。

跨端检查:focus:false 是 tauri.conf.json 全平台配置;data-tauri-drag-region
在 Linux WebKitGTK 上走 begin_move_drag、Windows 上走
WM_NCLBUTTONDOWN(HTCAPTION),本 PR 之前提交的 toolbar 拖拽对
Linux 同样生效。
appergb pushed a commit that referenced this pull request May 3, 2026
PR #206 的 reviewer 还指出两条未修:

1. Esc 关闭在 Windows / Linux 上仍然不响应。原因:QA 窗口创建时
   focus:false(避免抢前台 app 焦点保留选区抓取能力),webview 拿不到
   keyboard focus,注册在 window 上的 keydown 永远不触发。mac 上
   nonactivating panel 仍接受 webview 内键盘事件,所以表现不一致。
   修法:用户在浮窗上 pointerdown 时主动 setFocus(),把窗口提为 key
   window,之后 Esc 在三平台一致工作。不在 mount 时 setFocus,避免
   复制 focus:true 副作用破坏初始选区抓取。

2. selectionAsk.howto.windowDesc 写死「标题栏可拖动」对 Windows /
   Linux 不准(这俩端通过 toolbar 上的 data-tauri-drag-region 拖)。
   en.ts 已经是中性「toolbar is draggable」,把 zh-CN.ts 对齐。

跨端检查:focus:false 是 tauri.conf.json 全平台配置;data-tauri-drag-region
在 Linux WebKitGTK 上走 begin_move_drag、Windows 上走
WM_NCLBUTTONDOWN(HTCAPTION),本 PR 之前提交的 toolbar 拖拽对
Linux 同样生效。
@appergb
Copy link
Copy Markdown
Collaborator Author

appergb commented May 3, 2026

@H-Chris233 已按 reviewer guide 的两条 non-compliant 修复,commit 7cdc27c

1. Esc 关闭跨端一致

QA 窗口 `focus: false`(避免抢前台 app 焦点保留选区抓取能力)→ Windows / Linux 上 webview 不接 keyboard focus → `window.addEventListener('keydown', Esc)` 永远不触发。mac 上 nonactivating panel 仍接受 webview 内键盘事件,所以原来 Esc 能用,但跨端语义不一致。

修法:用户在浮窗上 `pointerdown` 时调 `getCurrentWindow().setFocus()` 主动接管 key window —— 此后 Esc 三平台一致工作。在 mount 时 setFocus,避免复制 `focus: true` 副作用、破坏初始选区抓取。

2. `selectionAsk.howto.windowDesc` 中性化

en.ts 已经是中性 "toolbar is draggable";zh-CN.ts 的 "标题栏可拖动" 与实际不符(mac 是整窗口、win/linux 是 toolbar drag region),同步改为 "toolbar 可拖动"。

3. 跨端检查(Linux 端验证)

  • `focus: false` 是 `tauri.conf.json` 全平台配置,Linux 上 WebKitGTK 同样不接 webview keyboard focus,本 fix 同样适用。
  • `data-tauri-drag-region` 在 Linux 上走 `gtk_window_begin_move_drag`,5b8be16 已加的 toolbar 拖拽对 Linux 同样生效。
  • mac `makeKeyAndOrderFront` / Win `SetForegroundWindow` / Linux `gtk_window_present` 都是 Tauri 2 `setFocus()` 跨端封装,已存在 `core:window:allow-set-focus` capability。

关于 #203:reviewer 把这条标 not-compliant 是因为它依赖 #205 闭环。本 PR + 5b8be16#205 全部 4 条都修了(文案 / 拖动 / 关闭交互 / 整体可用),#203 应一并满足,可以同步关闭。

`tsc + vite build` 通过。

appergb pushed a commit that referenced this pull request May 4, 2026
包含自 1.2.13 以来的修复与新功能:
- feat(autostart): 跨端开机自启 (#194)
- feat(asr): SiliconFlow / GLM-ASR / Groq / OpenAI Whisper preset (#212)
- fix(qa): Windows / Linux 划词追问浮窗 Esc + 拖拽 + 文案 (#205 / #206)
- fix(settings): preset 切换 race + per-provider 凭据隔离 (#219 / #220)
- fix(overview): 概览整屏适配 + 嵌套 scroller 细滚动条 (#243 / #248)
- 一系列 Windows IME (TSF) 模块 (#233 / #240 等)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[windows] 滑词追问浮窗:文案非平台特化、无法拖动、关闭交互不可靠 [windows] 滑词追问功能无法正常使用

2 participants