From 6a424bf901d522996555298e87a1b5fc1898c8c1 Mon Sep 17 00:00:00 2001 From: Christian Friedow Date: Sun, 31 Mar 2024 16:21:58 +0200 Subject: [PATCH 1/9] =?UTF-8?q?=F0=9F=90=9B=20filter=20hidden=20entries,?= =?UTF-8?q?=20entries=20with=20type=20!=3D=20application=20and=20fix=20onl?= =?UTF-8?q?yshowin?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/src/plugin/applications.rs | 33 +++++++++++++++++++------------ 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/client/src/plugin/applications.rs b/client/src/plugin/applications.rs index e9d2f18..13de89c 100644 --- a/client/src/plugin/applications.rs +++ b/client/src/plugin/applications.rs @@ -58,6 +58,25 @@ fn read_desktop_entry(path: &std::path::PathBuf) -> anyhow::Result bool { + if desktop_entry.type_() != Some("Application") { + return false; + } + + if desktop_entry.desktop_entry("Hidden") == Some("true") { + return false; + } + + if desktop_entry.no_display() { + return false; + } + + // filter entries where Exec == false + if let Some(exec) = desktop_entry.exec() { + if exec.to_ascii_lowercase() == "false" { + return false; + } + } + let desktop = std::env::var("XDG_CURRENT_DESKTOP").unwrap_or(String::from("sway")); // filter entries where NotShowIn == current desktop if let Some(not_show_in) = desktop_entry.desktop_entry("NotShowIn") { @@ -72,19 +91,7 @@ fn is_visible(desktop_entry: &freedesktop_desktop_entry::DesktopEntry) -> bool { if let Some(only_show_in) = desktop_entry.only_show_in() { let only_show_in_desktops = only_show_in.to_ascii_lowercase(); - if !only_show_in_desktops.split(';').any(|d| d == desktop) { - return false; - } - } - - // filter entries where NoDisplay != true - if desktop_entry.no_display() { - return false; - } - - // filter entries where Exec == false - if let Some(exec) = desktop_entry.exec() { - if exec.to_ascii_lowercase() == "false" { + if !only_show_in_desktops.split(';').all(|d| d != desktop) { return false; } } From 0817218375d3fe6d16a9c62caf06ccbefd9e347b Mon Sep 17 00:00:00 2001 From: Christian Friedow Date: Mon, 1 Apr 2024 14:05:06 +0200 Subject: [PATCH 2/9] =?UTF-8?q?=F0=9F=90=9B=20fix=20terminal=20application?= =?UTF-8?q?=20launching?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/src/plugin/applications.rs | 97 ++++++++++++++++++++----------- 1 file changed, 64 insertions(+), 33 deletions(-) diff --git a/client/src/plugin/applications.rs b/client/src/plugin/applications.rs index 13de89c..f656d46 100644 --- a/client/src/plugin/applications.rs +++ b/client/src/plugin/applications.rs @@ -5,33 +5,34 @@ pub struct ApplicationsPlugin { entries: Vec, } -fn read_desktop_entry(path: &std::path::PathBuf) -> anyhow::Result { - let pathstr = path.to_str().unwrap_or(""); - let bytes = std::fs::read_to_string(path)?; - let desktop_entry = freedesktop_desktop_entry::DesktopEntry::decode(path, &bytes)?; +fn read_desktop_entry( + path: &std::path::PathBuf, + terminal_command: Option, +) -> Option { + let bytes_result = std::fs::read_to_string(path); + if let Err(reading_error) = bytes_result { + log::warn!(target: "applications", "Desktop entry at path '{:?}' will be hidden because reading it failed: {}", path, reading_error); + return None; + } + let bytes = bytes_result.unwrap(); + + let desktop_entry_result = freedesktop_desktop_entry::DesktopEntry::decode(path, &bytes); + if let Err(parsing_error) = desktop_entry_result { + log::warn!(target: "applications", "Desktop entry at path '{:?}' will be hidden because parsing it failed: {}", path, parsing_error); + return None; + } + let desktop_entry = desktop_entry_result.unwrap(); if !is_visible(&desktop_entry) { - return Err(anyhow::anyhow!( - "Desktop entry at path '{}' is hidden.", - pathstr - )); + log::info!(target: "applications", "Desktop entry at path '{:?}' will be hidden because of its properties.", path); + return None; } let locale = std::env::var("LANG").unwrap_or(String::from("en_US")); - let title = desktop_entry - .name(Some(&locale)) - .context(format!( - "Desktop entry at path '{}' is missing the 'name' field.", - pathstr - ))? - .to_string(); - - let cmd = desktop_entry - .exec() - .context(format!( - "Desktop entry at path '{}' is missing the 'exec' field.", - pathstr - ))? + let title = desktop_entry.name(Some(&locale))?.to_string(); + + let mut cmd: Vec = desktop_entry + .exec()? .split_ascii_whitespace() .filter_map(|s| { if s.starts_with('%') { @@ -42,13 +43,23 @@ fn read_desktop_entry(path: &std::path::PathBuf) -> anyhow::Result