Filter out non-desktop files

#3
This commit is contained in:
Gregory 2020-05-22 19:36:16 -04:00
parent 513d68d1bd
commit e86d7dd316
No known key found for this signature in database
GPG key ID: 2E44FAEEDC94B1E2

View file

@ -165,6 +165,9 @@ impl MimeApps {
xdg::BaseDirectories::new()? xdg::BaseDirectories::new()?
.list_data_files_once("applications") .list_data_files_once("applications")
.into_iter() .into_iter()
.filter(|p| {
p.extension().map(|x| x.to_str()).flatten() == Some("desktop")
})
.filter_map(|p| DesktopEntry::try_from(p).ok()) .filter_map(|p| DesktopEntry::try_from(p).ok())
.for_each(|e| { .for_each(|e| {
stdout.write_all(e.file_name.as_bytes()).unwrap(); stdout.write_all(e.file_name.as_bytes()).unwrap();
@ -201,19 +204,23 @@ impl SystemApps {
}) })
.filter_map(|data_dir| std::fs::read_dir(data_dir).ok()) .filter_map(|data_dir| std::fs::read_dir(data_dir).ok())
.for_each(|dir| { .for_each(|dir| {
dir.filter_map(|path| { dir.filter_map(Result::ok)
path.ok() .filter(|p| {
.map(|p| DesktopEntry::try_from(p.path()).ok()) p.path()
.flatten() .extension()
}) .map(std::ffi::OsStr::to_str)
.for_each(|entry| { .flatten()
let (file_name, mimes) = (entry.file_name, entry.mimes); == Some("desktop")
mimes.into_iter().for_each(|mime| { })
map.entry(mime) .filter_map(|p| DesktopEntry::try_from(p.path()).ok())
.or_default() .for_each(|entry| {
.push(Handler::assume_valid(file_name.clone())); let (file_name, mimes) = (entry.file_name, entry.mimes);
mimes.into_iter().for_each(|mime| {
map.entry(mime)
.or_default()
.push(Handler::assume_valid(file_name.clone()));
});
}); });
});
}); });
Ok(Self(map)) Ok(Self(map))