ltrait_source_desktop/
lib.rs1use ltrait::{source::Source, tokio_stream};
2
3pub mod icon;
4
5#[derive(Debug, thiserror::Error)]
6pub enum DesktopError {
7 #[error("Failed to find icon of {0}")]
9 NoIcon(String),
10 #[error("Failed to open file: {0}")]
11 OpenFile(#[source] std::io::Error),
12 #[error("Failed to decode the image: {0}")]
13 ImageDecode(#[source] image::ImageError),
14}
15
16#[derive(Debug, Clone)]
17pub struct DesktopEntry {
18 pub entry: freedesktop_desktop_entry::DesktopEntry,
19}
20
21impl DesktopEntry {
22 pub fn icon(&self) -> Option<String> {
23 self.entry.icon().and_then(|n| icon::lookup(n).ok())
24 }
25}
26
27pub fn new<'a>() -> Result<Source<'a, DesktopEntry>, DesktopError> {
29 use freedesktop_desktop_entry::{Iter, default_paths};
30 let entries = Iter::new(default_paths())
31 .entries::<String>(None)
32 .map(|e| DesktopEntry { entry: e });
33
34 Ok(Box::pin(tokio_stream::iter(entries)))
35}