perf(wallpaper): ignore files that are not images

This commit is contained in:
Michael Aaron Murphy 2023-12-14 04:16:27 +01:00
parent 8000a67442
commit 2be76211e8
No known key found for this signature in database
GPG key ID: B2732D4240C9212C
3 changed files with 39 additions and 1 deletions

View file

@ -12,6 +12,7 @@ dirs = "5.0.1"
freedesktop-icons = "0.2.4"
futures-lite = "1.13.0"
image = "0.24.6"
infer = "0.15.0"
rayon = "1.7.0"
sctk = { git = "https://github.com/smithay/client-toolkit/", package = "smithay-client-toolkit", rev = "dc8c4a0"}
tokio = { version = "1.28.0", features = ["sync"] }

View file

@ -93,8 +93,11 @@ pub fn load_each_from_path(path: PathBuf) -> Receiver<(PathBuf, RgbaImage, RgbaI
let (tx, rx) = mpsc::channel(1);
tokio::task::spawn(async move {
// Scratch space for storing images into.
let mut buffer = Vec::new();
// Directories to search recursively.
let mut paths = vec![path];
// Discovered image files that will be loaded as wallpapers.
let mut wallpapers = BTreeSet::new();
while let Some(path) = paths.pop() {
@ -106,10 +109,17 @@ pub fn load_each_from_path(path: PathBuf) -> Receiver<(PathBuf, RgbaImage, RgbaI
let path = entry.path();
// Recursively search directories, while storing only image files.
if file_type.is_dir() {
paths.push(path);
} else if file_type.is_file() {
wallpapers.insert(path);
let Ok(Some(kind)) = infer::get_from_path(&path) else {
continue
};
if infer::MatcherType::Image == kind.matcher_type() {
wallpapers.insert(path);
}
}
}
}