fix: Fallback to using the hicolor theme if the selected theme doesn't exist
This commit is contained in:
parent
5e8d39a7a7
commit
c7914692a2
1 changed files with 51 additions and 46 deletions
97
src/lib.rs
97
src/lib.rs
|
|
@ -235,60 +235,65 @@ impl<'a> LookupBuilder<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Then lookup in the given theme
|
// Then lookup in the given theme
|
||||||
THEMES.get(self.theme).and_then(|icon_themes| {
|
THEMES
|
||||||
let icon = icon_themes
|
.get(self.theme)
|
||||||
.iter()
|
.or_else(|| THEMES.get("hicolor"))
|
||||||
.find_map(|theme| {
|
.and_then(|icon_themes| {
|
||||||
theme.try_get_icon(self.name, self.size, self.scale, self.force_svg)
|
let icon = icon_themes
|
||||||
})
|
.iter()
|
||||||
.or_else(|| {
|
.find_map(|theme| {
|
||||||
// Fallback to the parent themes recursively
|
theme.try_get_icon(self.name, self.size, self.scale, self.force_svg)
|
||||||
let mut parents = icon_themes
|
})
|
||||||
.iter()
|
.or_else(|| {
|
||||||
.flat_map(|t| t.inherits())
|
// Fallback to the parent themes recursively
|
||||||
.collect::<Vec<_>>();
|
let mut parents = icon_themes
|
||||||
parents.dedup();
|
.iter()
|
||||||
parents.into_iter().find_map(|parent| {
|
.flat_map(|t| t.inherits())
|
||||||
THEMES.get(parent).and_then(|parent| {
|
.collect::<Vec<_>>();
|
||||||
parent.iter().find_map(|t| {
|
parents.dedup();
|
||||||
t.try_get_icon(self.name, self.size, self.scale, self.force_svg)
|
parents.into_iter().find_map(|parent| {
|
||||||
|
THEMES.get(parent).and_then(|parent| {
|
||||||
|
parent.iter().find_map(|t| {
|
||||||
|
t.try_get_icon(self.name, self.size, self.scale, self.force_svg)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
.or_else(|| {
|
||||||
.or_else(|| {
|
THEMES.get("hicolor").and_then(|icon_themes| {
|
||||||
THEMES.get("hicolor").and_then(|icon_themes| {
|
icon_themes.iter().find_map(|theme| {
|
||||||
icon_themes.iter().find_map(|theme| {
|
theme.try_get_icon(self.name, self.size, self.scale, self.force_svg)
|
||||||
theme.try_get_icon(self.name, self.size, self.scale, self.force_svg)
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
.or_else(|| {
|
||||||
.or_else(|| {
|
for theme_base_dir in BASE_PATHS.iter() {
|
||||||
for theme_base_dir in BASE_PATHS.iter() {
|
if let Some(icon) =
|
||||||
if let Some(icon) =
|
try_build_icon_path(self.name, theme_base_dir, self.force_svg)
|
||||||
try_build_icon_path(self.name, theme_base_dir, self.force_svg)
|
{
|
||||||
{
|
return Some(icon);
|
||||||
return Some(icon);
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
None
|
|
||||||
})
|
|
||||||
.or_else(|| try_build_icon_path(self.name, "/usr/share/pixmaps", self.force_svg))
|
|
||||||
.or_else(|| {
|
|
||||||
let p = PathBuf::from(&self.name);
|
|
||||||
if let (Some(name), Some(parent)) = (p.file_stem(), p.parent()) {
|
|
||||||
try_build_icon_path(&name.to_string_lossy(), parent, self.force_svg)
|
|
||||||
} else {
|
|
||||||
None
|
None
|
||||||
}
|
})
|
||||||
});
|
.or_else(|| {
|
||||||
|
try_build_icon_path(self.name, "/usr/share/pixmaps", self.force_svg)
|
||||||
|
})
|
||||||
|
.or_else(|| {
|
||||||
|
let p = PathBuf::from(&self.name);
|
||||||
|
if let (Some(name), Some(parent)) = (p.file_stem(), p.parent()) {
|
||||||
|
try_build_icon_path(&name.to_string_lossy(), parent, self.force_svg)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
if self.cache {
|
if self.cache {
|
||||||
self.store(self.theme, icon)
|
self.store(self.theme, icon)
|
||||||
} else {
|
} else {
|
||||||
icon
|
icon
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue