Skip to content

Commit ee60e42

Browse files
author
Ngo Iok Ui (Wu Yu Wei)
authored
feat: asset custom protocol to access local file system (#2104)
1 parent 628a53e commit ee60e42

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

.changes/asset-protocol.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"api": patch
3+
---
4+
5+
Add asset custom protocol to access local file system.

core/tauri/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ normal = [ "attohttpc" ]
3333
[dependencies]
3434
serde_json = { version = "1.0", features = [ "raw_value" ] }
3535
serde = { version = "1.0", features = [ "derive" ] }
36-
tokio = { version = "1.7", features = [ "rt", "rt-multi-thread", "sync" ] }
36+
tokio = { version = "1.7", features = [ "rt", "rt-multi-thread", "sync", "fs" ] }
3737
futures = "0.3"
3838
uuid = { version = "0.8", features = [ "v4" ] }
3939
thiserror = "1.0"

core/tauri/src/manager.rs

+9
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,15 @@ impl<P: Params> WindowManager<P> {
343343
current_window_label = label.to_js_string()?,
344344
));
345345

346+
webview_attributes.uri_scheme_protocols.insert(
347+
"asset".into(),
348+
Box::new(move |url| {
349+
let path = url.replace("asset://", "");
350+
let data = crate::async_runtime::block_on(async move { tokio::fs::read(path).await })?;
351+
Ok(data)
352+
}),
353+
);
354+
346355
#[cfg(dev)]
347356
{
348357
webview_attributes = webview_attributes.initialization_script(&format!(

0 commit comments

Comments
 (0)