Merge pull request #13 from imgurbot12/fix/multi-stage

fix multi-stage configuration options
This commit is contained in:
Andrew Scott 2024-04-28 09:54:04 -07:00 committed by GitHub
commit 9270ef9ea0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 50 additions and 2 deletions

View File

@ -52,6 +52,9 @@ plugins:
powermenu: powermenu:
exec: ["~/.config/rmenu/plugins/powermenu.sh"] exec: ["~/.config/rmenu/plugins/powermenu.sh"]
cache: false cache: false
options:
hover_select: true
single_click: true
# custom keybindings # custom keybindings
keybinds: keybinds:

View File

@ -10,7 +10,7 @@ use rmenu_plugin::{Entry, Message};
use thiserror::Error; use thiserror::Error;
use crate::config::{cfg_replace, Config, Keybind}; 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 /// Allowed Formats for Entry Ingestion
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
@ -405,4 +405,39 @@ impl Args {
entries.extend(self.load_plugins(config)?); entries.extend(self.load_plugins(config)?);
Ok(entries) 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(())
}
} }

View File

@ -15,6 +15,9 @@ static DEFAULT_CONFIG: &'static str = "config.yaml";
static XDG_PREFIX: &'static str = "rmenu"; static XDG_PREFIX: &'static str = "rmenu";
static DEFAULT_CSS_CONTENT: &'static str = include_str!("../public/default.css"); 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 /// Application State for GUI
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]
pub struct App { pub struct App {
@ -33,7 +36,7 @@ pub struct App {
fn main() -> cli::Result<()> { fn main() -> cli::Result<()> {
// export self to environment for other scripts // export self to environment for other scripts
let exe = self_exe(); let exe = self_exe();
std::env::set_var("RMENU", exe); std::env::set_var(ENV_BIN, exe);
// enable log and set default level // enable log and set default level
if std::env::var("RUST_LOG").is_err() { 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()); .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()); 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 theme = cli.get_theme();
let css = cli.get_css(&config); let css = cli.get_css(&config);
// set environment variables before running app
cli.set_env();
// genrate app context and run gui // genrate app context and run gui
gui::run(App { gui::run(App {
name: "rmenu".to_owned(), name: "rmenu".to_owned(),