From 7b2bf4acc5b218eab6dc0f94ebca55661e87c65f Mon Sep 17 00:00:00 2001 From: Evan Almloff Date: Fri, 18 Aug 2023 10:57:30 -0500 Subject: [PATCH] find head relative to asset root --- packages/desktop/src/protocol.rs | 9 ++++++--- packages/desktop/src/webview.rs | 6 ++++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/desktop/src/protocol.rs b/packages/desktop/src/protocol.rs index 4046ee42f..0a8a9ff3e 100644 --- a/packages/desktop/src/protocol.rs +++ b/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 { /* diff --git a/packages/desktop/src/webview.rs b/packages/desktop/src/webview.rs index cd7561b74..a464653b8 100644 --- a/packages/desktop/src/webview.rs +++ b/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 } }