From 3be69c49eb0f4bdb8d9672fee14d507a95cd862a Mon Sep 17 00:00:00 2001 From: sigoden Date: Fri, 25 Oct 2024 21:27:32 +0800 Subject: [PATCH] icon path can be relative --- src/config.rs | 2 +- src/utils/app_icon.rs | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/config.rs b/src/config.rs index 6000b3f..7646b68 100644 --- a/src/config.rs +++ b/src/config.rs @@ -111,7 +111,7 @@ impl Config { } if let Some(v) = section.get("override_icons").map(normalize_path_value) { conf.switch_apps_override_icons = v - .split(|c: char| c == ',' || c == ';') + .split([',', ';']) .filter_map(|v| { v.trim() .split_once("=") diff --git a/src/utils/app_icon.rs b/src/utils/app_icon.rs index f92a8bd..6117dd1 100644 --- a/src/utils/app_icon.rs +++ b/src/utils/app_icon.rs @@ -38,7 +38,13 @@ pub fn get_app_icon( .iter() .find(|(k, _)| module_path_lc.contains(*k)) { - if let Some(icon) = load_image_as_hicon(v) { + let mut override_path = PathBuf::from(v); + if !override_path.is_absolute() { + if let Some(module_dir) = Path::new(module_path).parent() { + override_path = module_dir.join(override_path); + } + } + if let Some(icon) = load_image_as_hicon(override_path) { return icon; } } @@ -123,6 +129,9 @@ fn get_appx_logo_path(module_path: &str) -> Option { pub fn load_image_as_hicon>(image_path: T) -> Option { let image_path = image_path.as_ref(); + if !image_path.exists() { + return None; + } if let Some("ico") = image_path.extension().and_then(|v| v.to_str()) { let icon_path = to_wstring(image_path.to_string_lossy().as_ref()); unsafe {