Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions docs/WINDOWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ calendar matching can then be added back with Windows-native implementations.
Minimum porting checklist:

1. Move macOS-only dependencies behind `cfg(target_os = "macos")`.
2. Add Windows equivalents or feature fallbacks for global hotkeys, focus context,
microphone permission UX, meeting audio capture, screen recording, calendar
lookup, and credential storage.
2. Add Windows equivalents or feature fallbacks for focus context, microphone
permission UX, meeting audio capture, screen recording, calendar lookup, and
credential storage. (Global hotkeys are done — see "Hotkeys on Windows" below.)
3. Replace the unconditional Metal LLM build with a Windows-compatible llama.cpp
backend, likely CPU first, then optional CUDA/Vulkan later.
4. Add Windows sidecar binaries or disable the features that require the current
Expand All @@ -51,6 +51,26 @@ Minimum porting checklist:
6. Publish a Windows installer from Tauri, typically an NSIS `*-setup.exe` or an
MSI package.

## Hotkeys on Windows

Windows has no CGEventTap, so the configured bindings are registered with the
global-shortcut plugin (`RegisterHotKey`) instead of the macOS event tap. Two
consequences the UI has to live with:

- **A shortcut must contain a regular key.** `RegisterHotKey` cannot register a
bare modifier, so the macOS default (Right Control on its own) is not
expressible. Settings reports this rather than silently doing nothing.
- **Left/right modifiers are not distinguished.** "Right Alt + Slash" registers
as "Alt + Slash".
- **Registration is first-come-first-served across the whole system.** If another
running application already owns the combination, registration fails and Echo
Scribe surfaces the problem in Settings next to that shortcut.

Because a second instance of the app would lose that race against the first and
end up with no working hotkey at all, the app registers
`tauri-plugin-single-instance` and focuses the existing window instead of
starting a second process.

## Validation commands for a Windows developer

