From f2ed8163088221cdf5b70d82412fb3e14e84d6a9 Mon Sep 17 00:00:00 2001 From: Steven Pham Date: Sun, 27 Aug 2023 03:40:51 -0400 Subject: [PATCH] feat: Allow user desktop overrides to hide applications Hides applications which have both a system level desktop file and a user level desktop file where the user level desktop file sets either the `NoDisplay` or `Hidden` entries to `true`. This allows users to remove application entries without editing system level desktop files. Also add support for the `Hidden` desktop entry alongside `NoDisplay`. --- plugins/applications/src/scrubber.rs | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/plugins/applications/src/scrubber.rs b/plugins/applications/src/scrubber.rs index d72065c..52f5dcf 100644 --- a/plugins/applications/src/scrubber.rs +++ b/plugins/applications/src/scrubber.rs @@ -12,6 +12,7 @@ pub struct DesktopEntry { pub icon: String, pub term: bool, pub offset: i64, + pub ignored: bool, } const FIELD_CODE_LIST: &[&str] = &[ @@ -50,6 +51,7 @@ impl DesktopEntry { } let mut ret = Vec::new(); + let mut ignored = false; let entry = match new_sections.iter().find_map(|section| { if section[0].starts_with("[Desktop Entry]") { @@ -61,12 +63,17 @@ impl DesktopEntry { } } - if map.get("Type")? == &"Application" - && match map.get("NoDisplay") { - Some(no_display) => !no_display.parse::().unwrap_or(true), - None => true, - } - { + let no_display = map + .get("NoDisplay") + .and_then(|no_display| no_display.parse::().ok()) + .unwrap_or(false); + let hide = map + .get("Hidden") + .and_then(|hide| hide.parse::().ok()) + .unwrap_or(false); + ignored = hide || no_display; + + if map.get("Type")? == &"Application" { Some(DesktopEntry { exec: { let mut exec = map.get("Exec")?.to_string(); @@ -97,6 +104,7 @@ impl DesktopEntry { .map(|val| val.to_lowercase() == "true") .unwrap_or(false), offset: 0, + ignored, }) } else { None @@ -153,6 +161,7 @@ impl DesktopEntry { .map(|val| val.to_lowercase() == "true") .unwrap_or(false), offset: i as i64, + ignored, }) } } @@ -246,6 +255,7 @@ pub fn scrubber(config: &Config) -> Result, Box