improv api
This commit is contained in:
parent
1c377cc974
commit
e1e26f678b
1 changed files with 23 additions and 31 deletions
|
|
@ -109,9 +109,10 @@ fn match_entry(id: &str, de: &DesktopEntry) -> f32 {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn load_applications_for_app_ids<'a, 'b>(
|
/// The result will be in the same order of `app_ids`
|
||||||
|
pub fn load_applications_for_app_ids<'a, I: AsRef<str>>(
|
||||||
locale: impl Into<Option<&'a str>>,
|
locale: impl Into<Option<&'a str>>,
|
||||||
app_ids: impl Iterator<Item = &'b str>,
|
app_ids: impl Iterator<Item = I>,
|
||||||
fill_missing_ones: bool,
|
fill_missing_ones: bool,
|
||||||
include_no_display: bool,
|
include_no_display: bool,
|
||||||
) -> Vec<DesktopEntryData> {
|
) -> Vec<DesktopEntryData> {
|
||||||
|
|
@ -131,7 +132,6 @@ pub fn load_applications_for_app_ids<'a, 'b>(
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
let mut applications = Vec::new();
|
let mut applications = Vec::new();
|
||||||
let mut missing = Vec::new();
|
|
||||||
|
|
||||||
let locale = locale.into();
|
let locale = locale.into();
|
||||||
|
|
||||||
|
|
@ -144,7 +144,7 @@ pub fn load_applications_for_app_ids<'a, 'b>(
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
let score = match_entry(id, de);
|
let score = match_entry(id.as_ref(), de);
|
||||||
|
|
||||||
match max_score {
|
match max_score {
|
||||||
Some((prev_max_score, _)) => {
|
Some((prev_max_score, _)) => {
|
||||||
|
|
@ -163,38 +163,30 @@ pub fn load_applications_for_app_ids<'a, 'b>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut add_missing = false;
|
let mut has_matched = false;
|
||||||
match max_score {
|
if let Some((max_score, de)) = max_score {
|
||||||
Some((max_score, de)) => {
|
|
||||||
let entropy = max_score - second_max_score;
|
let entropy = max_score - second_max_score;
|
||||||
|
|
||||||
if max_score > 0.7 || entropy > 0.2 && max_score > 0.2 {
|
// println!("{id}: {max_score}:{entropy}: {}", de.appid);
|
||||||
|
|
||||||
|
if max_score > 0.7 || entropy > 0.15 && max_score > 0.2 {
|
||||||
applications.push(DesktopEntryData::from_desktop_entry(
|
applications.push(DesktopEntryData::from_desktop_entry(
|
||||||
locale,
|
locale,
|
||||||
Some(de.path.to_path_buf()),
|
Some(de.path.to_path_buf()),
|
||||||
de,
|
de,
|
||||||
));
|
));
|
||||||
} else {
|
has_matched = true;
|
||||||
add_missing = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
None => {
|
|
||||||
add_missing = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if fill_missing_ones && add_missing {
|
if fill_missing_ones && !has_matched {
|
||||||
missing.push(id);
|
applications.push(DesktopEntryData {
|
||||||
}
|
id: id.as_ref().to_string(),
|
||||||
}
|
name: id.as_ref().to_string(),
|
||||||
|
|
||||||
if fill_missing_ones {
|
|
||||||
applications.extend(missing.into_iter().map(|app_id| DesktopEntryData {
|
|
||||||
id: app_id.to_string(),
|
|
||||||
name: app_id.to_string(),
|
|
||||||
icon: IconSource::default(),
|
icon: IconSource::default(),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}));
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
applications
|
applications
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue