This commit is contained in:
Javier Feliz 2025-09-03 01:50:08 -04:00
parent 8aa0fb0943
commit 69c213f9ba
2 changed files with 48 additions and 9 deletions

View File

@ -5,7 +5,7 @@ use std::env;
use std::path::{Path, PathBuf};
#[derive(Debug)]
struct DesktopEntry {
pub struct DesktopEntry {
id: String,
name: String,
generic_name: Option<glib::GString>,
@ -17,6 +17,12 @@ struct DesktopEntry {
is_terminal_app: bool,
}
impl DesktopEntry {
pub fn path(&self) -> PathBuf {
self.path.clone()
}
}
impl LauncherListItem for DesktopEntry {
fn title(&self) -> String {
return self.name.to_owned();
@ -89,8 +95,8 @@ fn get_desktop_files() -> Vec<PathBuf> {
return files;
}
pub fn all() -> Vec<Box<dyn LauncherListItem>> {
let mut entries: Vec<Box<dyn LauncherListItem>> = Vec::new();
pub fn get_desktop_entries() -> Vec<DesktopEntry> {
let mut entries = Vec::new();
for f in get_desktop_files() {
if let Some(info) = DesktopAppInfo::from_filename(&f) {
@ -110,9 +116,19 @@ pub fn all() -> Vec<Box<dyn LauncherListItem>> {
is_terminal_app: info.boolean("Terminal"),
};
entries.push(Box::new(de));
entries.push(de);
}
}
entries
}
pub fn all() -> Vec<Box<dyn LauncherListItem>> {
let mut entries: Vec<Box<dyn LauncherListItem>> = Vec::new();
for e in get_desktop_entries() {
entries.push(Box::new(e));
}
entries
}

View File

@ -29,16 +29,33 @@ impl ListItem {
fn create_widget(&self) -> GtkBox {
let container = GtkBox::new(Orientation::Horizontal, 10);
let image = Image::new();
image.set_pixel_size(50);
image.set_icon_name(Some(&self.icon));
// let icon = if self.icon.eq("com.discordapp.Discord")
// || self.icon.eq("preferences-desktop-theme")
// || self.icon.eq("solaar")
// || self.icon.eq("kvantum")
// {
// println!("Failed: {}", self.icon);
// gio::Icon::for_string("vscode")
// } else {
// let x = String::from(self.icon.clone());
// gio::Icon::for_string(&x)
// };
// // let icon = gio::Icon::for_string("kvantum");
// let image: Image = match icon {
// Ok(ic) => Image::from_gicon(&ic),
// Err(_) => Image::from_icon_name("vscode"),
// };
// let image = Image::from_icon_name("vscode");
let image = gtk::Image::from_icon_name(&self.icon);
image.set_pixel_size(32);
// image.set_icon_name(Some("application-x-executable")); // Safe fallback
let label = Label::new(Some(&self.text));
label.set_xalign(0.0);
// container.append(&image);
container.append(&image);
container.append(&label);
println!("Icon: {}", self.icon);
container
}
}
@ -154,4 +171,10 @@ fn main() {
});
app.run();
// for e in drun::get_desktop_entries() {
// println!("---");
// println!("Icon: {}", e.icon());
// println!("Path: {}", e.path().to_string_lossy());
// println!("---");
// }
}