From fa0af222f835cac12f1822ff5be6b1ac4d0c976f Mon Sep 17 00:00:00 2001 From: Javier Feliz Date: Wed, 3 Sep 2025 19:00:43 -0400 Subject: [PATCH] WIP --- src/drun/mod.rs | 78 ++++++++++++------------------------------------- src/main.rs | 58 ++++++++++-------------------------- 2 files changed, 33 insertions(+), 103 deletions(-) diff --git a/src/drun/mod.rs b/src/drun/mod.rs index 1de3faf..ab940fc 100644 --- a/src/drun/mod.rs +++ b/src/drun/mod.rs @@ -1,26 +1,12 @@ -use crate::util::files; use crate::{LaunchError, LauncherListItem}; use gio::{AppInfo, DesktopAppInfo, Icon, prelude::*}; -use std::env; -use std::path::{Path, PathBuf}; #[derive(Debug)] pub struct DesktopEntry { id: String, name: String, - generic_name: Option, description: Option, icon: Option, - exec: Option, - path: PathBuf, - no_display: bool, - is_terminal_app: bool, -} - -impl DesktopEntry { - pub fn path(&self) -> PathBuf { - self.path.clone() - } } impl LauncherListItem for DesktopEntry { @@ -37,7 +23,7 @@ impl LauncherListItem for DesktopEntry { } fn execute(&self) -> Result<(), LaunchError> { - if let Some(di) = DesktopAppInfo::from_filename(&self.path) { + if let Some(di) = DesktopAppInfo::new(&self.id) { let app: AppInfo = di.upcast(); let ctx = gio::AppLaunchContext::new(); if app.launch(&[], Some(&ctx)).ok().is_none() { @@ -69,55 +55,27 @@ impl LauncherListItem for DesktopEntry { } } -fn get_desktop_files() -> Vec { - let dir_envs = - env::var("XDG_DATA_DIRS").expect("XDG_DATA_DIRS not set. Please fix your environment"); - let dir_string = String::from(dir_envs); - let dirs = dir_string.split(":"); - - let mut files = Vec::new(); - for dir in dirs { - // println!("Data dir: {}", dir); - let apps_path = Path::new(dir).join("applications"); - let desktop_files = match files::get_files_with_extension(&apps_path, "desktop") { - Ok(files) => files, - Err(_) => { - // eprintln!("Error reading {dir}: {err}"); - continue; - } - }; - - for f in desktop_files { - files.push(f); - } - } - - return files; -} - pub fn get_desktop_entries() -> Vec { let mut entries = Vec::new(); - for f in get_desktop_files() { - if let Some(info) = DesktopAppInfo::from_filename(&f) { - if info.is_nodisplay() { - continue; - } - - let de = DesktopEntry { - id: info.id().unwrap_or_default().to_string(), - name: info.name().to_string(), - generic_name: info.generic_name(), - description: info.description(), - icon: info.icon(), - exec: info.string("Exec"), - no_display: info.is_nodisplay(), - path: f.clone(), - is_terminal_app: info.boolean("Terminal"), - }; - - entries.push(de); + for i in gio::AppInfo::all() { + let info: gio::DesktopAppInfo; + match i.downcast_ref::() { + Some(inf) => info = inf.to_owned(), + None => continue, } + if !info.should_show() { + continue; + } + + let de = DesktopEntry { + id: info.id().unwrap_or_default().to_string(), + name: info.display_name().to_string(), + description: info.description(), + icon: info.icon(), + }; + + entries.push(de); } entries diff --git a/src/main.rs b/src/main.rs index 6b6988b..646c5d6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -278,51 +278,23 @@ fn find_icon_file(icon_name: &str, size: &str, theme_name: &str) -> Option() { - // // // ThemedIcon may have multiple names, we take the first - // // if let Some(name) = ti.names().first() { - // // println!("Themed: {}", name.to_string()); - // // } - // // } - - // // if let Ok(fi) = icon.clone().downcast::() { - // // if let Some(path) = fi.file().path() { - // // println!("File: {}", path.to_string_lossy().to_string()); - // // } - // // } - // } - // println!("\n"); - // } - - // let appinfo = gio::AppInfo::all(); + for p in icon_theme.search_path() { + println!("{}", p.to_string_lossy()); + } }