fix(desktop-entries): Hide entry if it doesn't match DE requirement

This commit is contained in:
Michael Aaron Murphy 2021-08-18 14:38:20 +02:00
parent a378194f57
commit 66fdf397cb

View file

@ -97,23 +97,29 @@ impl<W: AsyncWrite + Unpin> App<W> {
for (src, path) in DesktopIter::new(default_paths()) { for (src, path) in DesktopIter::new(default_paths()) {
if let Ok(bytes) = std::fs::read_to_string(&path) { if let Ok(bytes) = std::fs::read_to_string(&path) {
if let Ok(entry) = DesktopEntry::decode(&path, &bytes) { if let Ok(entry) = DesktopEntry::decode(&path, &bytes) {
if entry.no_display() { // If defined to only show in a specific DE, avoid showing it if invalid.
let matched = current let mut desktop_matched = false;
.as_ref() if let Some(desktops) = entry.only_show_in() {
.zip(entry.only_show_in()) desktop_matched = match current.as_ref() {
.map(|(current, desktops)| { Some(current) => desktops
!desktops .to_ascii_lowercase()
.to_ascii_lowercase() .split(';')
.split(';') .any(|desktop| current.iter().any(|c| *c == desktop)),
.any(|desktop| current.iter().any(|c| *c == desktop)) None => false,
}) };
.unwrap_or(true);
if matched || entry.name(None).map_or(false, |v| v == "GNOME Shell") { if !desktop_matched {
continue; continue;
} }
} }
if entry.no_display()
&& (!desktop_matched
|| entry.name(None).map_or(false, |v| v == "GNOME Shell"))
{
continue;
}
if let Some((name, exec)) = entry.name(locale).zip(entry.exec()) { if let Some((name, exec)) = entry.name(locale).zip(entry.exec()) {
if let Some(exec) = exec.split_ascii_whitespace().next() { if let Some(exec) = exec.split_ascii_whitespace().next() {
let item = Item { let item = Item {
@ -218,7 +224,9 @@ impl<W: AsyncWrite + Unpin> App<W> {
for search_interest in items.drain(..) { for search_interest in items.drain(..) {
let search_interest = search_interest.to_ascii_lowercase(); let search_interest = search_interest.to_ascii_lowercase();
let append = search_interest.starts_with(&*query) let append = search_interest.starts_with(&*query)
|| query.split_ascii_whitespace().any(|query| search_interest.contains(&*query)) || query
.split_ascii_whitespace()
.any(|query| search_interest.contains(&*query))
|| strsim::damerau_levenshtein(&*query, &*search_interest) < 3; || strsim::damerau_levenshtein(&*query, &*search_interest) < 3;
if append { if append {