Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changes/default-download.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
tauri: "patch:enhance"
---

Tauri will now allow downloads (`<a href="..." download="...">`) 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.
12 changes: 12 additions & 0 deletions crates/tauri/src/webview/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Loading