diff --git a/src/config.rs b/src/config.rs index 3d6fe65a4..309dcd9c0 100644 --- a/src/config.rs +++ b/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, pub asset_dir: Option, - + pub tools: Option>, - pub plugins: Option, pub sub_package: Option, } @@ -223,5 +223,4 @@ impl CrateConfig { self.features = Some(features); self } - } diff --git a/src/main.rs b/src/main.rs index 300d4ef73..db8bbb6b7 100644 --- a/src/main.rs +++ b/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); diff --git a/src/plugin/mod.rs b/src/plugin/mod.rs index 4253280a1..464c83434 100644 --- a/src/plugin/mod.rs +++ b/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 = Mutex::new(Lua::new()); } -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct PluginConfig { - pub available: bool, - pub required: Vec, -} - 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();