mirror of
https://github.com/Zedfrigg/ironbar.git
synced 2025-07-04 12:11:03 +02:00
fix(image): using fallback in places it shouldn't
This commit is contained in:
parent
1c68a97d33
commit
2367faab04
7 changed files with 27 additions and 15 deletions
|
@ -41,8 +41,9 @@ impl<'a> ImageProvider<'a> {
|
|||
///
|
||||
/// Note this checks that icons exist in theme, or files exist on disk
|
||||
/// but no other check is performed.
|
||||
pub fn parse(input: &str, theme: &'a IconTheme, size: i32) -> Option<Self> {
|
||||
let location = Self::get_location(input, theme, size, 0)?;
|
||||
pub fn parse(input: &str, theme: &'a IconTheme, use_fallback: bool, size: i32) -> Option<Self> {
|
||||
let location = Self::get_location(input, theme, size, use_fallback, 0)?;
|
||||
|
||||
Some(Self { location, size })
|
||||
}
|
||||
|
||||
|
@ -61,8 +62,19 @@ impl<'a> ImageProvider<'a> {
|
|||
input: &str,
|
||||
theme: &'a IconTheme,
|
||||
size: i32,
|
||||
use_fallback: bool,
|
||||
recurse_depth: usize,
|
||||
) -> Option<ImageLocation<'a>> {
|
||||
macro_rules! fallback {
|
||||
() => {
|
||||
if use_fallback {
|
||||
Some(Self::get_fallback_icon(theme))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
const MAX_RECURSE_DEPTH: usize = 2;
|
||||
|
||||
let (input_type, input_name) = input
|
||||
|
@ -99,20 +111,20 @@ impl<'a> ImageProvider<'a> {
|
|||
Report::msg(format!("Unsupported image type: {input_type}"))
|
||||
.note("You may need to recompile with support if available")
|
||||
);
|
||||
None
|
||||
fallback!()
|
||||
}
|
||||
None if PathBuf::from(input_name).is_file() => {
|
||||
Some(ImageLocation::Local(PathBuf::from(input_name)))
|
||||
}
|
||||
None if recurse_depth == MAX_RECURSE_DEPTH => Some(Self::get_fallback_icon(theme)),
|
||||
None if recurse_depth == MAX_RECURSE_DEPTH => fallback!(),
|
||||
None => {
|
||||
if let Some(location) = get_desktop_icon_name(input_name)
|
||||
.map(|input| Self::get_location(&input, theme, size, recurse_depth + 1))
|
||||
{
|
||||
if let Some(location) = get_desktop_icon_name(input_name).map(|input| {
|
||||
Self::get_location(&input, theme, size, use_fallback, recurse_depth + 1)
|
||||
}) {
|
||||
location
|
||||
} else {
|
||||
warn!("Failed to find image: {input}");
|
||||
Some(Self::get_fallback_icon(theme))
|
||||
fallback!()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue