From 04ee512b97653d1d7c7a3beb0511330cb9fa9bb1 Mon Sep 17 00:00:00 2001 From: DashieTM Date: Sat, 1 Jun 2024 16:45:53 +0200 Subject: [PATCH] plugins: fix plugin dir --- src/lib.rs | 13 ++++++++++++- src/utils/plugin_setup.rs | 41 +++++++++++++++++++++++++++------------ 2 files changed, 41 insertions(+), 13 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index ce06f01..6fe7228 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -32,7 +32,7 @@ impl fmt::Display for PathNotFoundError { } } -pub fn create_config(project_name: &str) -> Option { +pub fn create_config_directory(project_name: &str) -> Option { let base_dir = xdg::BaseDirectories::new(); if base_dir.is_err() { ERROR!("Could not get base directories", ErrorLevel::Critical); @@ -44,6 +44,17 @@ pub fn create_config(project_name: &str) -> Option { ERROR!("Could not create config directory", ErrorLevel::Critical); return None; } + Some(config_dir.unwrap()) +} + +pub fn create_config(project_name: &str) -> Option { + 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)); diff --git a/src/utils/plugin_setup.rs b/src/utils/plugin_setup.rs index 3f916b5..7578562 100644 --- a/src/utils/plugin_setup.rs +++ b/src/utils/plugin_setup.rs @@ -3,7 +3,7 @@ use std::{ hint::spin_loop, io::ErrorKind, path::PathBuf, - sync::{Arc, atomic::AtomicBool, RwLock}, + sync::{atomic::AtomicBool, Arc, RwLock}, }; use dbus_crossroads::{Crossroads, IfaceToken}; @@ -11,7 +11,7 @@ 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}; @@ -34,7 +34,7 @@ static mut LIBS: Vec = Vec::new(); pub static mut PLUGIN_DIR: Lazy = Lazy::new(|| PathBuf::from("")); static SETUP_PLUGIN_DIR: fn() -> Option = || -> Option { - 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 { @@ -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() @@ -216,11 +216,13 @@ fn setup_frontend_plugins() -> Vec { 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, @@ -231,19 +233,34 @@ fn setup_frontend_plugins() -> Vec { )); } (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 + ); } } } @@ -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)>, + libloading::Symbol<'static, unsafe extern "C" fn() -> (SidebarInfo, Vec)>, pub frontend_tests: libloading::Symbol<'static, unsafe extern "C" fn() -> Vec>, }