On a Windows development machine:
Expand Down
2 changes: 2 additions & 0 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ tauri-plugin-store = "2"
tauri-plugin-autostart = "2"
tauri-plugin-notification = "2"
tauri-plugin-global-shortcut = "2"
# Keeps a second launch from stealing/losing the global hotkey registration.
tauri-plugin-single-instance = "2"
# ASR / Parakeet via ONNX Runtime. CPU-only — `ort-coreml` was dropped after
# logs showed CoreML accepted only 15/39 encoder ops and 4/35 decoder ops, and
# spent ~50s on first-run graph compilation while still running most of the
Expand Down
112 changes: 81 additions & 31 deletions src-tauri/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ use crate::input::binding::{
code_from_key, key_from_code, Binding, ModifierKind, ModifierSide, SerKey,
};
use crate::input::hotkeys::{spawn_listener, HotkeyEvent};
use crate::input::trigger::HotkeyProblem;
use crate::llm::{self, rag, GenerateRequest, Llm, LlmDownloadProgress, LlmModelEntry};
use crate::permissions::{self, CameraAccessOutcome, MicAccessOutcome, PermissionsStatus, SettingsPane};
use crate::settings::SettingsStore;
Expand Down Expand Up @@ -62,6 +63,12 @@ pub struct AppState {
pub action_binding: Arc<RwLock<Binding>>,
pub edit_selection_binding: Arc<RwLock<Binding>>,
pub hotkey_started: AtomicBool,
/// Friendly, user-facing reasons the configured hotkeys couldn't be
/// registered (Windows/Linux only — macOS uses the event tap and never
/// registers anything). Refreshed on every `sync_hotkeys` call and read by
/// the settings UI via [`get_hotkey_problems`], so a shortcut that another
/// app already owns shows up in the UI instead of only in the log.
pub hotkey_problems: Arc<RwLock<Vec<HotkeyProblem>>>,
/// When `true`, the coordinator drops Pressed/Released events. Toggled
/// from the tray menu (Pause/Resume hotkeys). The hotkey listeners stay
/// running so the toggle is instant — only the coordinator filters.
Expand Down Expand Up @@ -344,6 +351,36 @@ pub fn request_screen_recording_access() -> Result<bool, String> {
Ok(granted)
}

/// Re-register the global shortcuts from the current bindings and store any
/// user-facing problems for [`get_hotkey_problems`].
///
/// No-op on macOS, where the CGEventTap listeners read the shared `Binding`
/// directly on every key event and so pick up rebinds with nothing to re-register.
pub fn sync_hotkeys(state: &AppState, app: &AppHandle) {
#[cfg(not(target_os = "macos"))]
{
let problems = crate::input::trigger::sync_shortcuts(app, state);
if let Ok(mut guard) = state.hotkey_problems.write() {
*guard = problems;
}
}
#[cfg(target_os = "macos")]
{
let _ = (state, app);
}
}

/// Hotkeys that could not be registered (empty on macOS, and empty on
/// Windows/Linux when everything registered cleanly).
#[tauri::command]
pub fn get_hotkey_problems(state: State<'_, AppState>) -> Vec<HotkeyProblem> {
state
.hotkey_problems
.read()
.map(|g| g.clone())
.unwrap_or_default()
}

#[tauri::command]
pub fn get_voice_at_cursor_binding(state: State<'_, AppState>) -> JsBinding {
let b = state
Expand All @@ -357,6 +394,7 @@ pub fn get_voice_at_cursor_binding(state: State<'_, AppState>) -> JsBinding {
#[tauri::command]
pub fn update_voice_at_cursor_binding(
state: State<'_, AppState>,
app: AppHandle,
binding: JsBinding,
) -> Result<(), String> {
let parsed: Binding = binding
Expand All @@ -366,11 +404,14 @@ pub fn update_voice_at_cursor_binding(
.settings
.set_voice_at_cursor_binding(parsed.clone())
.map_err(|e| e.to_string())?;
let mut guard = state
.binding
.write()
.map_err(|_| "binding lock poisoned".to_string())?;
*guard = parsed;
{
let mut guard = state
.binding
.write()
.map_err(|_| "binding lock poisoned".to_string())?;
*guard = parsed;
}
sync_hotkeys(&state, &app);
Ok(())
}

Expand All @@ -387,6 +428,7 @@ pub fn get_log_capture_binding(state: State<'_, AppState>) -> JsBinding {
#[tauri::command]
pub fn update_log_capture_binding(
state: State<'_, AppState>,
app: AppHandle,
binding: JsBinding,
) -> Result<(), String> {
let parsed: Binding = binding
Expand All @@ -396,11 +438,14 @@ pub fn update_log_capture_binding(
.settings
.set_log_capture_binding(parsed.clone())
.map_err(|e| e.to_string())?;
let mut guard = state
.log_capture_binding
.write()
.map_err(|_| "binding lock poisoned".to_string())?;
*guard = parsed;
{
let mut guard = state
.log_capture_binding
.write()
.map_err(|_| "binding lock poisoned".to_string())?;
*guard = parsed;
}
sync_hotkeys(&state, &app);
Ok(())
}

Expand All @@ -415,19 +460,26 @@ pub fn get_action_binding(state: State<'_, AppState>) -> JsBinding {
}

#[tauri::command]
pub fn update_action_binding(state: State<'_, AppState>, binding: JsBinding) -> Result<(), String> {
pub fn update_action_binding(
state: State<'_, AppState>,
app: AppHandle,
binding: JsBinding,
) -> Result<(), String> {
let parsed: Binding = binding
.try_into()
.map_err(|e: BindingConversionError| e.to_string())?;
state
.settings
.set_action_binding(parsed.clone())
.map_err(|e| e.to_string())?;
let mut guard = state
.action_binding
.write()
.map_err(|_| "action_binding lock poisoned".to_string())?;
*guard = parsed;
{
let mut guard = state
.action_binding
.write()
.map_err(|_| "action_binding lock poisoned".to_string())?;
*guard = parsed;
}
sync_hotkeys(&state, &app);
Ok(())
}

Expand All @@ -444,6 +496,7 @@ pub fn get_edit_selection_binding(state: State<'_, AppState>) -> JsBinding {
#[tauri::command]
pub fn update_edit_selection_binding(
state: State<'_, AppState>,
app: AppHandle,
binding: JsBinding,
) -> Result<(), String> {
let parsed: Binding = binding
Expand All @@ -453,11 +506,14 @@ pub fn update_edit_selection_binding(
.settings
.set_edit_selection_binding(parsed.clone())
.map_err(|e| e.to_string())?;
let mut guard = state
.edit_selection_binding
.write()
.map_err(|_| "edit_selection_binding lock poisoned".to_string())?;
*guard = parsed;
{
let mut guard = state
.edit_selection_binding
.write()
.map_err(|_| "edit_selection_binding lock poisoned".to_string())?;
*guard = parsed;
}
sync_hotkeys(&state, &app);
Ok(())
}

Expand Down Expand Up @@ -705,16 +761,10 @@ pub fn ensure_pipeline_started(state: &AppState, app: &AppHandle) {
spawn_listener(Arc::clone(&state.edit_selection_binding), es_tx, Arc::clone(&state.rebinding));

// macOS drives the coordinator from the CGEventTap listeners above.
// Non-macOS has no tap, so register the global-shortcut trigger.
#[cfg(not(target_os = "macos"))]
{
if let Err(e) = crate::input::trigger::register_default_dictation_shortcut(
app,
coord_tx.clone(),
) {
tracing::warn!(target: "trigger", %e, "dictation hotkey unavailable");
}
}
// Non-macOS has no tap, so register the configured bindings as global
// shortcuts. Must run after `coord_tx` is stored in state — the shortcut
// handlers forward into that channel.
sync_hotkeys(state, app);

// Adapter tasks: tag + forward into the coordinator channel. We use
// `tokio::spawn` rather than a dedicated thread because these are pure
Expand Down
11 changes: 11 additions & 0 deletions src-tauri/src/input/focus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,19 @@ pub fn capture_selection(element: Option<&FocusElement>) -> Option<SelectionSnap
None
}

/// Capture the current text selection without Accessibility.
///
/// Windows/Linux have no `AXSelectedText` equivalent wired up (the `FocusElement`
/// stubs return `None`), so the synthetic-copy + clipboard-delta path is the only
/// one available — and it is enough to make the edit-selection hotkey functional
/// rather than registering and then silently doing nothing.
#[cfg(not(target_os = "macos"))]
pub fn capture_selection(_element: Option<&FocusElement>) -> Option<SelectionSnapshot> {
if let Some(text) = crate::input::paste::capture_selection_via_copy() {
tracing::info!(target: "edit", chars = text.len(), "capture_selection: via Ctrl+C fallback");
return Some(SelectionSnapshot { text, method: SelectionMethod::Copy });
}
tracing::info!(target: "edit", "capture_selection: no selection found (clipboard unchanged)");
None
}

Expand Down
34 changes: 26 additions & 8 deletions src-tauri/src/input/paste.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,13 @@ pub fn selection_from_clipboard_delta(before: Option<&str>, after: Option<&str>)
}
}

/// Fallback selection capture: synthesize Cmd+C, read the clipboard, then
/// restore the user's original clipboard. Returns the selected text, or `None`
/// if nothing changed / the copy failed. macOS-only.
#[cfg(target_os = "macos")]
/// Fallback selection capture: synthesize the platform copy chord, read the
/// clipboard, then restore the user's original clipboard. Returns the selected
/// text, or `None` if nothing changed / the copy failed.
///
/// Platform-neutral: only [`synthesize_cmd_c`] differs per OS (CoreGraphics on
/// macOS, enigo elsewhere). On Windows this is the *only* selection path, since
/// the AX-based `focus::capture_selection` has no Win32 equivalent yet.
pub fn capture_selection_via_copy() -> Option<String> {
use arboard::Clipboard;
let mut clipboard = match Clipboard::new() {
Expand Down Expand Up @@ -170,10 +173,6 @@ pub fn capture_selection_via_copy() -> Option<String> {
result
}

#[cfg(not(target_os = "macos"))]
pub fn capture_selection_via_copy() -> Option<String> {
None
}

/// Synthesize Cmd+C via CoreGraphics (same deterministic approach as
/// [`synthesize_cmd_v`], with the Command flag set directly on the keydown).
Expand All @@ -200,6 +199,25 @@ fn synthesize_cmd_c() -> Result<(), PasteError> {
Ok(())
}

/// Synthesize Ctrl+C. Mirrors [`synthesize_cmd_v`]'s non-macOS enigo path so
/// the two chords behave identically on Windows/Linux.
#[cfg(not(target_os = "macos"))]
fn synthesize_cmd_c() -> Result<(), PasteError> {
use enigo::{Direction, Enigo, Key, Keyboard, Settings};
let mut enigo =
Enigo::new(&Settings::default()).map_err(|e| PasteError::Init(e.to_string()))?;
enigo
.key(Key::Control, Direction::Press)
.map_err(|e| PasteError::Keystroke(e.to_string()))?;
enigo
.key(Key::Unicode('c'), Direction::Click)
.map_err(|e| PasteError::Keystroke(e.to_string()))?;
enigo
.key(Key::Control, Direction::Release)
.map_err(|e| PasteError::Keystroke(e.to_string()))?;
Ok(())
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
Loading
Loading