gdritter repos dmesktop / master
Search all xdg dirs Getty Ritter 5 years ago
2 changed file(s) with 5 addition(s) and 4 deletion(s). Collapse all Expand all
66 [dependencies]
77 failure = "0.1.1"
88 xdg-desktop = { git = "https://git.gdritter.com/xdg-desktop/" }
9 xdg = "*"
11 #[macro_use] extern crate failure;
2 extern crate xdg;
23 extern crate xdg_desktop;
34
45 use failure::Error;
5758
5859 fn fetch_entries() -> Result<Vec<xdg_desktop::DesktopEntry>, Error> {
5960 let mut entries = Vec::new();
60 for f in std::fs::read_dir("/usr/share/applications")? {
61 let f = f?;
62 if f.file_type()?.is_file() && f.path().extension().map_or(false, |e| e == "desktop") {
63 let mut f = std::fs::File::open(f.path())?;
61 for f in xdg::BaseDirectories::new()?.list_data_files("applications") {
62 if f.extension().map_or(false, |e| e == "desktop") {
63 let mut f = std::fs::File::open(f)?;
6464 match xdg_desktop::DesktopEntry::from_file(&mut f) {
6565 Ok(e) => if e.is_application() {
6666 entries.push(e);