diff --git a/plugins/src/pop_shell/mod.rs b/plugins/src/pop_shell/mod.rs index 2c7303e..9f9a625 100644 --- a/plugins/src/pop_shell/mod.rs +++ b/plugins/src/pop_shell/mod.rs @@ -2,10 +2,11 @@ // Copyright © 2021 System76 use crate::*; +use freedesktop_desktop_entry as fde; use futures_lite::{AsyncWrite, AsyncWriteExt, StreamExt}; use pop_launcher::*; use serde::{Deserialize, Serialize}; -use std::convert::TryFrom; +use std::{convert::TryFrom, fs, path::PathBuf}; use zbus::Connection; use zvariant::{Signature, Type}; @@ -17,11 +18,12 @@ struct Item { entity: (u32, u32), name: String, description: String, + desktop_entry: String, } impl Type for Item { fn signature() -> Signature<'static> { - Signature::try_from("((uu)ss)").expect("bad dbus signature") + Signature::try_from("((uu)sss)").expect("bad dbus signature") } } @@ -56,6 +58,7 @@ pub async fn main() { } struct App { + desktop_entries: Vec<(fde::PathSource, PathBuf)>, entries: Vec, connection: Connection, tx: W, @@ -64,6 +67,7 @@ struct App { impl App { fn new(connection: Connection, tx: W) -> Self { Self { + desktop_entries: fde::Iter::new(fde::default_paths()).collect(), entries: Vec::new(), connection, tx, @@ -111,13 +115,33 @@ impl App { continue; } + let mut icon_name = Cow::Borrowed("application-x-executable"); + + if let Some(desktop_entry) = item.desktop_entry.strip_suffix(".desktop") { + for (_, path) in &self.desktop_entries { + if let Some(name) = path.file_stem() { + if desktop_entry == name { + if let Ok(data) = fs::read_to_string(path) { + if let Ok(entry) = fde::DesktopEntry::decode(path, &data) { + if let Some(icon) = entry.icon() { + icon_name = Cow::Owned(icon.to_owned()); + } + } + } + + break; + } + } + } + } + send( &mut self.tx, PluginResponse::Append(PluginSearchResult { id: id as u32, name: item.name.clone(), description: item.description.clone(), - icon: Some(IconSource::Window(item.entity)), + icon: Some(IconSource::Name(icon_name)), window: Some(item.entity), ..Default::default() }),