Skip to content

fix(windows): drive global hotkeys from the configured bindings [CI staging] - #1

Open
kstorm12 wants to merge 7 commits into
mainfrom
fix/windows-configured-hotkeys
Open

kstorm12 wants to merge 7 commits into
mainfrom
fix/windows-configured-hotkeys

Conversation

@kstorm12

Copy link
Copy Markdown
Owner

Staging PR on the fork so the Windows workflow builds every push without needing upstream approval. Real review happens on desduvauchelle#1 — do not merge this one.

Verifies: cargo test --lib (includes the new shortcut_parts tests) + NSIS installer artifact echo-scribe-windows for on-machine testing of the Ctrl+Alt+Space collision case.

kstorm12 and others added 7 commits July 25, 2026 20:09
On Windows/Linux the hotkey listener in `input/hotkeys.rs` is a no-op stub
(the real implementation is a macOS CGEventTap), so the binding the Settings
UI writes was never read. Windows instead registered a hardcoded
Ctrl+Alt+Space, which meant the hotkey UI was inert and the actual trigger
was unchangeable.

That combination is also a popular one — Claude desktop's default, among
others — and Windows `RegisterHotKey` is first-come-first-served across
processes. When another app already owns it, registration failed, and since
the configured binding did nothing and there is no in-app record button,
there was no way at all to start dictation. The failure surfaced only as a
`tracing::warn!`, so the app looked healthy while doing nothing.

- `trigger::sync_shortcuts` now rebuilds every global shortcut from the four
  configured bindings. It is idempotent (unregisters first), runs at pipeline
  start, and re-runs after every rebind, so Settings works on Windows.
- Registration problems are returned as `HotkeyProblem { action, message }`,
  stored on `AppState`, and rendered by `HotkeyRebinder` next to the shortcut
  that caused them — a taken or unregistrable combination is now visible.
- `RegisterHotKey` cannot express a bare modifier, so the shipped macOS
  default (Right Control alone) is reported as unsupported rather than
  silently ignored. Left/right modifier sides are folded, as Windows has no
  notion of them.
- Add `tauri-plugin-single-instance`: a second launch previously started a
  second process that lost the hotkey race to the first and ended up equally
  dead. Focus the existing window instead.
- Fix `log_dir()`, which returned the macOS `~/Library/Logs` path on every
  platform, to use the local data dir off macOS.

Fixes desduvauchelle/tucky-landing#2

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Two Echo Scribe actions bound to the same combination is legal on macOS (the
CGEventTap just sees the same keys satisfy two bindings) but RegisterHotKey
rejects the second registration. That surfaced as the generic "another
application is probably already using that combination" message, sending the
user hunting for a conflict that is actually between two of our own hotkeys.

Observed on a real Windows run: voice-at-cursor and log-capture were both
Shift+T, and the failure carried the SAME HotKey id as the successful one.

Detect the collision before asking the OS and report which action holds the
combination. Modifier order is now canonicalised in shortcut_parts so two
bindings requiring the same modifiers compare equal.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
`focus::capture_selection` returned None off macOS, so the edit-selection
hotkey registered and then silently did nothing — the most confusing kind of
half-working feature.

macOS tries AXSelectedText first and falls back to a synthetic Cmd+C plus a
clipboard-delta read. That fallback is entirely platform-neutral apart from the
chord synthesis, so rather than duplicate it, `capture_selection_via_copy` is
now compiled on every platform and only `synthesize_cmd_c` is cfg-split —
mirroring how `synthesize_cmd_v` already had an enigo path for Windows.

Windows therefore reports SelectionMethod::Copy, which means the apply path
skips the AX write-back (unavailable anyway, `replace_selected_text` returns
-1) and goes through paste_at_cursor's Ctrl+V, replacing the live selection.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
All three executable voice actions shelled out to `Command::new("open")`, which
does not exist on Windows. Every one failed with:

  ERROR coordinator: Voice action execution failed; falling back to standard
        pipeline  error=execution failed: program not found

The LLM classified correctly and produced a valid ActionCommand — only the
execution line was macOS-only.

- draft_email and open_url now go through tauri-plugin-opener, which is
  cross-platform. Note this is not merely a substitute for `cmd /C start`:
  `start` treats the `&` between `?subject=` and `&body=` as a command
  separator, so the naive Windows port would silently truncate every email
  body. The opener plugin does not have that failure mode.
  (The JS half, @tauri-apps/plugin-opener, was already in package.json; only
  the Rust crate was missing.)
- launch_app has no cross-platform primitive (the opener plugin opens paths
  and URLs, not app names), so it stays cfg-split: `open -a` on macOS,
  `cmd /C start "" <name>` on Windows, explicit error elsewhere.

