diff --git a/plugins/src/scripts/mod.rs b/plugins/src/scripts/mod.rs index a5192b2..2145177 100644 --- a/plugins/src/scripts/mod.rs +++ b/plugins/src/scripts/mod.rs @@ -87,7 +87,7 @@ impl App { let (tx, rx) = flume::unbounded::(); let script_sender = async move { - for path in path_rx.recv_async().await { + while let Ok(path) = path_rx.recv_async().await { load_from(&path, &path_tx, tx.clone()).await; } }; diff --git a/plugins/src/web/config.rs b/plugins/src/web/config.rs index 7e58fc6..6f569fd 100644 --- a/plugins/src/web/config.rs +++ b/plugins/src/web/config.rs @@ -9,17 +9,13 @@ pub struct Config { } impl Config { - pub fn new(rules: RawConfig) -> Self { - let mut config = Self::default(); - + pub fn append(&mut self, rules: RawConfig) { for rule in rules.rules { - let idx = config.queries.insert(rule.queries); + let idx = self.queries.insert(rule.queries); for keyword in rule.matches { - config.matches.insert(keyword, idx as u32); + self.matches.insert(keyword, idx as u32); } } - - config } pub fn get(&self, word: &str) -> Option<&[Definition]> { @@ -48,24 +44,24 @@ pub struct Definition { } pub fn load() -> Config { - pop_launcher::config::find("web") - .next() - .and_then(|path| { - let string = match std::fs::read_to_string(&path) { - Ok(string) => string, - Err(why) => { - tracing::error!("failed to read config: {}", why); - return None; - } - }; + let mut config = Config::default(); - match ron::from_str::(&string) { - Ok(config) => Some(Config::new(config)), - Err(why) => { - tracing::error!("failed to deserialize config: {}", why); - None - } + for path in pop_launcher::config::find("web") { + let string = match std::fs::read_to_string(&path) { + Ok(string) => string, + Err(why) => { + tracing::error!("failed to read config: {}", why); + continue; } - }) - .unwrap_or_default() + }; + + match ron::from_str::(&string) { + Ok(raw) => config.append(raw), + Err(why) => { + tracing::error!("failed to deserialize config: {}", why); + } + } + } + + config } diff --git a/plugins/src/web/mod.rs b/plugins/src/web/mod.rs index f030848..0591d1c 100644 --- a/plugins/src/web/mod.rs +++ b/plugins/src/web/mod.rs @@ -8,7 +8,7 @@ use smol::Unblock; use std::io; pub async fn main() { - let mut app = App::new(); + let mut app = App::default(); let mut requests = json_input_stream(async_stdin()); @@ -33,15 +33,17 @@ pub struct App { out: Unblock, } -impl App { - pub fn new() -> Self { +impl Default for App { + fn default() -> Self { Self { config: config::load(), queries: Vec::new(), out: async_stdout(), } } +} +impl App { pub async fn activate(&mut self, id: u32) { if let Some(query) = self.queries.get(id as usize) { eprintln!("got query: {}", query);