mirror of
https://github.com/imgurbot12/rmenu.git
synced 2025-01-12 23:36:29 +01:00
Merge pull request #13 from imgurbot12/fix/multi-stage
fix multi-stage configuration options
This commit is contained in:
commit
9270ef9ea0
3 changed files with 50 additions and 2 deletions
|
@ -52,6 +52,9 @@ plugins:
|
|||
powermenu:
|
||||
exec: ["~/.config/rmenu/plugins/powermenu.sh"]
|
||||
cache: false
|
||||
options:
|
||||
hover_select: true
|
||||
single_click: true
|
||||
|
||||
# custom keybindings
|
||||
keybinds:
|
||||
|
|
|
@ -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(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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(),
|
||||
|
|
Loading…
Reference in a new issue