Skip to content
Merged
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/asset-protocol.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"api": patch
---

Add asset custom protocol to access local file system.
2 changes: 1 addition & 1 deletion core/tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ normal = [ "attohttpc" ]
[dependencies]
serde_json = { version = "1.0", features = [ "raw_value" ] }
serde = { version = "1.0", features = [ "derive" ] }
tokio = { version = "1.7", features = [ "rt", "rt-multi-thread", "sync" ] }
tokio = { version = "1.7", features = [ "rt", "rt-multi-thread", "sync", "fs" ] }
futures = "0.3"
uuid = { version = "0.8", features = [ "v4" ] }
thiserror = "1.0"
Expand Down
9 changes: 9 additions & 0 deletions core/tauri/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,15 @@ impl<P: Params> WindowManager<P> {
current_window_label = label.to_js_string()?,
));

webview_attributes.uri_scheme_protocols.insert(
Comment thread
lemarier marked this conversation as resolved.
"asset".into(),
Box::new(move |url| {
let path = url.replace("asset://", "");
let data = crate::async_runtime::block_on(async move { tokio::fs::read(path).await })?;
Ok(data)
}),
);

#[cfg(dev)]
{
webview_attributes = webview_attributes.initialization_script(&format!(
Expand Down