Hide some Entries

Hide Entries if:
- Type is not Application
- NoDisplay is True
This commit is contained in:
BlueKenny committed 2026-11-22 21:27:29 +01:00
1 parent 01377806de
commit f6977323db
4 files changed
+98 -44

No files matched your search

+3
View File
@@ -0,0 +1,3 @@
/target
Cargo.lock
.sync-exclude.lst
+10
View File
@@ -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
+41 -15
View File
@@ -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<rustix_lib::ApplicationEntry>
apps: Vec<rustix_lib::ApplicationEntry>,
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)
+44 -29
View File
@@ -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<ApplicationEntry, String> {
@@ -11,43 +13,45 @@ pub fn load_application(path: String) -> Result<ApplicationEntry, String> {
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::<bool>()
.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<ApplicationEntry> {
pub fn load_apps(search_app_name: String) -> Vec<ApplicationEntry> {
let mut list_of_apps: Vec<ApplicationEntry> = 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
}