first commit
This commit is contained in:
commit
01377806de
4 files changed
+190
No files matched your search
@@ -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"
|
||||
+93
@@ -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<rustix_lib::ApplicationEntry>
|
||||
}
|
||||
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<Element<'_, Message>> = 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()
|
||||
}
|
||||
@@ -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<ApplicationEntry, String> {
|
||||
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<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();
|
||||
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
|
||||
}
|
||||
Reference in new issue
Block a user