A free, open source, and extensible speech-to-text application that works completely offline.
fix: disable WebView2 browser accelerator keys in the main window (#2060)
CJ Paisbf8756c3a88a
diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lockindex 8839379d..ce98ffe0 100644--- a/src-tauri/Cargo.lock+++ b/src-tauri/Cargo.lock@@ -2566,6 +2566,7 @@ dependencies = ["transcribe-cpp","transcribe-rs","vad-rs",+ "webview2-com","whatlang","windows 0.61.3","winreg 0.55.0",diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.tomlindex 81589ee2..a65b9c00 100644--- a/src-tauri/Cargo.toml+++ b/src-tauri/Cargo.toml@@ -101,6 +101,10 @@ tauri-plugin-single-instance = "2.3.2"tauri-plugin-updater = "2.10.1"[target.'cfg(windows)'.dependencies]+# Used to reach ICoreWebView2Settings3 through the webview's controller+# (disabling browser accelerator keys in the main window). Must match the+# version wry links against so the COM types are identical.+webview2-com = "0.38"# ONNX Runtime on Windows is CPU-only (no ort-directml), matching macOS/Linux.# The DirectML EP was experimental and, more importantly, pulled in pyke's# prebuilt ONNX Runtime which is compiled with a global /arch:AVX2 baseline thatdiff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rsindex 8677ae3a..facc9786 100644--- a/src-tauri/src/lib.rs+++ b/src-tauri/src/lib.rs@@ -953,7 +953,33 @@ pub fn run(cli_args: CliArgs) {win_builder = win_builder.data_directory(data_dir.join("webview"));}- win_builder.build()?;+ // Only used on Windows, to disable WebView2 browser accelerators.+ #[cfg_attr(not(target_os = "windows"), allow(unused_variables))]+ let main_window = win_builder.build()?;++ // Disable WebView2 browser accelerators (F5, F6, Ctrl+F, F12, ...).+ // A settings window has no use for them, and pressing F6 while+ // recording a shortcut was reported to turn the whole window white+ // (cjpais/Handy#1940), likely by triggering WebView2 focus cycling.+ // DevTools stays enabled; only the F12 accelerator is lost.+ #[cfg(target_os = "windows")]+ {+ let _ = main_window.with_webview(|webview| unsafe {+ use webview2_com::Microsoft::Web::WebView2::Win32::ICoreWebView2Settings3;+ use windows::core::Interface;++ let result = webview+ .controller()+ .CoreWebView2()+ .and_then(|core| core.Settings())+ .and_then(|settings| settings.cast::<ICoreWebView2Settings3>())+ .and_then(|settings| settings.SetAreBrowserAcceleratorKeysEnabled(false));++ if let Err(error) = result {+ log::warn!("Failed to disable WebView2 browser accelerators: {error}");+ }+ });+ }let mut settings = get_settings(app.handle());