diff --git a/plugin-desktop/src/main.rs b/plugin-desktop/src/main.rs index 57497fc..bf0167a 100644 --- a/plugin-desktop/src/main.rs +++ b/plugin-desktop/src/main.rs @@ -79,6 +79,7 @@ fn parse_desktop(path: &PathBuf, locale: Option<&str>) -> Option { actions, comment, icon, + icon_alt: None, }) } diff --git a/rmenu-plugin/Cargo.toml b/rmenu-plugin/Cargo.toml index af7ddb1..8f180fc 100644 --- a/rmenu-plugin/Cargo.toml +++ b/rmenu-plugin/Cargo.toml @@ -5,5 +5,20 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[lib] +name = "rmenu_plugin" +path = "src/lib.rs" + +[[bin]] +name = "rmenu-build" +path = "src/bin/main.rs" +required-features = ["cli"] + +[features] +default = [] +cli = ["clap", "serde_json"] + [dependencies] +clap = { version = "4.3.22", features = ["derive"], optional = true } serde = { version = "1.0.171", features = ["derive"] } +serde_json = { version = "1.0.105", optional = true } diff --git a/rmenu-plugin/src/bin/main.rs b/rmenu-plugin/src/bin/main.rs new file mode 100644 index 0000000..55c6bf0 --- /dev/null +++ b/rmenu-plugin/src/bin/main.rs @@ -0,0 +1,82 @@ +use rmenu_plugin::*; + +use clap::{Parser, Subcommand}; + +/// Parse Action from JSON +fn parse_action(action: &str) -> Result { + serde_json::from_str(action) +} + +//TODO: add options struct object that allows for further +// dynamic customization of the cli settings. +// last instance overwrites previous entries +// properties do not override cli-specified values +// +// priority order: +// 1. cli flags +// 2. plugin/source latest merged options +// 3. configuration settings + +#[derive(Debug, Subcommand)] +enum Command { + /// Generate Complete RMenu Entry + Entry { + /// Precomposed Action JSON Objects + #[arg(short, long, value_parser=parse_action)] + #[clap(required = true)] + actions: Vec, + /// Icon Image Path + #[arg(short, long)] + icon: Option, + /// Alternative Image Text/HTML + #[arg(short = 'o', long)] + icon_alt: Option, + }, + /// Generate RMenu Entry Action Object + Action { + /// Arguments to run As Action Command + #[clap(required = true, value_delimiter = ' ')] + args: Vec, + /// Run in New Terminal Session if Active + #[arg(short, long)] + terminal: bool, + }, +} + +#[derive(Debug, Parser)] +#[command(author, version, about, long_about = None)] +#[command(propagate_version = true)] +struct Cli { + /// Set Name of Entry/Action + #[arg(short, long, default_value_t=String::from("main"))] + name: String, + /// Set Comment of Entry/Action + #[arg(short, long)] + comment: Option, + /// Generate an Entry/Action Object + #[clap(subcommand)] + command: Command, +} + +fn main() { + let cli = Cli::parse(); + let result = match cli.command { + Command::Entry { + actions, + icon, + icon_alt, + } => serde_json::to_string(&Entry { + name: cli.name, + comment: cli.comment, + actions, + icon, + icon_alt, + }), + Command::Action { args, terminal } => serde_json::to_string(&Action { + name: cli.name, + exec: Method::new(args.join(" "), terminal), + comment: cli.comment, + }), + }; + println!("{}", result.expect("Serialization Failed")); +} diff --git a/rmenu-plugin/src/lib.rs b/rmenu-plugin/src/lib.rs index a1c9782..0e41732 100644 --- a/rmenu-plugin/src/lib.rs +++ b/rmenu-plugin/src/lib.rs @@ -1,5 +1,7 @@ +//! RMenu-Plugin Object Implementations use serde::{Deserialize, Serialize}; +/// Methods allowed to Execute Actions on Selection #[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] #[serde(rename_all = "lowercase")] pub enum Method { @@ -9,6 +11,7 @@ pub enum Method { } impl Method { + /// Generate the Required Method from a Function pub fn new(exec: String, terminal: bool) -> Self { match terminal { true => Self::Terminal(exec), @@ -17,6 +20,7 @@ impl Method { } } +/// RMenu Entry Action Definition #[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] pub struct Action { pub name: String, @@ -25,13 +29,15 @@ pub struct Action { } impl Action { - pub fn new(exec: &str) -> Self { + /// Generate a simple Execution Action + pub fn exec(exec: &str) -> Self { Self { name: "main".to_string(), exec: Method::Run(exec.to_string()), comment: None, } } + /// Generate a simple Echo Action pub fn echo(echo: &str) -> Self { Self { name: "main".to_string(), @@ -41,6 +47,7 @@ impl Action { } } +/// RMenu Menu-Entry Implementation #[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] pub struct Entry { pub name: String, @@ -51,16 +58,17 @@ pub struct Entry { } impl Entry { + /// Generate a simplified Exec Action Entry pub fn new(name: &str, action: &str, comment: Option<&str>) -> Self { Self { name: name.to_owned(), - actions: vec![Action::new(action)], + actions: vec![Action::exec(action)], comment: comment.map(|c| c.to_owned()), icon: Default::default(), icon_alt: Default::default(), } } - + /// Generate a simplified Echo Action Entry pub fn echo(echo: &str, comment: Option<&str>) -> Self { Self { name: echo.to_owned(), diff --git a/rmenu/src/gui.rs b/rmenu/src/gui.rs index 267a856..ff97d83 100644 --- a/rmenu/src/gui.rs +++ b/rmenu/src/gui.rs @@ -12,7 +12,6 @@ use crate::{App, DEFAULT_CSS_CONTENT}; /// spawn and run the app on the configured platform pub fn run(app: App) { - // customize window let theme = match app.config.window.dark_mode { Some(dark) => match dark { true => Some(dioxus_desktop::tao::window::Theme::Dark),