From 58a8f2db649098463b183c09cfa5897db217e2cf Mon Sep 17 00:00:00 2001 From: ellieplayswow <164806095+ellieplayswow@users.noreply.github.com> Date: Fri, 21 Mar 2025 22:39:55 +0000 Subject: [PATCH] Updating cosmic_toplevel plugin to check for an exact appid match, falling back to best match instead --- plugins/src/cosmic_toplevel/mod.rs | 49 +++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 14 deletions(-) diff --git a/plugins/src/cosmic_toplevel/mod.rs b/plugins/src/cosmic_toplevel/mod.rs index f299697..da38a6d 100644 --- a/plugins/src/cosmic_toplevel/mod.rs +++ b/plugins/src/cosmic_toplevel/mod.rs @@ -21,6 +21,7 @@ use pop_launcher::{ }; use std::borrow::Cow; use std::iter; +use std::time::Instant; use tokio::io::{AsyncWrite, AsyncWriteExt}; use self::toplevel_handler::{toplevel_handler, ToplevelAction}; @@ -194,21 +195,41 @@ impl App { .chain(iter::once(info.title.as_str())) .collect::>(); - fde::matching::get_best_match( - &window_words, - &self.desktop_entries, - fde::matching::MatchAppIdOptions::default(), - ) - .and_then(|de| { - let score = - fde::matching::get_entry_score(&query, de, &self.locales, &window_words); + // if there's an exact appid match, use that instead + let exact_appid_match = self + .desktop_entries + .iter() + .find(|de| de.appid == info.app_id); + if exact_appid_match.is_some() + && fde::matching::get_entry_score( + &query, + exact_appid_match.unwrap(), + &self.locales, + &window_words, + ) > 0.8 + { + exact_appid_match + } else { + fde::matching::get_best_match( + &window_words, + &self.desktop_entries, + fde::matching::MatchAppIdOptions::default(), + ) + .and_then(|de| { + let score = fde::matching::get_entry_score( + &query, + de, + &self.locales, + &window_words, + ); - if score > 0.8 { - Some(de) - } else { - None - } - }) + if score > 0.8 { + Some(de) + } else { + None + } + }) + } }; if let Some(de) = entry {