diff --git a/libimagstore/src/store.rs b/libimagstore/src/store.rs index baaa94db..5c43b118 100644 --- a/libimagstore/src/store.rs +++ b/libimagstore/src/store.rs @@ -375,7 +375,7 @@ impl Store { pub fn register_hook(&mut self, position: HookPosition, aspect_name: &String, - h: Box) + mut h: Box) -> Result<()> { debug!("Registering hook: {:?}", h); @@ -407,6 +407,7 @@ impl Store { let mut guard = guard.unwrap(); for mut aspect in guard.deref_mut() { if aspect.name().clone() == aspect_name.clone() { + self.get_config_for_hook(h.name()).map(|config| h.set_config(config)); aspect.register_hook(h); return Ok(()); } @@ -414,6 +415,22 @@ impl Store { return Err(StoreError::new(StoreErrorKind::HookRegisterError, None)); } + fn get_config_for_hook(&self, name: &str) -> Option<&Value> { + match &self.configuration { + &Value::Table(ref tabl) => { + tabl.get("hooks") + .map(|hook_section| { + match hook_section { + &Value::Table(ref tabl) => tabl.get(name), + _ => None + } + }) + .unwrap_or(None) + }, + _ => None, + } + } + fn execute_hooks_for_id(&self, aspects: Arc>>, id: &StoreId)