feat: commit code
This commit is contained in:
1 parent
5104f767b3
commit
f238e43bff
3 files changed
+11
-21
No files matched your search
+3
-4
@@ -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,7 +37,6 @@ impl Default for DioxusConfig {
|
||||
asset_dir: Some(PathBuf::from("public")),
|
||||
|
||||
tools: None,
|
||||
plugins: None,
|
||||
|
||||
sub_package: None,
|
||||
},
|
||||
@@ -59,6 +59,7 @@ impl Default for DioxusConfig {
|
||||
script: Some(vec![]),
|
||||
},
|
||||
},
|
||||
plugin: toml::Value::Table(toml::map::Map::new())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -71,7 +72,6 @@ pub struct ApplicationConfig {
|
||||
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
|
||||
}
|
||||
|
||||
}
|
||||
+4
-5
@@ -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,10 +7,9 @@ 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}");
|
||||
|
||||
+4
-12
@@ -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();
|
||||
|
||||
Reference in new issue
Block a user