Hide some Entries
Hide Entries if: - Type is not Application - NoDisplay is True
This commit is contained in:
1 parent
01377806de
commit
f6977323db
4 files changed
+91
-37
No files matched your search
@@ -0,0 +1,3 @@
|
|||||||
|
/target
|
||||||
|
Cargo.lock
|
||||||
|
.sync-exclude.lst
|
||||||
@@ -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
|
||||||
+39
-13
@@ -1,5 +1,5 @@
|
|||||||
use iced::widget::{button, column, grid, scrollable, text, svg};
|
use iced::widget::{container, button, column, grid, text_input, scrollable, text, row, svg};
|
||||||
//use iced::widget::{container, image, row};
|
//use iced::widget::{image};
|
||||||
use iced::{Element, Fill};
|
use iced::{Element, Fill};
|
||||||
//use iced::{Size, window};
|
//use iced::{Size, window};
|
||||||
|
|
||||||
@@ -7,17 +7,23 @@ mod rustix_lib;
|
|||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
enum Message {
|
enum Message {
|
||||||
LoadApps,
|
LoadApps(),
|
||||||
|
OpenFirstApp(),
|
||||||
OpenApp(String),
|
OpenApp(String),
|
||||||
|
SearchAppChanged(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Data {
|
struct Data {
|
||||||
apps: Vec<rustix_lib::ApplicationEntry>
|
apps: Vec<rustix_lib::ApplicationEntry>,
|
||||||
|
search_app: String,
|
||||||
|
first_app_exec: String,
|
||||||
}
|
}
|
||||||
impl Default for Data {
|
impl Default for Data {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
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) {
|
fn update(data: &mut Data, message: Message) {
|
||||||
match message {
|
match message {
|
||||||
|
Message::OpenFirstApp() => {
|
||||||
|
update(data, Message::OpenApp(data.first_app_exec.clone()));
|
||||||
|
},
|
||||||
Message::OpenApp(exec) => {
|
Message::OpenApp(exec) => {
|
||||||
println!("exec: {}", &exec);
|
println!("exec: {}", &exec);
|
||||||
rustix_lib::open_app(exec);
|
rustix_lib::open_app(exec);
|
||||||
},
|
},
|
||||||
Message::LoadApps => {
|
Message::LoadApps() => {
|
||||||
data.apps.clear();
|
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)
|
app_element(app)
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
scrollable(
|
container(
|
||||||
column![
|
column![
|
||||||
//button("Apps").on_press(Message::LoadApps),
|
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),
|
grid(apps).columns(6).spacing(20),
|
||||||
]
|
).width(Fill).height(Fill),
|
||||||
.spacing(20)
|
].spacing(10).padding(10)
|
||||||
.padding(20)
|
|
||||||
.width(Fill)
|
|
||||||
)
|
)
|
||||||
.width(Fill)
|
.width(Fill)
|
||||||
.height(Fill)
|
.height(Fill)
|
||||||
|
|||||||
+39
-24
@@ -4,6 +4,8 @@ pub struct ApplicationEntry {
|
|||||||
pub name: String,
|
pub name: String,
|
||||||
pub exec: String,
|
pub exec: String,
|
||||||
pub icon: String,
|
pub icon: String,
|
||||||
|
pub entry_type: String,
|
||||||
|
pub no_display: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn load_application(path: String) -> Result<ApplicationEntry, String> {
|
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 app_path = std::path::PathBuf::from(path.clone());
|
||||||
|
|
||||||
let name = freedesktop_desktop_entry::desktop_entry_from_path(app_path.clone(), "Name")
|
let name = freedesktop_desktop_entry::desktop_entry_from_path(app_path.clone(), "Name")
|
||||||
.map_err(|e| format!("Invalid Icon: {:?}", e))?
|
.map_err(|e| format!("Invalid Name: {:?}", e))?
|
||||||
.ok_or_else(|| "Missing Icon".to_string())?;
|
.ok_or_else(|| "Missing Name".to_string())?;
|
||||||
|
|
||||||
let exec = freedesktop_desktop_entry::desktop_entry_from_path(app_path.clone(), "Exec")
|
let exec = freedesktop_desktop_entry::desktop_entry_from_path(app_path.clone(), "Exec")
|
||||||
.map_err(|e| format!("Invalid Icon: {:?}", e))?
|
.map_err(|e| format!("Invalid Exec: {:?}", e))?
|
||||||
.ok_or_else(|| "Missing Icon".to_string())?;
|
.ok_or_else(|| "Missing Exec".to_string())?;
|
||||||
|
|
||||||
let icon = freedesktop_desktop_entry::desktop_entry_from_path(app_path.clone(), "Icon")
|
let icon = freedesktop_desktop_entry::desktop_entry_from_path(app_path.clone(), "Icon")
|
||||||
.map_err(|e| format!("Invalid Icon: {:?}", e))?
|
.map_err(|e| format!("Invalid Icon: {:?}", e))?
|
||||||
.ok_or_else(|| "Missing Icon".to_string())?;
|
.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!("Path: {:?}", &path);
|
||||||
println!("Name: {:?}", &name);
|
println!("Name: {:?}", &name);
|
||||||
println!("Exec: {:?}", &exec);
|
println!("Exec: {:?}", &exec);
|
||||||
println!("Icon: {:?}", &icon);
|
println!("Icon: {:?}", &icon);
|
||||||
|
println!("Type: {:?}", &entry_type);
|
||||||
|
println!("NoDisplay: {:?}", &no_display);
|
||||||
|
|
||||||
Ok(ApplicationEntry {
|
Ok(ApplicationEntry {
|
||||||
path,
|
path,
|
||||||
name,
|
name,
|
||||||
exec,
|
exec,
|
||||||
icon,
|
icon,
|
||||||
|
entry_type,
|
||||||
|
no_display,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn open_app(exec: String) {
|
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();
|
let args = shell_words::split(&exec).unwrap();
|
||||||
if let Some((program, args)) = args.split_first() {
|
if let Some((program, args)) = args.split_first() {
|
||||||
match std::process::Command::new(program)
|
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 mut list_of_apps: Vec<ApplicationEntry> = Vec::new();
|
||||||
let _apps = match std::fs::read_dir("/usr/share/applications/") {
|
let search_app_name_lowercase = search_app_name.to_lowercase();
|
||||||
Ok(apps) => {
|
let dirs = [
|
||||||
for app in apps {
|
"/usr/share/applications/",
|
||||||
let app_path: String = app.unwrap().path().display().to_string();
|
"/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) {
|
match load_application(app_path) {
|
||||||
Ok(this_application) => {
|
Ok(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);
|
list_of_apps.push(this_application);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
println!("Error: {}", e);
|
println!("Error: {}", e);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(e) => {
|
|
||||||
println!("Can't read apps: {}", e);
|
|
||||||
}
|
}
|
||||||
};
|
|
||||||
list_of_apps
|
list_of_apps
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user