From 1456f8e33ad3d05239c2ee71f64e49ef32d48f03 Mon Sep 17 00:00:00 2001 From: Fabian-Lars Date: Fri, 15 Aug 2025 15:25:11 +0200 Subject: [PATCH] fix: Allow downloads by default on linux/macos to match windows behavior (#1602) --- .changes/allow-downloads-default.md | 5 +++++ src/lib.rs | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 .changes/allow-downloads-default.md diff --git a/.changes/allow-downloads-default.md b/.changes/allow-downloads-default.md new file mode 100644 index 0000000..abdbcd9 --- /dev/null +++ b/.changes/allow-downloads-default.md @@ -0,0 +1,5 @@ +--- +wry: patch +--- + +Enabled all downloads by default to match WebView2 and browser behavior on all platforms. To disable this, provide a custom `download_started_handler`. diff --git a/src/lib.rs b/src/lib.rs index 2f59ff7..659d66c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -585,6 +585,8 @@ pub struct WebViewAttributes<'a> { /// second is a mutable `PathBuf` reference that (possibly) represents where the file will be downloaded to. The latter /// parameter can be used to set the download location by assigning a new path to it, the assigned path _must_ be /// absolute. The closure returns a `bool` to allow or deny the download. + /// + /// [`Self::default()`] sets a handler allowing all downloads to match browser behavior. pub download_started_handler: Option bool + 'static>>, /// A download completion handler to manage downloads that have finished. @@ -718,7 +720,7 @@ impl Default for WebViewAttributes<'_> { ipc_handler: None, drag_drop_handler: None, navigation_handler: None, - download_started_handler: None, + download_started_handler: Some(Box::new(|_, _| true)), download_completed_handler: None, new_window_req_handler: None, clipboard: false, @@ -1159,6 +1161,8 @@ impl<'a> WebViewBuilder<'a> { /// second is a mutable `PathBuf` reference that (possibly) represents where the file will be downloaded to. The latter /// parameter can be used to set the download location by assigning a new path to it, the assigned path _must_ be /// absolute. The closure returns a `bool` to allow or deny the download. + /// + /// By default a handler that allows all downloads is set to match browser behavior. pub fn with_download_started_handler( mut self, download_started_handler: impl FnMut(String, &mut PathBuf) -> bool + 'static,