diff --git a/src-tauri/src/utils/dirs.rs b/src-tauri/src/utils/dirs.rs index 56c74f2bc..f83af90f4 100644 --- a/src-tauri/src/utils/dirs.rs +++ b/src-tauri/src/utils/dirs.rs @@ -103,31 +103,18 @@ pub fn app_icons_dir() -> Result { pub fn find_target_icons(target: &str) -> Result> { let icons_dir = app_icons_dir()?; - let mut matching_files = Vec::new(); + let icon_path = fs::read_dir(&icons_dir)? + .filter_map(|entry| entry.ok().map(|e| e.path())) + .find(|path| { + path.file_prefix().is_some_and(|prefix| prefix == target) + && path + .extension() + .is_some_and(|ext| ext == "ico" || ext == "png") + }); - for entry in fs::read_dir(icons_dir)? { - let entry = entry?; - let path = entry.path(); - - if let Some(file_name) = path.file_name().and_then(|n| n.to_str()) - && file_name.starts_with(target) - && (file_name.ends_with(".ico") || file_name.ends_with(".png")) - { - matching_files.push(path); - } - } - - if matching_files.is_empty() { - Ok(None) - } else { - match matching_files.first() { - Some(first_path) => { - let first = path_to_str(first_path)?; - Ok(Some(first.into())) - } - None => Ok(None), - } - } + icon_path + .map(|path| path_to_str(&path).map(|s| s.into())) + .transpose() } /// logs dir