Skip to content

Commit

Permalink
icon path can be relative
Browse files Browse the repository at this point in the history
  • Loading branch information
sigoden committed Oct 25, 2024
1 parent e180b9d commit 3be69c4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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("=")
Expand Down
11 changes: 10 additions & 1 deletion src/utils/app_icon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -123,6 +129,9 @@ fn get_appx_logo_path(module_path: &str) -> Option<PathBuf> {

pub fn load_image_as_hicon<T: AsRef<Path>>(image_path: T) -> Option<HICON> {
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 {
Expand Down

0 comments on commit 3be69c4

Please sign in to comment.