mirror of
https://github.com/tauri-apps/tauri.git
synced 2025-01-02 07:56:20 +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]
|
||||
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"
|
||||
|
@ -343,6 +343,15 @@ impl<P: Params> WindowManager<P> {
|
||||
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)]
|
||||
{
|
||||
webview_attributes = webview_attributes.initialization_script(&format!(
|
||||
|
Loading…
Reference in New Issue
Block a user