ソースを参照

feat: disable drop handler (#3680)

Miles Murgaw 4 ヶ月 前
コミット
18feb0b38d
2 ファイル変更14 行追加2 行削除
  1. 9 0
      packages/desktop/src/config.rs
  2. 5 2
      packages/desktop/src/webview.rs

+ 9 - 0
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<CustomEventHandler>,
+    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);

+ 5 - 2
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);