Эх сурвалжийг харах

fix(core): custom protocol regression (#2115)

Lucas Fernandes Nogueira 4 жил өмнө
parent
commit
99d960841c

+ 5 - 0
.changes/fix-custom-protocol.md

@@ -0,0 +1,5 @@
+---
+"tauri": patch
+---
+
+Fixes `asset` protocol crashing application.

+ 7 - 9
core/tauri/src/manager.rs

@@ -343,15 +343,6 @@ 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!(
@@ -386,6 +377,13 @@ impl<P: Params> WindowManager<P> {
       webview_attributes = webview_attributes
         .register_uri_scheme_protocol("tauri", self.prepare_uri_scheme_protocol().protocol);
     }
+    if !webview_attributes.has_uri_scheme_protocol("asset") {
+      webview_attributes = webview_attributes.register_uri_scheme_protocol("asset", move |url| {
+        let path = url.replace("asset://", "");
+        let data = crate::async_runtime::block_on(async move { tokio::fs::read(path).await })?;
+        Ok(data)
+      });
+    }
 
     let local_app_data = resolve_path(
       &self.inner.config,