From d00d0d5fd4eb7a87128446509492f270e8d0791a Mon Sep 17 00:00:00 2001 From: DashieTM Date: Thu, 30 May 2024 20:35:35 +0200 Subject: [PATCH] plugins: Add path possibility for plugins --- src/utils/plugin_setup.rs | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/utils/plugin_setup.rs b/src/utils/plugin_setup.rs index cf66610..4bd055c 100644 --- a/src/utils/plugin_setup.rs +++ b/src/utils/plugin_setup.rs @@ -22,12 +22,18 @@ use super::{ pub static LIBS_LOADED: AtomicBool = AtomicBool::new(false); pub static LIBS_LOADING: AtomicBool = AtomicBool::new(false); -pub static mut FRONTEND_PLUGINS: Lazy> = Lazy::new(|| { - SETUP_LIBS(); +pub static mut FRONTEND_PLUGINS: Lazy< + Vec, + fn(Option<&str>) -> Vec, +> = Lazy::new(|path: Option<&str>| { + SETUP_LIBS(path); setup_frontend_plugins() }); -pub static mut BACKEND_PLUGINS: Lazy> = Lazy::new(|| { - SETUP_LIBS(); +pub static mut BACKEND_PLUGINS: Lazy< + Vec, + fn(Option<&str>) -> Vec, +> = Lazy::new(|path: Option<&str>| { + SETUP_LIBS(path); setup_backend_plugins() }); static mut LIBS: Vec = Vec::new(); @@ -48,7 +54,7 @@ static SETUP_PLUGIN_DIR: fn() -> Option = || -> Option { } }; -static SETUP_LIBS: fn() = || { +static SETUP_LIBS: fn(path: Option<&str>) = |path| { if LIBS_LOADING.load(std::sync::atomic::Ordering::SeqCst) { while !LIBS_LOADED.load(std::sync::atomic::Ordering::SeqCst) { spin_loop(); @@ -93,7 +99,11 @@ static SETUP_LIBS: fn() = || { } }); }; - let plugin_dir = SETUP_PLUGIN_DIR(); + let plugin_dir = if let Some(path) = path { + Some(PathBuf::from(path)) + } else { + SETUP_PLUGIN_DIR() + }; unsafe { if PLUGIN_DIR.is_dir() { read_dir(PLUGIN_DIR.clone());