From 11c1fc0ddcd46ebde19762f0e2815f26c5b5bc9f Mon Sep 17 00:00:00 2001 From: "NGnius (Graham)" Date: Sun, 29 Jan 2023 12:00:08 -0500 Subject: [PATCH] Set settings twice when dirty, to be extra sure settings are set when set and not unset when set set set set --- backend/src/api/handler.rs | 4 +++- backend/src/main.rs | 10 ++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/backend/src/api/handler.rs b/backend/src/api/handler.rs index f339ff8..dc7d1e8 100644 --- a/backend/src/api/handler.rs +++ b/backend/src/api/handler.rs @@ -218,12 +218,14 @@ pub struct ApiMessageHandler { impl ApiMessageHandler { pub fn process_forever(&mut self, settings: &mut Settings) { + let mut dirty_echo = true; // set everything twice, to make sure PowerTools wins on race conditions while let Ok(msg) = self.intake.recv() { let mut dirty = self.process(settings, msg); while let Ok(msg) = self.intake.try_recv() { dirty |= self.process(settings, msg); } - if dirty { + if dirty || dirty_echo { + dirty_echo = dirty; // echo only once // run on_set if let Err(e) = settings.on_set() { log::error!("Settings on_set() err: {}", e); diff --git a/backend/src/main.rs b/backend/src/main.rs index 0603a24..f335223 100644 --- a/backend/src/main.rs +++ b/backend/src/main.rs @@ -69,10 +69,6 @@ fn main() -> Result<(), ()> { //let (_save_handle, save_sender) = save_worker::spawn(loaded_settings.clone()); let _resume_handle = resume_worker::spawn(api_sender.clone()); - if let Err(e) = loaded_settings.on_set() { - log::error!("Startup Settings.on_set() error: {}", e); - } - let instance = Instance::new(PORT) .register("V_INFO", |_: Vec| { vec![format!("{} v{}", PACKAGE_NAME, PACKAGE_VERSION).into()] @@ -225,6 +221,12 @@ fn main() -> Result<(), ()> { ) .register("GENERAL_idk", api::general::gunter); + if let Err(e) = loaded_settings.on_set() { + log::error!("Startup Settings.on_set() error: {}", e); + } else { + log::info!("Startup Settings.on_set() success"); + } + api_worker::spawn(loaded_settings, api_handler); instance