parent
7450393e97
commit
60799fb544
3 changed files with 41 additions and 15 deletions
7
Cargo.lock
generated
7
Cargo.lock
generated
|
|
@ -1269,6 +1269,7 @@ dependencies = [
|
|||
"tracing",
|
||||
"tracing-subscriber",
|
||||
"urlencoding",
|
||||
"ward",
|
||||
"zbus",
|
||||
"zvariant",
|
||||
]
|
||||
|
|
@ -1860,6 +1861,12 @@ version = "1.1.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9d5b2c62b4012a3e1eca5a7e077d13b3bf498c4073e33ccd58626607748ceeca"
|
||||
|
||||
[[package]]
|
||||
name = "ward"
|
||||
version = "2.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1cbcd609d606e1307a1530061482ed2ee3fc9963128990238cefb2013127b61e"
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.10.2+wasi-snapshot-preview1"
|
||||
|
|
|
|||
|
|
@ -29,3 +29,4 @@ tracing-subscriber = "0.2"
|
|||
urlencoding = "2"
|
||||
zbus = "1"
|
||||
zvariant = "=2.6" # Restrict for 1.47
|
||||
ward = "2.1.0"
|
||||
|
|
|
|||
|
|
@ -94,26 +94,44 @@ impl<W: AsyncWrite + Unpin> App<W> {
|
|||
for (src, path) in DesktopIter::new(default_paths()) {
|
||||
if let Ok(bytes) = std::fs::read_to_string(&path) {
|
||||
if let Ok(entry) = DesktopEntry::decode(&path, &bytes) {
|
||||
// If defined to only show in a specific DE, avoid showing it if invalid.
|
||||
let mut desktop_matched = false;
|
||||
if let Some(desktops) = entry.only_show_in() {
|
||||
desktop_matched = match current.as_ref() {
|
||||
Some(current) => desktops
|
||||
.to_ascii_lowercase()
|
||||
.split(';')
|
||||
.any(|desktop| current.iter().any(|c| *c == desktop)),
|
||||
None => false,
|
||||
};
|
||||
// Do not show if our desktop is defined in `NotShowIn`.
|
||||
if let Some(not_show_in) = entry.desktop_entry("NotShowIn") {
|
||||
let current = ward::ward!(current.as_ref(), else { continue });
|
||||
|
||||
if !desktop_matched {
|
||||
let matched = not_show_in
|
||||
.to_ascii_lowercase()
|
||||
.split(';')
|
||||
.any(|desktop| current.iter().any(|c| *c == desktop));
|
||||
|
||||
if matched {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if entry.no_display()
|
||||
&& (!desktop_matched
|
||||
|| entry.name(None).map_or(false, |v| v == "GNOME Shell"))
|
||||
{
|
||||
// Track this condition so that we can override `NoDisplay` if this is true.
|
||||
let mut only_show_in = false;
|
||||
|
||||
// Do not show if our desktop is not defined in `OnlyShowIn`.
|
||||
if let Some(desktops) = entry.only_show_in() {
|
||||
let current = ward::ward!(current.as_ref(), else { continue });
|
||||
|
||||
only_show_in = desktops
|
||||
.to_ascii_lowercase()
|
||||
.split(';')
|
||||
.any(|desktop| current.iter().any(|c| *c == desktop));
|
||||
|
||||
if !only_show_in {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// Avoid showing the GNOME Shell entry entirely
|
||||
if entry.name(None).map_or(false, |v| v == "GNOME Shell") {
|
||||
continue;
|
||||
}
|
||||
|
||||
// And also avoid showing anything that's set as `NoDisplay`
|
||||
if !only_show_in && entry.no_display() {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue