From ca63ebe5042e772873bf87f9dd3c3229d5ce72a3 Mon Sep 17 00:00:00 2001 From: Byson94 Date: Wed, 8 Oct 2025 19:43:44 +0530 Subject: [PATCH] feat: fixing few errors and improving other stuff --- CHANGELOG.md | 1 + crates/ewwii/src/app.rs | 28 ++++++++++++++-------------- crates/ewwii/src/plugin.rs | 2 +- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a3c21af..ed0f639 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/). ### Added - Support for binary level plugins. +- `set-plugin` command ### Changed diff --git a/crates/ewwii/src/app.rs b/crates/ewwii/src/app.rs index b0028e7..efc28a5 100644 --- a/crates/ewwii/src/app.rs +++ b/crates/ewwii/src/app.rs @@ -43,9 +43,8 @@ use tokio::sync::mpsc::UnboundedSender; static ACTIVE_PLUGIN: OnceCell = OnceCell::new(); -fn set_active_plugin(lib: libloading::Library) { - // will panic if called more than once - ACTIVE_PLUGIN.set(lib).unwrap(); +fn set_active_plugin(lib: libloading::Library) -> Result<()> { + ACTIVE_PLUGIN.set(lib).map_err(|_| anyhow!("Plugin already set")) } /// A command for the ewwii daemon. @@ -381,7 +380,7 @@ impl App { } DaemonCommand::SetPlugin { file_path, sender } => { match self.set_ewwii_plugin(file_path) { - Ok(_) => sender.send_success(String::new())?, + Ok(_) => sender.send_success(String::from("OK"))?, Err(e) => sender.send_failure(e.to_string())?, } } @@ -846,20 +845,21 @@ impl App { let host = crate::plugin::EwwiiImpl { requestor: tx.clone() }; plugin.init(&host); // call init immediately - set_active_plugin(lib); // keep library alive + set_active_plugin(lib)?; // keep library alive } - while let Ok(req) = rx.recv() { - match req { - PluginRequest::RhaiEngineAct(func) => { - let mut cp = self.config_parser.borrow_mut(); - cp.action_with_engine(func); + let cp = self.config_parser.clone(); + + glib::MainContext::default().spawn_local(async move { + while let Ok(req) = rx.recv() { + match req { + PluginRequest::RhaiEngineAct(func) => { + let mut cp = cp.borrow_mut(); + cp.action_with_engine(func); + } } } - } - - // use tokio::task::spawn_blocking() - // when more plugin requests are being handled. + }); Ok(()) } diff --git a/crates/ewwii/src/plugin.rs b/crates/ewwii/src/plugin.rs index 228c8cf..9ba93d4 100644 --- a/crates/ewwii/src/plugin.rs +++ b/crates/ewwii/src/plugin.rs @@ -15,7 +15,7 @@ impl EwwiiAPI for EwwiiImpl { // Rhai Manipulation Stuff fn rhai_engine_action(&self, f: Box) -> Result<(), String> { self.requestor - .send(PluginRequest::SetRhaiEngine(f)) + .send(PluginRequest::RhaiEngineAct(f)) .map_err(|_| "Failed to send request to host".to_string())?; Ok(()) }