diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ebc01e9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/target +Cargo.lock +.sync-exclude.lst diff --git a/README.md b/README.md index e69de29..116e3a3 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,10 @@ + +this is the Dash / App Drawer for the rustix desktop environment. + +Its light and runs without systemd or other init system. + +We Designed it to run on any POSIX OS: +Tested on FreeBSD + +# Compile +cargo build --release diff --git a/src/main.rs b/src/main.rs index c8f4ce8..6c7562c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,5 @@ -use iced::widget::{button, column, grid, scrollable, text, svg}; -//use iced::widget::{container, image, row}; +use iced::widget::{container, button, column, grid, text_input, scrollable, text, row, svg}; +//use iced::widget::{image}; use iced::{Element, Fill}; //use iced::{Size, window}; @@ -7,17 +7,23 @@ mod rustix_lib; #[derive(Debug, Clone)] enum Message { - LoadApps, + LoadApps(), + OpenFirstApp(), OpenApp(String), + SearchAppChanged(String), } struct Data { - apps: Vec + apps: Vec, + search_app: String, + first_app_exec: String, } impl Default for Data { fn default() -> Self { Self { - apps: rustix_lib::load_apps(), + apps: rustix_lib::load_apps(String::new()), + search_app: String::new(), + first_app_exec: String::new(), } } } @@ -29,13 +35,29 @@ fn main() -> iced::Result { fn update(data: &mut Data, message: Message) { match message { + Message::OpenFirstApp() => { + update(data, Message::OpenApp(data.first_app_exec.clone())); + }, Message::OpenApp(exec) => { println!("exec: {}", &exec); rustix_lib::open_app(exec); }, - Message::LoadApps => { + Message::LoadApps() => { data.apps.clear(); - data.apps = rustix_lib::load_apps(); + data.apps = rustix_lib::load_apps(data.search_app.clone()); + if data.apps.len() > 0 { + match data.apps.first() + { + Some(first_app) => { + data.first_app_exec = first_app.exec.clone(); + } + None => {} + }; + } + }, + Message::SearchAppChanged(app_name) => { + data.search_app = app_name.clone(); + update(data, Message::LoadApps()); }, } } @@ -47,14 +69,18 @@ fn view(data: &Data) -> Element<'_, Message> { app_element(app) }) .collect(); - scrollable( - column![ - //button("Apps").on_press(Message::LoadApps), - grid(apps).columns(6).spacing(20), - ] - .spacing(20) - .padding(20) - .width(Fill) + container( + column![ + row![ + text("Search: "), + text_input("search application or command", &data.search_app) + .on_input(Message::SearchAppChanged) + .on_submit(Message::OpenFirstApp()), + ].width(Fill), + scrollable( + grid(apps).columns(6).spacing(20), + ).width(Fill).height(Fill), + ].spacing(10).padding(10) ) .width(Fill) .height(Fill) diff --git a/src/rustix_lib.rs b/src/rustix_lib.rs index ae680a1..fbb6906 100644 --- a/src/rustix_lib.rs +++ b/src/rustix_lib.rs @@ -4,6 +4,8 @@ pub struct ApplicationEntry { pub name: String, pub exec: String, pub icon: String, + pub entry_type: String, + pub no_display: bool, } pub fn load_application(path: String) -> Result { @@ -11,43 +13,45 @@ pub fn load_application(path: String) -> Result { 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())?; + .map_err(|e| format!("Invalid Name: {:?}", e))? + .ok_or_else(|| "Missing Name".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())?; - + .map_err(|e| format!("Invalid Exec: {:?}", e))? + .ok_or_else(|| "Missing Exec".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())?; - + + let entry_type = freedesktop_desktop_entry::desktop_entry_from_path(app_path.clone(), "Type") + .map_err(|e| format!("Invalid Type: {:?}", e))? + .ok_or_else(|| "Missing Type".to_string())?; + + let no_display = freedesktop_desktop_entry::desktop_entry_from_path(app_path.clone(), "NoDisplay") + .map_err(|e| format!("{:?}", e))? + .unwrap_or_else(|| "false".to_string()) + .parse::() + .unwrap_or(false); + println!("Path: {:?}", &path); println!("Name: {:?}", &name); println!("Exec: {:?}", &exec); println!("Icon: {:?}", &icon); - + println!("Type: {:?}", &entry_type); + println!("NoDisplay: {:?}", &no_display); + Ok(ApplicationEntry { path, name, exec, icon, + entry_type, + no_display, }) } 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) @@ -64,25 +68,36 @@ pub fn open_app(exec: String) { } } -pub fn load_apps() -> Vec { +pub fn load_apps(search_app_name: String) -> 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(); + let search_app_name_lowercase = search_app_name.to_lowercase(); + let dirs = [ + "/usr/share/applications/", + "/usr/local/share/applications/", + &format!("{}/.local/share/applications/", std::env::var("HOME").unwrap()), + ]; + for dir in dirs { + if let Ok(entries) = std::fs::read_dir(dir) { + for entry in entries.flatten() { + let app_path: String = entry.path().display().to_string(); match load_application(app_path) { Ok(this_application) => { - list_of_apps.push(this_application); + let this_application_name_lowercase = this_application.name.to_lowercase(); + if this_application_name_lowercase.contains(&search_app_name_lowercase) { + if this_application.entry_type == "Application" { + if this_application.no_display {} else { + list_of_apps.push(this_application); + } + } + } }, Err(e) => { println!("Error: {}", e); } }; + } } - Err(e) => { - println!("Can't read apps: {}", e); - } - }; + } list_of_apps }