merge develop into master #20

Merged
michael-bailey merged 181 commits from develop into master 2023-12-01 21:48:28 +00:00
2 changed files with 27 additions and 6 deletions
Showing only changes of commit 83c8a6c2b7 - Show all commits

View File

@ -1,7 +1,10 @@
use std::collections::HashMap;
use std::io::Error;
use std::sync::Arc;
use libloading::Library;
use crate::plugin::Plugin::Plugin;
use tokio::fs::{create_dir, File, read_dir};
use crate::plugin::plugin::{Plugin, PluginDetailsFn, TestPluginFn};
use crate::plugin::plugin_details::PluginDetails;
/// # PluginManager
///
@ -20,11 +23,28 @@ impl PluginManager {
})
}
pub async fn load(&self) {
unsafe {
println!("[PluginManager]: loading plugins");
println!("[PluginManager]: from: {}", std::env::current_dir().unwrap().to_string_lossy());
let lib = Library::new("./plugins")?;
pub async fn load(&self) -> Result<(), Error> {
println!("[PluginManager]: loading plugins");
println!("[PluginManager]: from: {}", std::env::current_dir().unwrap().to_string_lossy());
if let Ok( mut plugins) = read_dir("./plugins").await {
while let Some(child) = plugins.next_entry().await? {
let metadata = child.metadata().await?;
if metadata.is_file() && child.path().extension().unwrap() == "dylib" {
println!("[PluginManager]: Library at:{}", child.path().to_string_lossy());
unsafe {
let lib = Library::new(child.path()).unwrap();
let get_details = lib.get::<PluginDetailsFn>("details".as_ref()).unwrap();
let details = get_details();
println!("[PluginManager]: got details: {}", details);
};
}
}
} else {
create_dir("./plugins").await?;
}
Ok(())
}
}

View File

@ -120,6 +120,7 @@ impl Server {
// start client manager and network manager
self.network_manager.clone().start();
self.client_manager.clone().start();
let _ = self.plugin_manager.clone().load().await;
// clone block items
let server = self.clone();