Skip to content

Commit

Permalink
feat: Allow user desktop overrides to hide applications
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
Eliasin committed Aug 27, 2023
1 parent 76af3eb commit f2ed816
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions plugins/applications/src/scrubber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub struct DesktopEntry {
pub icon: String,
pub term: bool,
pub offset: i64,
pub ignored: bool,
}

const FIELD_CODE_LIST: &[&str] = &[
Expand Down Expand Up @@ -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]") {
Expand All @@ -61,12 +63,17 @@ impl DesktopEntry {
}
}

if map.get("Type")? == &"Application"
&& match map.get("NoDisplay") {
Some(no_display) => !no_display.parse::<bool>().unwrap_or(true),
None => true,
}
{
let no_display = map
.get("NoDisplay")
.and_then(|no_display| no_display.parse::<bool>().ok())
.unwrap_or(false);
let hide = map
.get("Hidden")
.and_then(|hide| hide.parse::<bool>().ok())
.unwrap_or(false);
ignored = hide || no_display;

if map.get("Type")? == &"Application" {
Some(DesktopEntry {
exec: {
let mut exec = map.get("Exec")?.to_string();
Expand Down Expand Up @@ -97,6 +104,7 @@ impl DesktopEntry {
.map(|val| val.to_lowercase() == "true")
.unwrap_or(false),
offset: 0,
ignored,
})
} else {
None
Expand Down Expand Up @@ -153,6 +161,7 @@ impl DesktopEntry {
.map(|val| val.to_lowercase() == "true")
.unwrap_or(false),
offset: i as i64,
ignored,
})
}
}
Expand Down Expand Up @@ -246,6 +255,7 @@ pub fn scrubber(config: &Config) -> Result<Vec<(DesktopEntry, u64)>, Box<dyn std

Ok(entries
.into_iter()
.filter(|(_, entry)| !entry.ignored)
.enumerate()
.map(|(i, (_, entry))| (entry, i as u64))
.collect())
Expand Down

0 comments on commit f2ed816

Please sign in to comment.