diff --git a/.changes/default-download.md b/.changes/default-download.md new file mode 100644 index 000000000000..83a5c7135e82 --- /dev/null +++ b/.changes/default-download.md @@ -0,0 +1,5 @@ +--- +tauri: "patch:enhance" +--- + +Tauri will now allow downloads (``) on local URLs (devPath/frontendDist) by default, essentially matching the behavior of browsers. This behavior can be overwritting by providing a custom [download handler](https://docs.rs/tauri/latest/tauri/webview/struct.WebviewWindowBuilder.html#method.on_download) in Rust. diff --git a/crates/tauri/src/webview/mod.rs b/crates/tauri/src/webview/mod.rs index 4f7a17a0e4d5..779b446c0636 100644 --- a/crates/tauri/src/webview/mod.rs +++ b/crates/tauri/src/webview/mod.rs @@ -572,6 +572,18 @@ tauri::Builder::default() false } })); + } else { + // If no download handler was provided we provide a default handler + // that behaves similar to a browser by saving the file into the Downloads dir if the current url is local. + let label = pending.label.clone(); + let manager = manager.manager_owned(); + pending.download_handler.replace(Arc::new(move |_| { + if let Some(w) = manager.get_webview(&label) { + w.url().map(|url| w.is_local_url(&url)).unwrap_or(false) + } else { + false + } + })); } let label_ = pending.label.clone();