Browse Source

Search all xdg dirs

Getty Ritter 4 years ago
parent
commit
a5a073092f
2 changed files with 5 additions and 4 deletions
  1. 1 0
      Cargo.toml
  2. 4 4
      src/main.rs

+ 1 - 0
Cargo.toml

@@ -6,3 +6,4 @@ authors = ["Getty Ritter <dmesktop@infinitenegativeutility.com>"]
 [dependencies]
 failure = "0.1.1"
 xdg-desktop = { git = "https://git.gdritter.com/xdg-desktop/" }
+xdg = "*"

+ 4 - 4
src/main.rs

@@ -1,4 +1,5 @@
 #[macro_use] extern crate failure;
+extern crate xdg;
 extern crate xdg_desktop;
 
 use failure::Error;
@@ -57,10 +58,9 @@ fn run_command(cmd: &Option<String>) -> Result<(), Error> {
 
 fn fetch_entries() -> Result<Vec<xdg_desktop::DesktopEntry>, Error> {
     let mut entries = Vec::new();
-    for f in std::fs::read_dir("/usr/share/applications")? {
-        let f = f?;
-        if f.file_type()?.is_file() && f.path().extension().map_or(false, |e| e == "desktop") {
-            let mut f = std::fs::File::open(f.path())?;
+    for f in xdg::BaseDirectories::new()?.list_data_files("applications") {
+        if f.extension().map_or(false, |e| e == "desktop") {
+            let mut f = std::fs::File::open(f)?;
             match xdg_desktop::DesktopEntry::from_file(&mut f) {
                 Ok(e) => if e.is_application() {
                     entries.push(e);