Skip to content

Commit

Permalink
🐛 XDG_DATA_HOME now has a higher priority then XDG_DATA_DIRS when rea…
Browse files Browse the repository at this point in the history
…ding desktop entries
  • Loading branch information
friedow committed Apr 3, 2024
1 parent 49a2c91 commit 15dfa5d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ chrono = "0.4.33"

# applications plugin
freedesktop-desktop-entry = "0.5.1"
xdg = "2.5.2"

# sway_windows plugin
swayipc = "3.0.1"
Expand Down
12 changes: 10 additions & 2 deletions client/src/plugin/applications.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,15 @@ fn path_name(path: &std::path::PathBuf) -> String {
name_option.unwrap().to_string()
}

fn data_dirs() -> Vec<std::path::PathBuf> {
let base_dirs = xdg::BaseDirectories::new().unwrap();
let mut data_dirs: Vec<std::path::PathBuf> = vec![];
data_dirs.push(base_dirs.get_data_home());
data_dirs.append(&mut base_dirs.get_data_dirs());

data_dirs.iter().map(|d| d.join("applications")).collect()
}

impl Plugin for ApplicationsPlugin {
fn new() -> Self {
Self { entries: vec![] }
Expand Down Expand Up @@ -179,8 +188,7 @@ impl Plugin for ApplicationsPlugin {
self.entries.clear();

let mut paths: Vec<std::path::PathBuf> =
freedesktop_desktop_entry::Iter::new(freedesktop_desktop_entry::default_paths())
.collect();
freedesktop_desktop_entry::Iter::new(data_dirs()).collect();

paths.sort_by_key(path_name);
paths.dedup_by_key(|path| path_name(path));
Expand Down

0 comments on commit 15dfa5d

Please sign in to comment.