WIP
This commit is contained in:
parent
bf252ed6ee
commit
fa0af222f8
@ -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<glib::GString>,
|
||||
description: Option<glib::GString>,
|
||||
icon: Option<Icon>,
|
||||
exec: Option<glib::GString>,
|
||||
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<PathBuf> {
|
||||
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<DesktopEntry> {
|
||||
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::<gio::DesktopAppInfo>() {
|
||||
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
|
||||
|
58
src/main.rs
58
src/main.rs
@ -278,51 +278,23 @@ fn find_icon_file(icon_name: &str, size: &str, theme_name: &str) -> Option<std::
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let app = Application::builder()
|
||||
.application_id("dev.thegrind.waycast")
|
||||
.build();
|
||||
// let app = Application::builder()
|
||||
// .application_id("dev.thegrind.waycast")
|
||||
// .build();
|
||||
|
||||
app.connect_activate(|app| {
|
||||
let model = AppModel::new(app);
|
||||
model.borrow().show();
|
||||
});
|
||||
// app.connect_activate(|app| {
|
||||
// let model = AppModel::new(app);
|
||||
// model.borrow().show();
|
||||
// });
|
||||
|
||||
app.run();
|
||||
// app.run();
|
||||
|
||||
// gtk::init().expect("Failed to init GTK");
|
||||
// let display = gtk::gdk::Display::default().unwrap();
|
||||
// let icon_theme = gtk::IconTheme::for_display(&display);
|
||||
// println!("Current icon theme: {:?}", icon_theme.theme_name());
|
||||
// for info in gio::AppInfo::all() {
|
||||
// if !info.should_show() {
|
||||
// continue;
|
||||
// }
|
||||
gtk::init().expect("Failed to init GTK");
|
||||
let display = gtk::gdk::Display::default().unwrap();
|
||||
let icon_theme = gtk::IconTheme::for_display(&display);
|
||||
println!("Current icon theme: {:?}", icon_theme.theme_name());
|
||||
|
||||
// println!("App: {}", info.display_name());
|
||||
// if let Some(icon) = info.icon() {
|
||||
// if let Some(x) = icon.to_string() {
|
||||
// println!("Icon: {}", x.to_string());
|
||||
// if let Some(path) = find_icon_file(&x, "48", icon_theme.theme_name().as_str()) {
|
||||
// println!("Found at: {}", path.to_string_lossy());
|
||||
// } else {
|
||||
// println!("Not found");
|
||||
// }
|
||||
// }
|
||||
// // if let Ok(ti) = icon.clone().downcast::<gio::ThemedIcon>() {
|
||||
// // // 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::<gio::FileIcon>() {
|
||||
// // 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());
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user