Skip to content

Commit

Permalink
feat: disable drop handler (#3680)
Browse files Browse the repository at this point in the history
  • Loading branch information
DogeDark authored Feb 8, 2025
1 parent 8b9e246 commit 18feb0b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
9 changes: 9 additions & 0 deletions packages/desktop/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
Expand Down Expand Up @@ -108,6 +109,7 @@ impl Config {
background_color: None,
last_window_close_behavior: WindowCloseBehaviour::LastWindowExitsApp,
custom_event_handler: None,
disable_file_drop_handler: false,
}
}

Expand All @@ -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);
Expand Down
7 changes: 5 additions & 2 deletions packages/desktop/src/webview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 18feb0b

Please sign in to comment.