commit 01377806de7b4f5cd53683107ca99a582b933403 Author: Zaunz Kenny Date: Sun Nov 22 19:16:20 2026 +0100 first commit diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..f573baf --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "rustix-dash" +version = "0.1.1" +edition = "2024" + +[dependencies] +freedesktop-desktop-entry = "0.8.4" +iced = { version = "0.14.0", features = ["image", "svg"] } +shell-words = "1.1.1" diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..c8f4ce8 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,93 @@ +use iced::widget::{button, column, grid, scrollable, text, svg}; +//use iced::widget::{container, image, row}; +use iced::{Element, Fill}; +//use iced::{Size, window}; + +mod rustix_lib; + +#[derive(Debug, Clone)] +enum Message { + LoadApps, + OpenApp(String), +} + +struct Data { + apps: Vec +} +impl Default for Data { + fn default() -> Self { + Self { + apps: rustix_lib::load_apps(), + } + } +} + +fn main() -> iced::Result { + println!("Starte..."); + iced::run(update, view) +} + +fn update(data: &mut Data, message: Message) { + match message { + Message::OpenApp(exec) => { + println!("exec: {}", &exec); + rustix_lib::open_app(exec); + }, + Message::LoadApps => { + data.apps.clear(); + data.apps = rustix_lib::load_apps(); + }, + } +} + +fn view(data: &Data) -> Element<'_, Message> { + let apps: Vec> = data.apps + .iter() + .map(|app| { + app_element(app) + }) + .collect(); + scrollable( + column![ + //button("Apps").on_press(Message::LoadApps), + grid(apps).columns(6).spacing(20), + ] + .spacing(20) + .padding(20) + .width(Fill) + ) + .width(Fill) + .height(Fill) + .into() +} + +fn app_element(app: &rustix_lib::ApplicationEntry) -> Element<'_, Message> { + //$HOME/.icons (for backwards compatibility), in $XDG_DATA_DIRS/icons and in /usr/share/pixmaps (in that order). + let absolute_icon_path = format!("/usr/share/icons/hicolor/scalable/apps/{}.svg", app.icon.clone()); + /* + if std::path::Path::new(&absolute_icon_path).is_file() {} else { + absolute_icon_path = format!("$XDG_DATA_DIRS/.icons/{}", app.icon.clone()); + if std::path::Path::new(&absolute_icon_path).is_file() {} else { + absolute_icon_path = format!("/usr/share/pixmaps/{}", app.icon.clone()); + } + } + */ + + button( + column![ + text(app.name.clone()) + .center(), + svg(absolute_icon_path.clone()) + .height(100) + .width(100), + ] + .height(250) + .width(1250) + .padding(20) + .spacing(10) + ) + .height(250) + .width(250) + .on_press(Message::OpenApp(app.exec.clone())) + .into() +} diff --git a/src/rustix_lib.rs b/src/rustix_lib.rs new file mode 100644 index 0000000..ae680a1 --- /dev/null +++ b/src/rustix_lib.rs @@ -0,0 +1,88 @@ + +pub struct ApplicationEntry { + pub path: String, + pub name: String, + pub exec: String, + pub icon: String, +} + +pub fn load_application(path: String) -> Result { + println!("load_application({})", path); + let app_path = std::path::PathBuf::from(path.clone()); + + let name = freedesktop_desktop_entry::desktop_entry_from_path(app_path.clone(), "Name") + .map_err(|e| format!("Invalid Icon: {:?}", e))? + .ok_or_else(|| "Missing Icon".to_string())?; + + let exec = freedesktop_desktop_entry::desktop_entry_from_path(app_path.clone(), "Exec") + .map_err(|e| format!("Invalid Icon: {:?}", e))? + .ok_or_else(|| "Missing Icon".to_string())?; + + let icon = freedesktop_desktop_entry::desktop_entry_from_path(app_path.clone(), "Icon") + .map_err(|e| format!("Invalid Icon: {:?}", e))? + .ok_or_else(|| "Missing Icon".to_string())?; + + println!("Path: {:?}", &path); + println!("Name: {:?}", &name); + println!("Exec: {:?}", &exec); + println!("Icon: {:?}", &icon); + + Ok(ApplicationEntry { + path, + name, + exec, + icon, + }) +} + +pub fn open_app(exec: String) { + /* + match std::process::Command::new(exec) + //.arg("https://streaming.brf.be/brf1-high.mp3") + .spawn() + { + Ok(_child) => { + println!("run"); + } + Err(e) => { + println!("Error: {e}"); + } + }*/ + let args = shell_words::split(&exec).unwrap(); + if let Some((program, args)) = args.split_first() { + match std::process::Command::new(program) + .args(args) + .spawn() + { + Ok(_) => { + println!("run"); + } + Err(e) => { + println!("Error: {e}"); + } + } + } +} + +pub fn load_apps() -> Vec { + let mut list_of_apps: Vec = Vec::new(); + let _apps = match std::fs::read_dir("/usr/share/applications/") { + Ok(apps) => { + for app in apps { + let app_path: String = app.unwrap().path().display().to_string(); + match load_application(app_path) { + Ok(this_application) => { + list_of_apps.push(this_application); + }, + Err(e) => { + println!("Error: {}", e); + } + }; + } + } + Err(e) => { + println!("Can't read apps: {}", e); + } + }; + list_of_apps +}