YuKun Liu пре 2 година
родитељ
комит
f238e43bff
3 измењених фајлова са 14 додато и 24 уклоњено
  1. 5 6
      src/config.rs
  2. 5 6
      src/main.rs
  3. 4 12
      src/plugin/mod.rs

+ 5 - 6
src/config.rs

@@ -1,4 +1,4 @@
-use crate::{error::Result, plugin::PluginConfig};
+use crate::error::Result;
 use serde::{Deserialize, Serialize};
 use std::{collections::HashMap, fs::File, io::Read, path::PathBuf};
 
@@ -6,6 +6,7 @@ use std::{collections::HashMap, fs::File, io::Read, path::PathBuf};
 pub struct DioxusConfig {
     pub application: ApplicationConfig,
     pub web: WebConfig,
+    pub plugin: toml::Value,
 }
 
 impl DioxusConfig {
@@ -36,8 +37,7 @@ impl Default for DioxusConfig {
                 asset_dir: Some(PathBuf::from("public")),
 
                 tools: None,
-                plugins: None,
-                
+
                 sub_package: None,
             },
             web: WebConfig {
@@ -59,6 +59,7 @@ impl Default for DioxusConfig {
                     script: Some(vec![]),
                 },
             },
+            plugin: toml::Value::Table(toml::map::Map::new())
         }
     }
 }
@@ -69,9 +70,8 @@ pub struct ApplicationConfig {
     pub default_platform: String,
     pub out_dir: Option<PathBuf>,
     pub asset_dir: Option<PathBuf>,
-    
+
     pub tools: Option<HashMap<String, toml::Value>>,
-    pub plugins: Option<PluginConfig>,
 
     pub sub_package: Option<String>,
 }
@@ -223,5 +223,4 @@ impl CrateConfig {
         self.features = Some(features);
         self
     }
-
 }

+ 5 - 6
src/main.rs

@@ -1,5 +1,5 @@
 use clap::Parser;
-use dioxus_cli::{*, plugin::{PluginManager, PluginConfig}};
+use dioxus_cli::{plugin::PluginManager, *};
 use std::process::exit;
 
 #[tokio::main]
@@ -7,11 +7,10 @@ async fn main() -> Result<()> {
     let args = Cli::parse();
     set_up_logging();
 
-    let plugin_state = PluginManager::init(&PluginConfig {
-        available: true,
-        required: vec![],
-    });
-    
+    let dioxus_config = DioxusConfig::load()?;
+
+    let plugin_state = PluginManager::init(dioxus_config.plugin);
+
     if let Err(e) = plugin_state {
         log::error!("🚫 Plugin system initialization failed: {e}");
         exit(1);

+ 4 - 12
src/plugin/mod.rs

@@ -5,7 +5,6 @@ use std::{
 };
 
 use mlua::{AsChunk, Lua, Table};
-use serde::{Deserialize, Serialize};
 use serde_json::json;
 
 use crate::{
@@ -28,23 +27,16 @@ lazy_static::lazy_static! {
     static ref LUA: Mutex<Lua> = Mutex::new(Lua::new());
 }
 
-#[derive(Debug, Clone, Serialize, Deserialize)]
-pub struct PluginConfig {
-    pub available: bool,
-    pub required: Vec<String>,
-}
-
 pub struct PluginManager;
 
 impl PluginManager {
-    pub fn init(config: &PluginConfig) -> anyhow::Result<()> {
+    pub fn init(config: toml::Value) -> anyhow::Result<()> {
         let lua = LUA.lock().unwrap();
 
-        if !config.available {
-            // // if plugin system is available, just set manager to nil.
-            // lua.globals().set("manager", mlua::Value::Nil).unwrap();
+        if !config.is_table() {
+            // if plugins config is not a table, then termination init
             return Ok(());
-       }
+        }
 
         let manager = lua.create_table().unwrap();
         let plugin_dir = Self::init_plugin_dir();