mirror of
https://github.com/tauri-apps/tauri.git
synced 2025-01-04 17:18:56 +03:00
feat: asset custom protocol to access local file system (#2104)
This commit is contained in:
parent
628a53eb61
commit
ee60e42422
5
.changes/asset-protocol.md
Normal file
5
.changes/asset-protocol.md
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"api": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Add asset custom protocol to access local file system.
|
@ -33,7 +33,7 @@ normal = [ "attohttpc" ]
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
serde_json = { version = "1.0", features = [ "raw_value" ] }
|
serde_json = { version = "1.0", features = [ "raw_value" ] }
|
||||||
serde = { version = "1.0", features = [ "derive" ] }
|
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"
|
futures = "0.3"
|
||||||
uuid = { version = "0.8", features = [ "v4" ] }
|
uuid = { version = "0.8", features = [ "v4" ] }
|
||||||
thiserror = "1.0"
|
thiserror = "1.0"
|
||||||
|
@ -343,6 +343,15 @@ impl<P: Params> WindowManager<P> {
|
|||||||
current_window_label = label.to_js_string()?,
|
current_window_label = label.to_js_string()?,
|
||||||
));
|
));
|
||||||
|
|
||||||
|
webview_attributes.uri_scheme_protocols.insert(
|
||||||
|
"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)]
|
#[cfg(dev)]
|
||||||
{
|
{
|
||||||
webview_attributes = webview_attributes.initialization_script(&format!(
|
webview_attributes = webview_attributes.initialization_script(&format!(
|
||||||
|
Loading…
Reference in New Issue
Block a user