Use XDG vars to find desktop files
This commit is contained in:
@@ -22,6 +22,7 @@ Configuration currently happen through environment variables:
|
|||||||
- WLDASH_APP_OPENER: The command used to open normal applications. For sway, the recommended value is "swaymsg exec".
|
- WLDASH_APP_OPENER: The command used to open normal applications. For sway, the recommended value is "swaymsg exec".
|
||||||
- WLDASH_TERM_OPENER: The command used to open terminal applications.
|
- WLDASH_TERM_OPENER: The command used to open terminal applications.
|
||||||
- WLDASH_URL_OPENER: The command used to open a URL.
|
- WLDASH_URL_OPENER: The command used to open a URL.
|
||||||
|
- XDG_DATA_DIRS and XDG_DATA_HOME: Used to find the many `applications` folders that contain `desktop` files.
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
|
|||||||
+12
-10
@@ -73,17 +73,19 @@ impl PartialEq for Desktop {
|
|||||||
|
|
||||||
pub fn load_desktop_files() -> Vec<Desktop> {
|
pub fn load_desktop_files() -> Vec<Desktop> {
|
||||||
let home = env::var_os("HOME").unwrap().into_string().unwrap();
|
let home = env::var_os("HOME").unwrap().into_string().unwrap();
|
||||||
let paths = [
|
|
||||||
"/usr/share/applications".to_string(),
|
|
||||||
"/usr/local/share/applications".to_string(),
|
|
||||||
"/var/lib/flatpak/exports/share/applications".to_string(),
|
|
||||||
format!("{}/.local/share/applications", home).to_string(),
|
|
||||||
format!("{}/.local/share/flatpak/exports/share/applications", home).to_string(),
|
|
||||||
];
|
|
||||||
|
|
||||||
paths
|
let xdg_data_home = match env::var_os("XDG_DATA_HOME") {
|
||||||
.into_iter()
|
Some(s) => s.into_string().unwrap(),
|
||||||
.map(|p| Desktop::parse_dir(&p))
|
None => format!("{}/.local/share", home).to_string(),
|
||||||
|
};
|
||||||
|
let xdg_data_dirs = match env::var_os("XDG_DATA_DIRS") {
|
||||||
|
Some(s) => s.into_string().unwrap(),
|
||||||
|
None => "/usr/local/share:/usr/share".to_string(),
|
||||||
|
};
|
||||||
|
|
||||||
|
std::iter::once(xdg_data_home.as_str())
|
||||||
|
.chain(xdg_data_dirs.split(":"))
|
||||||
|
.map(|p| Desktop::parse_dir(&format!("{}/applications", p)))
|
||||||
.filter_map(Result::ok)
|
.filter_map(Result::ok)
|
||||||
.flatten()
|
.flatten()
|
||||||
.filter(|d| {
|
.filter(|d| {
|
||||||
|
|||||||
Reference in New Issue
Block a user