diff --git a/ica-rs/src/ica.rs b/ica-rs/src/ica.rs index b54d080..ccc921f 100644 --- a/ica-rs/src/ica.rs +++ b/ica-rs/src/ica.rs @@ -11,7 +11,7 @@ use crate::error::{ClientResult, IcaError}; use crate::{version_str, StopGetter}; /// icalingua 客户端的兼容版本号 -pub const ICA_PROTOCOL_VERSION: &str = "2.12.12"; +pub const ICA_PROTOCOL_VERSION: &str = "2.12.20"; pub async fn start_ica(config: &IcaConfig, stop_reciver: StopGetter) -> ClientResult<(), IcaError> { let span = span!(Level::INFO, "Icalingua Client"); diff --git a/ica-rs/src/py/config.rs b/ica-rs/src/py/config.rs index 522f6d3..dd9f9f5 100644 --- a/ica-rs/src/py/config.rs +++ b/ica-rs/src/py/config.rs @@ -57,6 +57,14 @@ impl PluginConfigFile { } } + fn get_table(&self) -> Option<&Table> { + self.data.get(CONFIG_KEY).and_then(|item| item.as_table()) + } + + fn get_table_mut(&mut self) -> Option<&mut Table> { + self.data.get_mut(CONFIG_KEY).and_then(|item| item.as_table_mut()) + } + /// 获取插件状态 /// 默认为 true pub fn get_status(&self, path: &Path) -> bool { @@ -73,6 +81,23 @@ impl PluginConfigFile { true } + /// 删掉一个状态 + pub fn remove_status(&mut self, path: &Path) -> Option { + let path_str = path.to_str().unwrap(); + if let Some(table) = self.get_table_mut() { + if let Some(item) = table.get_mut(path_str) { + if let Some(bool) = item.as_bool() { + table.remove(path_str); + return Some(bool); + } else { + table.remove(path_str); + return Some(false); + } + } + } + None + } + /// 设置插件状态 pub fn set_status(&mut self, path: &Path, status: bool) { self.verify_and_init(); diff --git a/ica-rs/src/py/mod.rs b/ica-rs/src/py/mod.rs index eb3c8d8..d9b243f 100644 --- a/ica-rs/src/py/mod.rs +++ b/ica-rs/src/py/mod.rs @@ -41,6 +41,11 @@ impl PyStatus { pub fn add_file(path: PathBuf, plugin: PyPlugin) { Self::get_map_mut().insert(path, plugin); } + /// 删除一个插件 + pub fn delete_file(path: &PathBuf) -> Option { + Self::get_map_mut().remove(path) + } + pub fn verify_file(path: &PathBuf) -> bool { Self::get_map().get(path).map_or(false, |plugin| plugin.verifiy()) }