From 9d292c3360a39360b1fea297293e927095c13cb2 Mon Sep 17 00:00:00 2001 From: imgurbot12 Date: Fri, 26 Apr 2024 16:44:25 -0700 Subject: [PATCH 1/2] feat: use env-vars to preserve configuration between multi-stage cmds --- rmenu/src/cli.rs | 37 ++++++++++++++++++++++++++++++++++++- rmenu/src/main.rs | 12 +++++++++++- 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/rmenu/src/cli.rs b/rmenu/src/cli.rs index 7bd3dcf..7ffeff5 100644 --- a/rmenu/src/cli.rs +++ b/rmenu/src/cli.rs @@ -10,7 +10,7 @@ use rmenu_plugin::{Entry, Message}; use thiserror::Error; use crate::config::{cfg_replace, Config, Keybind}; -use crate::{DEFAULT_CONFIG, DEFAULT_THEME, XDG_PREFIX}; +use crate::{DEFAULT_CONFIG, DEFAULT_THEME, ENV_ACTIVE_PLUGINS, XDG_PREFIX}; /// Allowed Formats for Entry Ingestion #[derive(Debug, Clone)] @@ -405,4 +405,39 @@ impl Args { entries.extend(self.load_plugins(config)?); Ok(entries) } + + /// Configure Environment Variables for Multi-Stage Execution + pub fn set_env(&self) { + let mut running = self.run.join(","); + if let Ok(already_running) = std::env::var(ENV_ACTIVE_PLUGINS) { + running = format!("{running},{already_running}"); + } + std::env::set_var(ENV_ACTIVE_PLUGINS, running); + } + + /// Load Settings from Environment Variables for Multi-Stage Execution + pub fn load_env(&mut self, config: &mut Config) -> Result<()> { + let env_plugins = std::env::var(ENV_ACTIVE_PLUGINS).unwrap_or_default(); + let active_plugins: Vec<&str> = env_plugins + .split(",") + .map(|s| s.trim()) + .filter(|s| !s.is_empty()) + .collect(); + for name in active_plugins { + // retrieve plugin configuration + log::info!("reloading plugin configuration for {name:?}"); + let plugin = config + .plugins + .get(name) + .cloned() + .ok_or_else(|| RMenuError::NoSuchPlugin(name.to_owned()))?; + // update config w/ plugin options when available + if let Some(options) = plugin.options.as_ref() { + config + .update(options) + .map_err(|e| RMenuError::InvalidKeybind(e))?; + } + } + Ok(()) + } } diff --git a/rmenu/src/main.rs b/rmenu/src/main.rs index 1629b07..fa05423 100644 --- a/rmenu/src/main.rs +++ b/rmenu/src/main.rs @@ -15,6 +15,9 @@ static DEFAULT_CONFIG: &'static str = "config.yaml"; static XDG_PREFIX: &'static str = "rmenu"; static DEFAULT_CSS_CONTENT: &'static str = include_str!("../public/default.css"); +static ENV_BIN: &'static str = "RMENU"; +static ENV_ACTIVE_PLUGINS: &'static str = "RMENU_ACTIVE_PLUGINS"; + /// Application State for GUI #[derive(Debug, PartialEq)] pub struct App { @@ -33,7 +36,7 @@ pub struct App { fn main() -> cli::Result<()> { // export self to environment for other scripts let exe = self_exe(); - std::env::set_var("RMENU", exe); + std::env::set_var(ENV_BIN, exe); // enable log and set default level if std::env::var("RUST_LOG").is_err() { @@ -54,9 +57,16 @@ fn main() -> cli::Result<()> { .any(|e| e.icon.is_some() || e.icon_alt.is_some()); config.use_comments = config.use_comments && entries.iter().any(|e| e.comment.is_some()); + // load additional configuration settings from env + cli.load_env(&mut config)?; + + // configure css theme and css overrides let theme = cli.get_theme(); let css = cli.get_css(&config); + // set environment variables before running app + cli.set_env(); + // genrate app context and run gui gui::run(App { name: "rmenu".to_owned(), From f3e545025b13f09b402ff82a225b5c9f7c598a9e Mon Sep 17 00:00:00 2001 From: imgurbot12 Date: Fri, 26 Apr 2024 16:47:50 -0700 Subject: [PATCH 2/2] feat: update default config for powermenu --- rmenu/public/config.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/rmenu/public/config.yaml b/rmenu/public/config.yaml index a1c5466..80b02ac 100644 --- a/rmenu/public/config.yaml +++ b/rmenu/public/config.yaml @@ -52,6 +52,9 @@ plugins: powermenu: exec: ["~/.config/rmenu/plugins/powermenu.sh"] cache: false + options: + hover_select: true + single_click: true # custom keybindings keybinds: