chore: update fde

This commit is contained in:
Ashley Wulber 2025-03-12 18:22:01 -04:00 committed by Michael Murphy
parent 617de4dc95
commit 26ea70a6bd
2 changed files with 24 additions and 19 deletions

View file

@ -121,7 +121,7 @@ zbus = { version = "4.2.1", default-features = false, optional = true }
[target.'cfg(unix)'.dependencies] [target.'cfg(unix)'.dependencies]
freedesktop-icons = { package = "cosmic-freedesktop-icons", git = "https://github.com/pop-os/freedesktop-icons" } freedesktop-icons = { package = "cosmic-freedesktop-icons", git = "https://github.com/pop-os/freedesktop-icons" }
freedesktop-desktop-entry = { version = "0.5.1", optional = true } freedesktop-desktop-entry = { version = "0.7.8", optional = true }
shlex = { version = "1.3.0", optional = true } shlex = { version = "1.3.0", optional = true }
[dependencies.cosmic-theme] [dependencies.cosmic-theme]

View file

@ -107,7 +107,7 @@ pub fn load_applications_for_app_ids<'a, 'b>(
true true
// Fallback: If the name matches... // Fallback: If the name matches...
} else if let Some(i) = app_ids.iter().position(|id| { } else if let Some(i) = app_ids.iter().position(|id| {
de.name(None) de.name::<&str>(&[])
.map(|n| n.to_lowercase() == id.to_lowercase()) .map(|n| n.to_lowercase() == id.to_lowercase())
.unwrap_or_default() .unwrap_or_default()
}) { }) {
@ -134,11 +134,12 @@ pub fn load_applications_filtered<'a, F: FnMut(&DesktopEntry) -> bool>(
mut filter: F, mut filter: F,
) -> Vec<DesktopEntryData> { ) -> Vec<DesktopEntryData> {
let locale = locale.into(); let locale = locale.into();
let locale_arr: Option<Vec<_>> = locale.map(|l| vec![l]);
freedesktop_desktop_entry::Iter::new(freedesktop_desktop_entry::default_paths()) freedesktop_desktop_entry::Iter::new(freedesktop_desktop_entry::default_paths())
.filter_map(|path| { .filter_map(|path| {
std::fs::read_to_string(&path).ok().and_then(|input| { DesktopEntry::from_path(&path, locale_arr.as_deref())
DesktopEntry::decode(&path, &input).ok().and_then(|de| { .ok()
.and_then(|de| {
if !filter(&de) { if !filter(&de) {
return None; return None;
} }
@ -149,7 +150,6 @@ pub fn load_applications_filtered<'a, F: FnMut(&DesktopEntry) -> bool>(
de, de,
)) ))
}) })
})
}) })
.collect() .collect()
} }
@ -160,11 +160,12 @@ pub fn load_desktop_file<'a>(
path: impl AsRef<Path>, path: impl AsRef<Path>,
) -> Option<DesktopEntryData> { ) -> Option<DesktopEntryData> {
let path = path.as_ref(); let path = path.as_ref();
std::fs::read_to_string(path).ok().and_then(|input| { let locale = locale.into();
DesktopEntry::decode(path, &input) let locale_arr: Option<Vec<_>> = locale.clone().map(|l| vec![l]);
.ok()
.map(|de| DesktopEntryData::from_desktop_entry(locale, PathBuf::from(path), de)) DesktopEntry::from_path(&path, locale_arr.as_deref())
}) .ok()
.map(|de| DesktopEntryData::from_desktop_entry(locale, PathBuf::from(path), de))
} }
#[cfg(not(windows))] #[cfg(not(windows))]
@ -175,14 +176,14 @@ impl DesktopEntryData {
de: DesktopEntry, de: DesktopEntry,
) -> DesktopEntryData { ) -> DesktopEntryData {
let locale = locale.into(); let locale = locale.into();
let locale_arr: Option<Vec<_>> = locale.map(|l| vec![l]);
let name = de let name = de
.name(locale) .name(locale_arr.as_deref().unwrap_or_default())
.unwrap_or(Cow::Borrowed(de.appid)) .unwrap_or(Cow::Borrowed(&de.appid))
.to_string(); .to_string();
// check if absolute path exists and otherwise treat it as a name // check if absolute path exists and otherwise treat it as a name
let icon = de.icon().unwrap_or(de.appid); let icon = de.icon().unwrap_or(&de.appid);
let icon_path = Path::new(icon); let icon_path = Path::new(icon);
let icon = if icon_path.is_absolute() && icon_path.exists() { let icon = if icon_path.is_absolute() && icon_path.exists() {
IconSource::Path(icon_path.into()) IconSource::Path(icon_path.into())
@ -200,16 +201,20 @@ impl DesktopEntryData {
categories: de categories: de
.categories() .categories()
.unwrap_or_default() .unwrap_or_default()
.split_terminator(';') .into_iter()
.map(std::string::ToString::to_string) .map(std::string::ToString::to_string)
.collect(), .collect(),
desktop_actions: de desktop_actions: de
.actions() .actions()
.map(|actions| { .map(|actions| {
actions actions
.split(';') .into_iter()
.filter_map(|action| { .filter_map(|action| {
let name = de.action_entry_localized(action, "Name", locale); let name = de.action_entry_localized(
action,
"Name",
locale_arr.as_deref().unwrap_or_default(),
);
let exec = de.action_entry(action, "Exec"); let exec = de.action_entry(action, "Exec");
if let (Some(name), Some(exec)) = (name, exec) { if let (Some(name), Some(exec)) = (name, exec) {
Some(DesktopAction { Some(DesktopAction {
@ -227,7 +232,7 @@ impl DesktopEntryData {
.mime_type() .mime_type()
.map(|mime_types| { .map(|mime_types| {
mime_types mime_types
.split_terminator(';') .into_iter()
.filter_map(|mime_type| mime_type.parse::<Mime>().ok()) .filter_map(|mime_type| mime_type.parse::<Mime>().ok())
.collect::<Vec<_>>() .collect::<Vec<_>>()
}) })