Skip to content

DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.

fix(desktop): 关闭 WebView2 外部拖放,修复拖选文本后页面卡死(#591)

hairyf73a7cb3b9b56
diff --git a/src-tauri/src/desktop/builder.rs b/src-tauri/src/desktop/builder.rs
index 6a00ae45..4171dea5 100644
--- a/src-tauri/src/desktop/builder.rs
+++ b/src-tauri/src/desktop/builder.rs
@@ -537,6 +537,9 @@ pub fn build_main_window(app: &tauri::AppHandle<Wry>) -> tauri::Result<tauri::We
// 注意不能用 .drag_and_drop(false):它只设置 tao 窗口层的拖放开关
// (tauri issue #13761),不影响 webview 层,拖拽依旧失效;
// disable_drag_drop_handler 才能关掉 wry 的接管(等价于旧配置 dragDropEnabled: false)。
+ // 代价:wry 随接管一起关掉的 AllowExternalDrop 防护也没了,必须由
+ // desktop::window::disable_external_drop 在页面加载时补回,否则页面内拖放
+ // 文本会让 WebView2 卡在失效的鼠标捕获上(issue #591)。
.disable_drag_drop_handler()
// 接管内嵌 iframe 的 window.open() / target=_blank 新窗口请求:
// WebView2 里这类请求走 NewWindowRequested,wry 在没有 handler 时
diff --git a/src-tauri/src/desktop/window.rs b/src-tauri/src/desktop/window.rs
index 47bcba40..270fb383 100644
--- a/src-tauri/src/desktop/window.rs
+++ b/src-tauri/src/desktop/window.rs
@@ -64,6 +64,30 @@ pub fn on_download<R: Runtime>(webview: Webview<R>, event: DownloadEvent<'_>) ->
}
}
+/// 关掉 WebView2 的外部拖放(`AllowExternalDrop`)。
+///
+/// wry 只在它自己接管拖放时才关闭该开关(`drop_handler` 为空就跳过);本项目用
+/// `disable_drag_drop_handler()` 关掉了那份接管以恢复 iframe 内的 HTML5 拖拽,
+/// 于是开关留在默认开启状态。而开启时,在页面内拖放文本会让 WebView2 卡在失效的
+/// 鼠标捕获上:选中无法取消、点击与输入失效、滚轮仍可用(WebView2Feedback #5141 /
+/// #5613)。这里补回这道防护——它只影响外部拖放,页面内 HTML5 拖拽不受影响。
+#[cfg(windows)]
+pub fn disable_external_drop(webview: &tauri::webview::PlatformWebview) {
+ use webview2_com::Microsoft::Web::WebView2::Win32::ICoreWebView2Controller4;
+ use windows_core::Interface;
+
+ unsafe {
+ match webview.controller().cast::<ICoreWebView2Controller4>() {
+ Ok(controller) => {
+ if let Err(e) = controller.SetAllowExternalDrop(false) {
+ log::warn!("[webview] failed to disable external drop: {e}");
+ }
+ }
+ Err(e) => log::warn!("[webview] ICoreWebView2Controller4 unavailable: {e}"),
+ }
+ }
+}
+
#[cfg(windows)]
pub fn on_page_load(
webview_window: WebviewWindow<Wry>,
@@ -80,6 +104,7 @@ pub fn on_page_load(
log::info!("[notification] top-level page load started; scheduling handler registration");
let parent = webview_window.clone();
if let Err(e) = webview_window.with_webview(move |platform| {
+ disable_external_drop(&platform);
if let Err(e) =
crate::desktop::notification::enable_notification_permissions(platform, parent)
{