Skip to content

Commit 99d9608

Browse files
authored
fix(core): custom protocol regression (#2115)
1 parent 1a41e9f commit 99d9608

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

.changes/fix-custom-protocol.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri": patch
3+
---
4+
5+
Fixes `asset` protocol crashing application.

core/tauri/src/manager.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -343,15 +343,6 @@ 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-
355346
#[cfg(dev)]
356347
{
357348
webview_attributes = webview_attributes.initialization_script(&format!(
@@ -386,6 +377,13 @@ impl<P: Params> WindowManager<P> {
386377
webview_attributes = webview_attributes
387378
.register_uri_scheme_protocol("tauri", self.prepare_uri_scheme_protocol().protocol);
388379
}
380+
if !webview_attributes.has_uri_scheme_protocol("asset") {
381+
webview_attributes = webview_attributes.register_uri_scheme_protocol("asset", move |url| {
382+
let path = url.replace("asset://", "");
383+
let data = crate::async_runtime::block_on(async move { tokio::fs::read(path).await })?;
384+
Ok(data)
385+
});
386+
}
389387

390388
let local_app_data = resolve_path(
391389
&self.inner.config,

0 commit comments

Comments
 (0)