Skip to content

Commit 58a8f2d

Browse files
ellieplayswowjacobgkau
authored andcommitted
Updating cosmic_toplevel plugin to check for an exact appid match, falling back to best match instead
1 parent 87bb6c6 commit 58a8f2d

File tree

1 file changed

+36
-15
lines changed
  • plugins/src/cosmic_toplevel

1 file changed

+36
-15
lines changed

plugins/src/cosmic_toplevel/mod.rs

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use pop_launcher::{
2121
};
2222
use std::borrow::Cow;
2323
use std::iter;
24+
use std::time::Instant;
2425
use tokio::io::{AsyncWrite, AsyncWriteExt};
2526

2627
use self::toplevel_handler::{toplevel_handler, ToplevelAction};
@@ -194,21 +195,41 @@ impl<W: AsyncWrite + Unpin> App<W> {
194195
.chain(iter::once(info.title.as_str()))
195196
.collect::<Vec<_>>();
196197

197-
fde::matching::get_best_match(
198-
&window_words,
199-
&self.desktop_entries,
200-
fde::matching::MatchAppIdOptions::default(),
201-
)
202-
.and_then(|de| {
203-
let score =
204-
fde::matching::get_entry_score(&query, de, &self.locales, &window_words);
205-
206-
if score > 0.8 {
207-
Some(de)
208-
} else {
209-
None
210-
}
211-
})
198+
// if there's an exact appid match, use that instead
199+
let exact_appid_match = self
200+
.desktop_entries
201+
.iter()
202+
.find(|de| de.appid == info.app_id);
203+
if exact_appid_match.is_some()
204+
&& fde::matching::get_entry_score(
205+
&query,
206+
exact_appid_match.unwrap(),
207+
&self.locales,
208+
&window_words,
209+
) > 0.8
210+
{
211+
exact_appid_match
212+
} else {
213+
fde::matching::get_best_match(
214+
&window_words,
215+
&self.desktop_entries,
216+
fde::matching::MatchAppIdOptions::default(),
217+
)
218+
.and_then(|de| {
219+
let score = fde::matching::get_entry_score(
220+
&query,
221+
de,
222+
&self.locales,
223+
&window_words,
224+
);
225+
226+
if score > 0.8 {
227+
Some(de)
228+
} else {
229+
None
230+
}
231+
})
232+
}
212233
};
213234

214235
if let Some(de) = entry {

0 commit comments

Comments
 (0)