Also bundle tray_thinking.png / tray_thinking_dark.png. Both exist in
resources/ but were absent from tauri.conf.json's resources array, so the
"thinking" tray state failed to load on EVERY platform, not just Windows:

  WARN ui::tray: failed to load tray icon, falling back to solid
       resolved="...\resources\tray_thinking.png"

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
capture_selection_via_copy inferred "something was copied" by comparing the
clipboard before and after. That comparison is unsound when the pre-read fails,
because `before == None` makes ANY leftover clipboard content compare as
changed.

Observed on Windows: edit-selection captured `https://github.com/` — a URL
from an unrelated test minutes earlier — with chars=19 matching that string
exactly. The LLM echoed it back and the output sanitizer rejected it, so
nothing was pasted, but the selection editor had been handed text the user
never selected. Windows makes this easy to hit: the clipboard is a single
global resource that browsers and clipboard managers lock constantly, so a
transient read failure is routine rather than exotic.

Write a known sentinel before synthesizing the copy, then check whether it
survived. Because we author the pre-state, "nothing was copied" becomes
provable instead of inferred, and an unreadable clipboard can no longer be
mistaken for a selection. Restore is now unconditional, including on the
early-return paths, so a bail-out can't leave the probe marker in the
clipboard.

selection_from_clipboard_delta is kept (correct when the pre-read is known to
have succeeded) with a test documenting the unsoundness that motivated this.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Enabling the copy fallback off macOS leaked keystrokes into the user's
document. Reported and reproduced: holding Ctrl+Shift+S in Notepad played the
recording-start sound and then typed a stream of "S" into the file.

Cause: the coordinator captures the selection at hotkey-PRESS time, while the
trigger is still held. enigo's chord ends by RELEASING Ctrl, so the OS now sees
Ctrl as up; the still-held primary key keeps auto-repeating, no longer matches
the RegisterHotKey combination, Windows stops claiming it, and it goes to the
focused app.

macOS never had this: the CGEventTap swallows the primary key, and CGEvent sets
the Command flag on the event rather than pressing and releasing a real
modifier, so global modifier state is untouched.

No keystroke-based fix is safe. Re-pressing Ctrl still leaks whatever repeated
in the gap, and "Ctrl is already down, just send c" breaks when the binding also
holds Shift (Ctrl+Shift+C is not a copy). The correct implementation reads the
selection without synthesizing input: UI Automation TextPattern
(IUIAutomationTextPattern::GetSelection), the Win32 counterpart to
AXSelectedText.

capture_selection_via_copy itself is KEPT, including the sentinel-probe
soundness fix, which is a genuine improvement to the macOS path. Only the
non-macOS call site is withdrawn, with a warn! naming the real fix so this
reads as deliberate rather than unimplemented.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Edit-selection has never worked on Windows. capture_selection returned None
there, so every attempt aborted at the "select text first" hint:

  WARN edit: capture_selection: not supported on this platform yet
  INFO coordinator: edit selection: nothing selected; showing hint

That stub was deliberate. 9856d20 withdrew the synthetic Ctrl+C because the
coordinator captures at hotkey-PRESS time, while the trigger is still held:
enigo's chord ends by releasing Ctrl, the still-held primary key stops matching
the RegisterHotKey combination, and its auto-repeat lands in the user's
document. That commit named UI Automation TextPattern as the correct fix and
left it unimplemented. This implements it.

input/uia.rs reads the focused control's selection out of band —
GetFocusedElement -> GetCurrentPatternAs(UIA_TextPatternId) -> GetSelection().
No synthesized input, clipboard untouched, so none of the modifier-desync
failure modes apply. GetCurrentPatternAs rather than GetCurrentPattern: it
does the QueryInterface, so an element with no TextPattern surfaces as an Err
instead of a silently-null IUnknown.

The COM work runs on a throwaway thread behind a 600 ms deadline. The press
handler is on the hotkey's critical path, and a provider pumping a modal loop
must cost us the deadline and nothing more. Only the String crosses the thread
boundary, which is what keeps it sound given COM interfaces are !Send.

TextPattern is a per-control opt-in — Win32 edits, RichEdit, UWP, Office and
Chromium expose it, some custom-drawn editors do not. Every failure step logs a
distinct reason so an unsupported control reads as itself rather than as "no
selection".

Also instruments the trigger-word path, which is a separate reported failure
with no evidence in the log. Plain voice-at-cursor never logged its transcript,
so "the trigger word didn't match" and "the hotkey never fired" were
indistinguishable. The DB's items table shows the word absent from every
transcript ("Open Google.", "Make this more concise."), so the matcher had
nothing to match. The trigger word is spoken FIRST, which makes it exactly the
word microphone start-up latency clips, so log both halves: the compared prefix
(head=) on a miss, and press_to_capture_ms once the recorder is live.

Cargo.lock was already stale — tauri-plugin-opener, added to Cargo.toml in
4e545a7, was never recorded. Re-resolved; the diff is purely additive.

Not compiled locally: this machine has no MSVC toolchain, so cargo cannot link.
Every signature was verified against the vendored windows-0.58.0 source instead.
CI is the compiler.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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