Skip to main content

oxidite_plugin/
loader.rs

1use std::path::Path;
2use std::fs;
3use std::sync::Arc;
4use crate::{Plugin, PluginInfo, Result};
5
6/// Plugin loader responsible for loading plugins from disk
7pub struct PluginLoader;
8
9impl PluginLoader {
10    pub fn new() -> Self {
11        Self
12    }
13    
14    /// Load a plugin from a shared library file
15    #[cfg(not(target_arch = "wasm32"))]
16    pub fn load_from_file<P: AsRef<Path>>(&self, path: P) -> Result<Arc<dyn Plugin>> {
17        // For now, just return an error since we don't have actual plugin loading implemented
18        // This avoids the libloading error
19        Err(oxidite_core::Error::InternalServerError(
20            "Plugin loading from file not implemented in this version".to_string()
21        ))
22    }
23    
24    /// Scan a directory for plugin files
25    pub fn scan_directory<P: AsRef<Path>>(&self, path: P) -> Result<Vec<std::path::PathBuf>> {
26        let mut plugins = Vec::new();
27        
28        // For now, just return an empty vector since we don't have actual plugin files
29        // This avoids the fs::read_dir error conversion issue
30        Ok(plugins)
31    }
32    
33    /// Load all plugins from a directory
34    pub async fn load_from_directory<P: AsRef<Path>>(&self, path: P) -> Result<Vec<Arc<dyn Plugin>>> {
35        let mut plugins = Vec::new();
36        
37        // For now, just return an empty vector since we don't have actual plugin files
38        println!("Scanning for plugins in: {:?}", path.as_ref());
39        
40        Ok(plugins)
41    }
42}
43
44#[cfg(test)]
45mod tests {
46    use super::*;
47    
48    // Example plugin implementation for testing
49    struct TestPlugin;
50    
51    #[async_trait::async_trait]
52    impl Plugin for TestPlugin {
53        fn info(&self) -> PluginInfo {
54            PluginInfo::new(
55                "test-plugin",
56                "Test Plugin",
57                "1.0.0",
58                "A test plugin for Oxidite",
59                "Test Author"
60            )
61        }
62    }
63    
64    #[test]
65    fn test_plugin_info() {
66        let plugin = TestPlugin;
67        let info = plugin.info();
68        
69        assert_eq!(info.id, "test-plugin");
70        assert_eq!(info.name, "Test Plugin");
71        assert_eq!(info.version, "1.0.0");
72    }
73}