Skip to content

Commit

Permalink
plugins: fix plugin dir
Browse files Browse the repository at this point in the history
  • Loading branch information
DashieTM committed Jun 1, 2024
1 parent 8130974 commit 04ee512
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 13 deletions.
13 changes: 12 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl fmt::Display for PathNotFoundError {
}
}

pub fn create_config(project_name: &str) -> Option<PathBuf> {
pub fn create_config_directory(project_name: &str) -> Option<PathBuf> {
let base_dir = xdg::BaseDirectories::new();
if base_dir.is_err() {
ERROR!("Could not get base directories", ErrorLevel::Critical);
Expand All @@ -44,6 +44,17 @@ pub fn create_config(project_name: &str) -> Option<PathBuf> {
ERROR!("Could not create config directory", ErrorLevel::Critical);
return None;
}
Some(config_dir.unwrap())
}

pub fn create_config(project_name: &str) -> Option<PathBuf> {
create_config_directory(project_name);
let base_dir = xdg::BaseDirectories::new();
if base_dir.is_err() {
ERROR!("Could not get base directories", ErrorLevel::Critical);
return None;
}
let base_dir = base_dir.unwrap();
let mut config_file = base_dir.find_config_file(format!("{}/ReSet.toml", project_name));
if config_file.is_none() {
let res = base_dir.place_config_file(format!("{}/ReSet.toml", project_name));
Expand Down
41 changes: 29 additions & 12 deletions src/utils/plugin_setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ use std::{
hint::spin_loop,
io::ErrorKind,
path::PathBuf,
sync::{Arc, atomic::AtomicBool, RwLock},
sync::{atomic::AtomicBool, Arc, RwLock},
};

use dbus_crossroads::{Crossroads, IfaceToken};
use libloading::Library;
use once_cell::sync::Lazy;
use toml::Value;

use crate::{create_config, ERROR, LOG};
use crate::{create_config, create_config_directory, ERROR, LOG};
#[cfg(debug_assertions)]
use crate::{utils::macros::ErrorLevel, write_log_to_file};

Expand All @@ -34,7 +34,7 @@ static mut LIBS: Vec<libloading::Library> = Vec::new();
pub static mut PLUGIN_DIR: Lazy<PathBuf> = Lazy::new(|| PathBuf::from(""));

static SETUP_PLUGIN_DIR: fn() -> Option<PathBuf> = || -> Option<PathBuf> {
let config = create_config("reset").expect("Could not create config directory");
let config = create_config_directory("reset").expect("Could not create config directory");
let plugin_dir = create_dir(config.join("plugins"));
if let Err(error) = plugin_dir {
if error.kind() != ErrorKind::AlreadyExists {
Expand Down Expand Up @@ -96,7 +96,7 @@ static SETUP_LIBS: fn() = || {
});
};
#[allow(clippy::borrow_interior_mutable_const)]
let plugin_dir = if let Some(config) = CONFIG.get("plugin_path") {
let plugin_dir = if let Some(config) = CONFIG.get("plugin_path") {
let config = config.as_str();
if config.is_none() {
SETUP_PLUGIN_DIR()
Expand Down Expand Up @@ -216,11 +216,13 @@ fn setup_frontend_plugins() -> Vec<FrontendPluginFunctions> {
data_frontend,
tests_frontend,
) {
(Ok(frontend_name),
(
Ok(frontend_name),
Ok(startup_frontend),
Ok(shutdown_frontend),
Ok(data_frontend),
Ok(tests_frontend)) => {
Ok(tests_frontend),
) => {
plugins.push(FrontendPluginFunctions::new(
capabilities.get_capabilities(),
frontend_name,
Expand All @@ -231,19 +233,34 @@ fn setup_frontend_plugins() -> Vec<FrontendPluginFunctions> {
));
}
(Err(error), _, _, _, _) => {
ERROR!(format!("Failed to load plugin function: {}", error), ErrorLevel::PartialBreakage);
ERROR!(
format!("Failed to load plugin function: {}", error),
ErrorLevel::PartialBreakage
);
}
(_, Err(error), _, _, _) => {
ERROR!(format!("Failed to load plugin function: {}", error), ErrorLevel::PartialBreakage);
ERROR!(
format!("Failed to load plugin function: {}", error),
ErrorLevel::PartialBreakage
);
}
(_, _, Err(error), _, _) => {
ERROR!(format!("Failed to load plugin function: {}", error), ErrorLevel::PartialBreakage);
ERROR!(
format!("Failed to load plugin function: {}", error),
ErrorLevel::PartialBreakage
);
}
(_, _, _, Err(error), _) => {
ERROR!(format!("Failed to load plugin function: {}", error), ErrorLevel::PartialBreakage);
ERROR!(
format!("Failed to load plugin function: {}", error),
ErrorLevel::PartialBreakage
);
}
(_, _, _, _, Err(error)) => {
ERROR!(format!("Failed to load plugin function: {}", error), ErrorLevel::PartialBreakage);
ERROR!(
format!("Failed to load plugin function: {}", error),
ErrorLevel::PartialBreakage
);
}
}
}
Expand Down Expand Up @@ -307,7 +324,7 @@ pub struct FrontendPluginFunctions {
pub frontend_startup: libloading::Symbol<'static, unsafe extern "C" fn()>,
pub frontend_shutdown: libloading::Symbol<'static, unsafe extern "C" fn()>,
pub frontend_data:
libloading::Symbol<'static, unsafe extern "C" fn() -> (SidebarInfo, Vec<gtk::Box>)>,
libloading::Symbol<'static, unsafe extern "C" fn() -> (SidebarInfo, Vec<gtk::Box>)>,
pub frontend_tests: libloading::Symbol<'static, unsafe extern "C" fn() -> Vec<PluginTestFunc>>,
}

Expand Down

0 comments on commit 04ee512

Please sign in to comment.