From 36f3db741178b959070ee90bcd6448e1b2a6ef26 Mon Sep 17 00:00:00 2001 From: Jake Stanger Date: Wed, 26 Jul 2023 21:51:39 +0100 Subject: [PATCH] refactor(image): do not try to read desktop files where definitely not necessary --- src/image/provider.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/image/provider.rs b/src/image/provider.rs index 00c26c4..397ba62 100644 --- a/src/image/provider.rs +++ b/src/image/provider.rs @@ -50,12 +50,12 @@ impl<'a> ImageProvider<'a> { /// Returns true if the input starts with a prefix /// that is supported by the parser /// (ie the parser would not fallback to checking the input). - #[cfg(any(feature = "music", feature = "workspaces"))] pub fn is_definitely_image_input(input: &str) -> bool { input.starts_with("icon:") || input.starts_with("file://") || input.starts_with("http://") || input.starts_with("https://") + || input.starts_with('/') } fn get_location( @@ -77,6 +77,8 @@ impl<'a> ImageProvider<'a> { const MAX_RECURSE_DEPTH: usize = 2; + let should_parse_desktop_file = !Self::is_definitely_image_input(input); + let (input_type, input_name) = input .split_once(':') .map_or((None, input), |(t, n)| (Some(t), n)); @@ -117,7 +119,7 @@ impl<'a> ImageProvider<'a> { Some(ImageLocation::Local(PathBuf::from(input_name))) } None if recurse_depth == MAX_RECURSE_DEPTH => fallback!(), - None => { + None if should_parse_desktop_file => { if let Some(location) = get_desktop_icon_name(input_name).map(|input| { Self::get_location(&input, theme, size, use_fallback, recurse_depth + 1) }) { @@ -127,6 +129,10 @@ impl<'a> ImageProvider<'a> { fallback!() } } + None => { + warn!("Failed to find image: {input}"); + fallback!() + } } }