From 7864d41de8650f20fa73cefbddd78381b9d8aa11 Mon Sep 17 00:00:00 2001 From: Lucas Fernandes Nogueira Date: Thu, 21 Apr 2022 20:34:15 -0700 Subject: [PATCH] feat(core): fallback to `{path}.html` in Tauri protocol loader ref #3887 (#3939) --- .changes/asset-default-ext-fallback.md | 5 +++++ core/tauri/src/manager.rs | 14 +++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 .changes/asset-default-ext-fallback.md diff --git a/.changes/asset-default-ext-fallback.md b/.changes/asset-default-ext-fallback.md new file mode 100644 index 000000000..ca82b8758 --- /dev/null +++ b/.changes/asset-default-ext-fallback.md @@ -0,0 +1,5 @@ +--- +"tauri": patch +--- + +Fallback to `{path}.html` when `{path}` is not found in the Tauri custom protocol handler. diff --git a/core/tauri/src/manager.rs b/core/tauri/src/manager.rs index c6018c838..ddef57b5f 100644 --- a/core/tauri/src/manager.rs +++ b/core/tauri/src/manager.rs @@ -751,6 +751,18 @@ impl WindowManager { let asset_response = assets .get(&path.as_str().into()) .or_else(|| { + eprintln!("Asset `{}` not found; fallback to {}.html", path, path); + let fallback = format!("{}.html", path.as_str()).into(); + let asset = assets.get(&fallback); + asset_path = fallback; + asset + }) + .or_else(|| { + #[cfg(debug_assertions)] + eprintln!( + "Asset `{}` not found; fallback to {}/index.html", + path, path + ); let fallback = format!("{}/index.html", path.as_str()).into(); let asset = assets.get(&fallback); asset_path = fallback; @@ -758,7 +770,7 @@ impl WindowManager { }) .or_else(|| { #[cfg(debug_assertions)] - eprintln!("Asset `{}` not found; fallback to index.html", path); // TODO log::error! + eprintln!("Asset `{}` not found; fallback to index.html", path); let fallback = AssetKey::from("index.html"); let asset = assets.get(&fallback); asset_path = fallback;