Explorar o código

find head relative to asset root

Evan Almloff hai 1 ano
pai
achega
7b2bf4acc5
Modificáronse 2 ficheiros con 10 adicións e 5 borrados
  1. 6 3
      packages/desktop/src/protocol.rs
  2. 4 2
      packages/desktop/src/webview.rs

+ 6 - 3
packages/desktop/src/protocol.rs

@@ -114,9 +114,7 @@ pub(super) fn desktop_handler(
     let path = PathBuf::from(&*decoded);
 
     // If the path is relative, we'll try to serve it from the assets directory.
-    let mut asset = get_asset_root()
-        .unwrap_or_else(|| Path::new(".").to_path_buf())
-        .join(&path);
+    let mut asset = get_asset_root_or_default().join(&path);
 
     if !asset.exists() {
         asset = PathBuf::from("/").join(path);
@@ -135,6 +133,11 @@ pub(super) fn desktop_handler(
         .map_err(From::from)
 }
 
+#[allow(unreachable_code)]
+pub(crate) fn get_asset_root_or_default() -> PathBuf {
+    get_asset_root().unwrap_or_else(|| Path::new(".").to_path_buf())
+}
+
 #[allow(unreachable_code)]
 fn get_asset_root() -> Option<PathBuf> {
     /*

+ 4 - 2
packages/desktop/src/webview.rs

@@ -25,10 +25,12 @@ pub fn build(
         }
         #[cfg(not(debug_assertions))]
         {
-            match std::fs::read_to_string("./dist/__assets_head.html") {
+            let head = crate::protocol::get_asset_root_or_default();
+            let head = head.join("dist/__assets_head.html");
+            match std::fs::read_to_string(&head) {
                 Ok(s) => Some(s),
                 Err(err) => {
-                    log::error!("Failed to read ./dist/__assets_head.html: {}", err);
+                    log::error!("Failed to read {head:?}: {err}");
                     None
                 }
             }