diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 7ca1b2d..32126a0 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -401,6 +401,12 @@ fn main() { // sweep re-reads each strip tab's cookie so a profile switched // *inside* a tab (an SPA re-render) repaints its dot. Both are cheap // and only act on a real change. + // + // Disabled on Windows: periodic synchronous WebView2 URL/cookie/eval + // calls can re-enter WebView2's UI thread while voice-dictation + // tools inject text into a focused input and deadlock the host + // window. Session persistence remains event-driven on Windows. + #[cfg(not(target_os = "windows"))] { let sess_handle = handle.clone(); std::thread::spawn(move || loop { diff --git a/src-tauri/src/strip.rs b/src-tauri/src/strip.rs index a100364..16aa495 100644 --- a/src-tauri/src/strip.rs +++ b/src-tauri/src/strip.rs @@ -1283,52 +1283,65 @@ pub fn profile_from_cookies(cookies: &[Cookie<'static>]) -> Option { /// session (#18). Runs on a worker thread — the cookie read marshals via the /// dispatcher, so it must not be called from inside a wry callout (wry#583). fn capture_tab_profile(app: &AppHandle, window_label: &str, tab_label: &str) { - // Guard the cookie read at the CHOKEPOINT, not just at the periodic sweep - // (#33). `wv.cookies()` is a synchronous WebView2 read that marshals onto — - // and pumps a nested loop on — the main thread. While the strip's "⋯" popup - // owns the main thread (TrackPopupMenu modal loop), that re-entry deadlocks - // the UI. recapture_profiles guards itself, but capture_tab_profile is ALSO - // reached from the `route` bridge handler (recapture_tab_profile, fired by a - // background SSE-driven navigation) and on_page_load — both unguarded - // otherwise. Guarding here covers every caller; the value is re-read on the - // next route/sweep once the menu closes. - if app - .state::() - .menu_open - .load(std::sync::atomic::Ordering::SeqCst) + #[cfg(target_os = "windows")] { - return; + // WebView2 synchronous cookie reads can re-enter the UI thread and + // deadlock while accessibility/voice-dictation software is injecting + // text into a focused WebView. Skip the read on Windows; the existing + // menu_open chokepoint guard (#33) covered the popup case, this covers + // the AX-injection case. + let _ = (app, window_label, tab_label); } - let Some(win) = app.windows().get(window_label).cloned() else { - return; - }; - let Some(wv) = find_webview(&win, tab_label) else { - return; - }; - let profile = match wv.cookies() { - Ok(cs) => profile_from_cookies(&cs), - Err(e) => { - log::debug!("strip: profile read failed for {tab_label}: {e}"); + + #[cfg(not(target_os = "windows"))] + { + // Guard the cookie read at the CHOKEPOINT, not just at the periodic sweep + // (#33). `wv.cookies()` is a synchronous WebView2 read that marshals onto — + // and pumps a nested loop on — the main thread. While the strip's "⋯" popup + // owns the main thread (TrackPopupMenu modal loop), that re-entry deadlocks + // the UI. recapture_profiles guards itself, but capture_tab_profile is ALSO + // reached from the `route` bridge handler (recapture_tab_profile, fired by a + // background SSE-driven navigation) and on_page_load — both unguarded + // otherwise. Guarding here covers every caller; the value is re-read on the + // next route/sweep once the menu closes. + if app + .state::() + .menu_open + .load(std::sync::atomic::Ordering::SeqCst) + { return; } - }; - let changed = { - let state = app.state::(); - let mut strip = state.strip.lock().unwrap(); - match strip - .get_mut(window_label) - .and_then(|e| e.tabs.iter_mut().find(|t| t.label == tab_label)) - { - Some(tab) if tab.profile != profile => { - tab.profile = profile; - true + let Some(win) = app.windows().get(window_label).cloned() else { + return; + }; + let Some(wv) = find_webview(&win, tab_label) else { + return; + }; + let profile = match wv.cookies() { + Ok(cs) => profile_from_cookies(&cs), + Err(e) => { + log::debug!("strip: profile read failed for {tab_label}: {e}"); + return; } - _ => false, + }; + let changed = { + let state = app.state::(); + let mut strip = state.strip.lock().unwrap(); + match strip + .get_mut(window_label) + .and_then(|e| e.tabs.iter_mut().find(|t| t.label == tab_label)) + { + Some(tab) if tab.profile != profile => { + tab.profile = profile; + true + } + _ => false, + } + }; + if changed { + emit_tabs(app, window_label); + crate::session::persist(app); } - }; - if changed { - emit_tabs(app, window_label); - crate::session::persist(app); } } @@ -1339,6 +1352,7 @@ fn capture_tab_profile(app: &AppHandle, window_label: &str, tab_label: &str) { /// periodic sweep plus a re-capture on tab activation covers both without a /// WebUI signal. `capture_tab_profile` only emits when a value actually /// changed, so this is cheap. Runs on a worker thread (cookie reads marshal). +#[cfg(not(target_os = "windows"))] pub fn recapture_profiles(app: &AppHandle) { // Cookie reads marshal into each webview via the runtime dispatcher. If a // native menu modal loop is up (the strip's "⋯" popup), that marshal would