From 8cc0d28402d76c4fdd74613f4d984b5233876f11 Mon Sep 17 00:00:00 2001 From: Joshua Megnauth <48846352+joshuamegnauth54@users.noreply.github.com> Date: Mon, 30 Sep 2024 18:10:36 +0000 Subject: [PATCH] fix(desktop_entries): respect `NoDisplay` precedence Closes: pop-os/cosmic-epoch#905 `NoDisplay` allows applications or users to signal that an entry shouldn't be shown in menus. This is useful for entries that may launch an app in a certain way such as opening a specific menu or handling a MIME type. Some desktop environments use it to signal special cases. `NoDisplay` as well as `Hidden` allow user defined entries to hide apps. User defined desktop entries should override the system's applications, but the old logic continued parsing entries from all locations instead of stopping at a user override. --- plugins/src/desktop_entries/mod.rs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/plugins/src/desktop_entries/mod.rs b/plugins/src/desktop_entries/mod.rs index c43c52e..6015be4 100644 --- a/plugins/src/desktop_entries/mod.rs +++ b/plugins/src/desktop_entries/mod.rs @@ -76,9 +76,15 @@ impl App { let desktop_entries = DesktopEntry::from_paths(paths, &locales) .filter_map(|de| { de.ok().and_then(|de| { - if deduplicator.contains(de.appid.as_ref()) { + // Treat Flatpak and system apps differently in the cache so they don't + // override each other + let appid = de.flatpak().unwrap_or_else(|| de.appid.as_ref()); + if deduplicator.contains(appid) { return None; } + // Always cache already visited entries to allow overriding entries e.g. by + // placing a modified copy in ~/.local/share/applications/ + deduplicator.insert(appid.to_owned()); if de.name(&self.locales).is_none() { return None; @@ -128,12 +134,14 @@ impl App { return None; } } - } else { - if de.no_display() { - return None; - } } - deduplicator.insert(de.appid.to_string()); + // Treat `OnlyShowIn` as an override otherwise do not show if `NoDisplay` is true + // Some desktop environments set `OnlyShowIn` and `NoDisplay = true` to + // indicate special entries + else if de.no_display() { + return None; + } + Some(de) }) })