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

27
Cargo.lock generated
View file

@ -638,6 +638,17 @@ dependencies = [
"libc",
]
[[package]]
name = "cfb"
version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d38f2da7a0a2c4ccf0065be06397cc26a81f4e528be095826eee9d4adbb8c60f"
dependencies = [
"byteorder",
"fnv",
"uuid",
]
[[package]]
name = "cfg-if"
version = "1.0.0"
@ -1004,6 +1015,7 @@ dependencies = [
"freedesktop-icons",
"futures-lite 1.13.0",
"image",
"infer",
"rayon",
"smithay-client-toolkit 0.18.0",
"tokio",
@ -2606,6 +2618,15 @@ dependencies = [
"hashbrown 0.14.3",
]
[[package]]
name = "infer"
version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cb33622da908807a06f9513c19b3c1ad50fab3e4137d82a78107d502075aa199"
dependencies = [
"cfb",
]
[[package]]
name = "inotify"
version = "0.9.6"
@ -4988,6 +5009,12 @@ version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a"
[[package]]
name = "uuid"
version = "1.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5e395fcf16a7a3d8127ec99782007af141946b4795001f876d54fb0d55978560"
[[package]]
name = "valuable"
version = "0.1.0"

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);
}
}
}
}