From 64fc749174a756f42599ff0fdf0e30a29af5beb3 Mon Sep 17 00:00:00 2001 From: nik012003 Date: Tue, 16 May 2023 14:14:56 +0200 Subject: [PATCH] Added size to cached icon map --- src/xdg.rs | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/src/xdg.rs b/src/xdg.rs index 409a7f6..8df3b43 100644 --- a/src/xdg.rs +++ b/src/xdg.rs @@ -25,7 +25,7 @@ use walkdir::WalkDir; struct ImageCache { path: PathBuf, #[serde_as(as = "Vec<(_, _)>")] - pub map: HashMap, + pub map: HashMap<(String, u16), PathBuf>, } impl ImageCache { @@ -46,7 +46,7 @@ impl ImageCache { } } - fn insert(&mut self, k: String, v: PathBuf) { + fn insert(&mut self, k: (String, u16), v: PathBuf) { self.map.insert(k, v); } @@ -237,7 +237,12 @@ impl DesktopFile { } } - if let Some(cache_icon_path) = IMAGE_CACHE.lock().unwrap().map.get(icon_name) { + if let Some(cache_icon_path) = IMAGE_CACHE + .lock() + .unwrap() + .map + .get(&(icon_name.clone(), preferred_px_size)) + { if cache_icon_path.exists() { if let Some(icon) = Icon::from_path(cache_icon_path.to_owned(), preferred_px_size) { return Some(icon); @@ -296,25 +301,28 @@ impl Icon { } pub fn cached_process(self, size: u16) -> Result { - if !IMAGE_CACHE.lock().unwrap().map.contains_key( - &self - .path + if !IMAGE_CACHE.lock().unwrap().map.contains_key(&( + self.path .with_extension("") .file_name() .unwrap() .to_str() .unwrap() .to_owned(), - ) { + size, + )) { print!("Saving in the cache"); IMAGE_CACHE.lock().unwrap().insert( - self.path - .with_extension("") - .file_name() - .unwrap() - .to_str() - .unwrap() - .to_owned(), + ( + self.path + .with_extension("") + .file_name() + .unwrap() + .to_str() + .unwrap() + .to_owned(), + size, + ), self.path.clone(), ); IMAGE_CACHE.lock().unwrap().save();