Search all xdg dirs
Getty Ritter
5 years ago
6 | 6 |
[dependencies]
|
7 | 7 |
failure = "0.1.1"
|
8 | 8 |
xdg-desktop = { git = "https://git.gdritter.com/xdg-desktop/" }
|
| 9 |
xdg = "*"
|
1 | 1 |
#[macro_use] extern crate failure;
|
| 2 |
extern crate xdg;
|
2 | 3 |
extern crate xdg_desktop;
|
3 | 4 |
|
4 | 5 |
use failure::Error;
|
|
57 | 58 |
|
58 | 59 |
fn fetch_entries() -> Result<Vec<xdg_desktop::DesktopEntry>, Error> {
|
59 | 60 |
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)?;
|
64 | 64 |
match xdg_desktop::DesktopEntry::from_file(&mut f) {
|
65 | 65 |
Ok(e) => if e.is_application() {
|
66 | 66 |
entries.push(e);
|