fix: asset resolution on debug mode

This commit is contained in:
Lucas Nogueira
2021-03-31 02:51:32 -03:00
parent 52a5a6727e
commit 5eb04461ae
2 changed files with 7 additions and 10 deletions

View File

@@ -14,11 +14,12 @@ pub struct ContextData {
/// Build an `AsTauriContext` implementation for including in application code.
pub fn context_codegen(data: ContextData) -> Result<TokenStream, EmbeddedAssetsError> {
let ContextData {
config,
mut config,
config_parent,
struct_ident,
} = data;
let dist_dir = config_parent.join(&config.build.dist_dir);
config.build.dist_dir = dist_dir.to_string_lossy().to_string();
// generate the assets inside the dist dir into a perfect hash function
let assets = EmbeddedAssets::new(&dist_dir)?;

View File

@@ -216,17 +216,13 @@ pub(super) fn build_webview<A: ApplicationExt + 'static>(
.canonicalize()
.or_else(|_| Err(crate::Error::AssetNotFound(path.clone())))
.and_then(|pathbuf| {
if pathbuf.is_file() && pathbuf.starts_with(&dist_dir) {
match std::fs::read(pathbuf) {
Ok(asset) => return Ok(asset),
Err(e) => {
#[cfg(debug_assertions)]
eprintln!("Error reading asset from dist: {:?}", e); // TODO log::error!
}
match std::fs::read(pathbuf) {
Ok(asset) => Ok(asset),
Err(e) => {
eprintln!("Error reading asset from dist: {:?}", e); // TODO log::error!
Err(crate::Error::AssetNotFound(path.clone()))
}
}
Err(crate::Error::AssetNotFound(path))
})
})
}