feat: commit dirs library

This commit is contained in:
mrxiaozhuox committed 2022-07-30 09:57:38 +08:00
1 parent 3630224659
commit 54dc59360e
3 files changed
+38 -3

No files matched your search

+29
View File
@@ -0,0 +1,29 @@
use mlua::UserData;
use crate::tools::app_path;
pub struct PluginDirs;
impl UserData for PluginDirs {
fn add_methods<'lua, M: mlua::UserDataMethods<'lua, Self>>(methods: &mut M) {
methods.add_function("plugin_dir", |_, ()| {
let path = app_path().join("plugins");
Ok(path.to_str().unwrap().to_string())
});
methods.add_function("self_dir", |_, name: String| {
let path = app_path().join("plugins").join(name);
Ok(path.to_str().unwrap().to_string())
});
methods.add_function("document_dir", |_, ()| {
let path = dirs::document_dir().unwrap().to_str().unwrap().to_string();
Ok(path)
});
methods.add_function("download_dir", |_, ()| {
let path = dirs::download_dir().unwrap().to_str().unwrap().to_string();
Ok(path)
});
methods.add_function("cache_dir", |_, ()| {
let path = dirs::cache_dir().unwrap().to_str().unwrap().to_string();
Ok(path)
});
}
}
+1
View File
@@ -4,6 +4,7 @@ pub mod logger;
pub mod command;
pub mod fs;
pub mod download;
pub mod dirs;
#[derive(Debug)]
pub struct PluginInfo<'lua> {
+8 -3
View File
@@ -7,7 +7,10 @@ use crate::tools::{app_path, clone_repo};
use self::{
interface::PluginInfo,
interface::{command::PluginCommander, logger::PluginLogger, fs::PluginFileSystem, download::PluginDownloader},
interface::{
command::PluginCommander, download::PluginDownloader, fs::PluginFileSystem,
logger::PluginLogger,
},
};
pub mod interface;
@@ -37,7 +40,9 @@ impl PluginManager {
.set("PLUGIN_COMMAND", PluginCommander)
.unwrap();
lua.globals().set("PLUGIN_FS", PluginFileSystem).unwrap();
lua.globals().set("PLUGIN_DOWNLOAD", PluginDownloader).unwrap();
lua.globals()
.set("PLUGIN_DOWNLOAD", PluginDownloader)
.unwrap();
let plugin_dir = Self::init_plugin_dir();
let mut index = 1;
@@ -60,10 +65,10 @@ impl PluginManager {
}
}
lua.globals().set("manager", manager).unwrap();
lua.globals()
.set("LIBDIR", plugin_dir.join("library").to_str().unwrap())
.unwrap();
lua.globals().set("manager", manager).unwrap();
Some(Self { lua })
}