Skip to content

Commit ab14658

Browse files
committed
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`.
1 parent 786f539 commit ab14658

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

plugins/applications/src/scrubber.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ pub struct DesktopEntry {
1212
pub icon: String,
1313
pub term: bool,
1414
pub offset: i64,
15+
pub ignored: bool,
1516
}
1617

1718
const FIELD_CODE_LIST: &[&str] = &[
@@ -50,6 +51,7 @@ impl DesktopEntry {
5051
}
5152

5253
let mut ret = Vec::new();
54+
let mut ignored = false;
5355

5456
let entry = match new_sections.iter().find_map(|section| {
5557
if section[0].starts_with("[Desktop Entry]") {
@@ -61,12 +63,17 @@ impl DesktopEntry {
6163
}
6264
}
6365

64-
if map.get("Type")? == &"Application"
65-
&& match map.get("NoDisplay") {
66-
Some(no_display) => !no_display.parse::<bool>().unwrap_or(true),
67-
None => true,
68-
}
69-
{
66+
let no_display = map
67+
.get("NoDisplay")
68+
.and_then(|no_display| no_display.parse::<bool>().ok())
69+
.unwrap_or(false);
70+
let hidden = map
71+
.get("Hidden")
72+
.and_then(|hidden| hidden.parse::<bool>().ok())
73+
.unwrap_or(false);
74+
ignored = hidden || no_display;
75+
76+
if map.get("Type")? == &"Application" {
7077
Some(DesktopEntry {
7178
exec: {
7279
let mut exec = map.get("Exec")?.to_string();
@@ -97,6 +104,7 @@ impl DesktopEntry {
97104
.map(|val| val.to_lowercase() == "true")
98105
.unwrap_or(false),
99106
offset: 0,
107+
ignored,
100108
})
101109
} else {
102110
None
@@ -153,6 +161,7 @@ impl DesktopEntry {
153161
.map(|val| val.to_lowercase() == "true")
154162
.unwrap_or(false),
155163
offset: i as i64,
164+
ignored,
156165
})
157166
}
158167
}
@@ -246,6 +255,7 @@ pub fn scrubber(config: &Config) -> Result<Vec<(DesktopEntry, u64)>, Box<dyn std
246255

247256
Ok(entries
248257
.into_iter()
258+
.filter(|(_, entry)| !entry.ignored)
249259
.enumerate()
250260
.map(|(i, (_, entry))| (entry, i as u64))
251261
.collect())

0 commit comments

Comments
 (0)