Have icon_for_app_id run in a background thread

This should probably be faster, but it's good for things like this to
not block the UI thread regardless.

We could probably also cache for multiple apps with the same ID. Not
sure if there's a good way to detect changes to the icon for an app id
(Not really needed, probably?)
This commit is contained in:
Ian Douglas Scott 2025-01-21 09:24:19 -08:00
parent 0c9cabd21a
commit 8a4d4b6957
2 changed files with 36 additions and 10 deletions

View file

@ -5,13 +5,17 @@ use freedesktop_desktop_entry::DesktopEntry;
use itertools::Itertools;
use std::path::PathBuf;
pub fn icon_for_app_id(app_id: String) -> Option<PathBuf> {
Some(
desktop_info_for_app_ids(vec![app_id])
.into_iter()
.next()?
.icon,
)
pub async fn icon_for_app_id(app_id: String) -> Option<PathBuf> {
tokio::task::spawn_blocking(|| {
Some(
desktop_info_for_app_ids(vec![app_id])
.into_iter()
.next()?
.icon,
)
})
.await
.unwrap()
}
#[allow(dead_code)]