Skip to content

Commit

Permalink
plugins: Add explicit enabling of each plugin per config
Browse files Browse the repository at this point in the history
  • Loading branch information
DashieTM committed May 25, 2024
1 parent d4089a4 commit 4682d3b
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use serial_test::serial;
#[cfg(test)]
use crate::utils::plugin::plugin_tests;
#[cfg(test)]
use crate::{utils::macros::ErrorLevel, ERROR, LOG, write_log_to_file};
use crate::{utils::macros::ErrorLevel, write_log_to_file, ERROR, LOG};
#[cfg(test)]
use crate::{utils::plugin::PluginTestError, utils::plugin::PluginTestFunc};

Expand Down
2 changes: 1 addition & 1 deletion src/utils/gtk/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pub mod widgets;
pub mod utils;
pub mod widgets;
1 change: 1 addition & 0 deletions src/utils/gtk/widgets.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

3 changes: 1 addition & 2 deletions src/utils/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ macro_rules! LOG {
#[macro_export]
#[cfg(not(debug_assertions))]
macro_rules! ERROR {
($message:expr, $level:expr ) => {{
}};
($message:expr, $level:expr ) => {{}};
}

#[macro_export]
Expand Down
4 changes: 2 additions & 2 deletions src/utils/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
pub mod config;
pub mod dbus_utils;
pub mod flags;
pub mod gtk;
pub mod macros;
pub mod plugin;
pub mod plugin_setup;
pub mod variant;
pub mod config;
pub mod gtk;
17 changes: 16 additions & 1 deletion src/utils/plugin_setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ use crate::{create_config, ERROR};
#[cfg(debug_assertions)]
use crate::{utils::macros::ErrorLevel, write_log_to_file};

use super::plugin::{PluginCapabilities, PluginImplementation, PluginTestFunc, SidebarInfo};
use super::{
config::CONFIG,
plugin::{PluginCapabilities, PluginImplementation, PluginTestFunc, SidebarInfo},
};

pub static LIBS_LOADED: AtomicBool = AtomicBool::new(false);
pub static LIBS_LOADING: AtomicBool = AtomicBool::new(false);
Expand Down Expand Up @@ -53,9 +56,21 @@ static SETUP_LIBS: fn() = || {
}
LIBS_LOADING.store(true, std::sync::atomic::Ordering::SeqCst);
let read_dir: fn(PathBuf) = |dir: PathBuf| {
let plugins = CONFIG.get("plugins");
if plugins.is_none() {
return;
}
let plugins = plugins.unwrap().as_array();
if plugins.is_none() {
return;
}
let plugins = plugins.unwrap();
let plugin_dir = dir.read_dir().expect("Could not read directory");
plugin_dir.for_each(|plugin| {
if let Ok(file) = plugin {
if !plugins.contains(file.file_name()) {
return;
}
unsafe {
let path = file.path();
let lib = libloading::Library::new(&path);
Expand Down
2 changes: 0 additions & 2 deletions src/utils/variant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -477,5 +477,3 @@ fn test_conversion_tuple_same_type() {
assert_eq!(converted_value.0, comparison_value.0);
assert_eq!(converted_value.1, comparison_value.1);
}

// TODO: explain the "superflous" existence of this file

0 comments on commit 4682d3b

Please sign in to comment.