From 18feb0b38d858dc57d69d378669f90f57efe73e2 Mon Sep 17 00:00:00 2001 From: Miles Murgaw Date: Fri, 7 Feb 2025 19:10:05 -0500 Subject: [PATCH] feat: disable drop handler (#3680) --- packages/desktop/src/config.rs | 9 +++++++++ packages/desktop/src/webview.rs | 7 +++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/desktop/src/config.rs b/packages/desktop/src/config.rs index 3b587ba07e..9a89b4f055 100644 --- a/packages/desktop/src/config.rs +++ b/packages/desktop/src/config.rs @@ -63,6 +63,7 @@ pub struct Config { pub(crate) background_color: Option<(u8, u8, u8, u8)>, pub(crate) last_window_close_behavior: WindowCloseBehaviour, pub(crate) custom_event_handler: Option, + pub(crate) disable_file_drop_handler: bool, } impl LaunchConfig for Config {} @@ -108,6 +109,7 @@ impl Config { background_color: None, last_window_close_behavior: WindowCloseBehaviour::LastWindowExitsApp, custom_event_handler: None, + disable_file_drop_handler: false, } } @@ -131,6 +133,13 @@ impl Config { self } + /// Set whether or not the file drop handler should be disabled. + /// On Windows the drop handler must be disabled for HTML drag and drop APIs to work. + pub fn with_disable_drag_drop_handler(mut self, disable: bool) -> Self { + self.disable_file_drop_handler = disable; + self + } + /// Set the pre-rendered HTML content pub fn with_prerendered(mut self, content: String) -> Self { self.pre_rendered = Some(content); diff --git a/packages/desktop/src/webview.rs b/packages/desktop/src/webview.rs index 2c5ad4bd12..05ff7c0ad1 100644 --- a/packages/desktop/src/webview.rs +++ b/packages/desktop/src/webview.rs @@ -359,8 +359,11 @@ impl WebviewInstance { } }) // prevent all navigations .with_asynchronous_custom_protocol(String::from("dioxus"), request_handler) - .with_web_context(&mut web_context) - .with_drag_drop_handler(file_drop_handler); + .with_web_context(&mut web_context); + + if !cfg.disable_file_drop_handler { + webview = webview.with_drag_drop_handler(file_drop_handler); + } if let Some(color) = cfg.background_color { webview = webview.with_background_color(color);