From 4eb553473d6f143de43f6433041767436551e5f7 Mon Sep 17 00:00:00 2001 From: shenjack <3695888@qq.com> Date: Tue, 11 Feb 2025 23:15:20 +0800 Subject: [PATCH] a ? --- ica-rs/src/ica.rs | 2 +- ica-rs/src/py/call.rs | 9 ++++++--- ica-rs/src/py/mod.rs | 38 +++++++++++++++++++++++--------------- news.md | 1 + 4 files changed, 31 insertions(+), 19 deletions(-) diff --git a/ica-rs/src/ica.rs b/ica-rs/src/ica.rs index c8e3d53..f8a0beb 100644 --- a/ica-rs/src/ica.rs +++ b/ica-rs/src/ica.rs @@ -13,7 +13,7 @@ use crate::error::{ClientResult, IcaError}; use crate::{version_str, StopGetter}; /// icalingua 客户端的兼容版本号 -pub const ICA_PROTOCOL_VERSION: &str = "2.12.26"; +pub const ICA_PROTOCOL_VERSION: &str = "2.12.28"; // mod status { // use crate::data_struct::ica::all_rooms::Room; diff --git a/ica-rs/src/py/call.rs b/ica-rs/src/py/call.rs index 882df40..a968077 100644 --- a/ica-rs/src/py/call.rs +++ b/ica-rs/src/py/call.rs @@ -26,14 +26,17 @@ impl PyTasks { pub fn push_ica_new_message(&mut self, handle: tokio::task::JoinHandle<()>) { self.ica_new_message.push(handle); + self.ica_new_message.retain(|handle| !handle.is_finished()); } pub fn push_ica_delete_message(&mut self, handle: tokio::task::JoinHandle<()>) { self.ica_delete_message.push(handle); + self.ica_delete_message.retain(|handle| !handle.is_finished()); } pub fn push_tailchat_new_message(&mut self, handle: tokio::task::JoinHandle<()>) { self.tailchat_new_message.push(handle); + self.tailchat_new_message.retain(|handle| !handle.is_finished()); } pub async fn join_all(&mut self) { @@ -221,7 +224,7 @@ pub async fn ica_new_message_py(message: &ica::messages::NewMessage, client: &Cl let client = class::ica::IcaClientPy::new(client); let args = (msg, client); let task = call_py_func!(args, plugin, path, ICA_NEW_MESSAGE_FUNC, client); - PY_TASKS.lock().await.push_ica_new_message(task); + // PY_TASKS.lock().await.push_ica_new_message(task); } } @@ -234,7 +237,7 @@ pub async fn ica_delete_message_py(msg_id: ica::MessageId, client: &Client) { let client = class::ica::IcaClientPy::new(client); let args = (msg_id.clone(), client); let task = call_py_func!(args, plugin, path, ICA_DELETE_MESSAGE_FUNC, client); - PY_TASKS.lock().await.push_ica_delete_message(task); + // PY_TASKS.lock().await.push_ica_delete_message(task); } } @@ -250,6 +253,6 @@ pub async fn tailchat_new_message_py( let client = class::tailchat::TailchatClientPy::new(client); let args = (msg, client); let task = call_py_func!(args, plugin, path, TAILCHAT_NEW_MESSAGE_FUNC, client); - PY_TASKS.lock().await.push_tailchat_new_message(task); + // PY_TASKS.lock().await.push_tailchat_new_message(task); } } diff --git a/ica-rs/src/py/mod.rs b/ica-rs/src/py/mod.rs index 0500e72..dae8080 100644 --- a/ica-rs/src/py/mod.rs +++ b/ica-rs/src/py/mod.rs @@ -14,7 +14,7 @@ use pyo3::prelude::*; use pyo3::types::PyTuple; use tracing::{event, span, warn, Level}; -use crate::{MainStatus, StopGetter}; +use crate::MainStatus; #[derive(Debug, Clone)] pub struct PyStatus { @@ -39,12 +39,18 @@ impl PyStatus { let _ = unsafe { PyPluginStatus.get_or_init(|| status) }; } - pub fn get() -> &'static PyStatus { unsafe { PyPluginStatus.get().unwrap() } } + pub fn get() -> &'static PyStatus { + unsafe { PyPluginStatus.get().unwrap() } + } - pub fn get_mut() -> &'static mut PyStatus { unsafe { PyPluginStatus.get_mut().unwrap() } } + pub fn get_mut() -> &'static mut PyStatus { + unsafe { PyPluginStatus.get_mut().unwrap() } + } /// 添加一个插件 - pub fn add_file(&mut self, path: PathBuf, plugin: PyPlugin) { self.files.insert(path, plugin); } + pub fn add_file(&mut self, path: PathBuf, plugin: PyPlugin) { + self.files.insert(path, plugin); + } /// 重新加载一个插件 pub fn reload_plugin(&mut self, plugin_name: &str) -> bool { @@ -64,7 +70,9 @@ impl PyStatus { } /// 删除一个插件 - pub fn delete_file(&mut self, path: &PathBuf) -> Option { self.files.remove(path) } + pub fn delete_file(&mut self, path: &PathBuf) -> Option { + self.files.remove(path) + } pub fn get_status(&self, pluging_id: &str) -> Option { self.files.iter().find_map(|(_, plugin)| { @@ -187,7 +195,9 @@ impl PyPlugin { } } - pub fn get_id(&self) -> String { plugin_path_as_id(&self.file_path) } + pub fn get_id(&self) -> String { + plugin_path_as_id(&self.file_path) + } } impl Display for PyPlugin { @@ -344,7 +354,7 @@ impl TryFrom for PyPlugin { } /// 插件路径转换为 id -pub fn plugin_path_as_id(path: &PathBuf) -> String { +pub fn plugin_path_as_id(path: &Path) -> String { path.file_name() .unwrap_or_default() .to_str() @@ -388,7 +398,9 @@ pub fn load_py_plugins(path: &PathBuf) { ); } -pub fn get_change_time(path: &Path) -> Option { path.metadata().ok()?.modified().ok() } +pub fn get_change_time(path: &Path) -> Option { + path.metadata().ok()?.modified().ok() +} pub fn py_module_from_code(content: &str, path: &Path) -> PyResult> { Python::with_gil(|py| -> PyResult> { @@ -430,11 +442,7 @@ fn init_py_with_env_path(path: &str) { let wide_path = OsStr::new(path).encode_wide().chain(Some(0)).collect::>(); // 设置 prefix 和 exec_prefix - pyo3::ffi::PyConfig_SetString( - config_ptr, - &mut config.prefix as *mut _, - wide_path.as_ptr(), - ); + pyo3::ffi::PyConfig_SetString(config_ptr, &mut config.prefix as *mut _, wide_path.as_ptr()); pyo3::ffi::PyConfig_SetString( config_ptr, &mut config.exec_prefix as *mut _, @@ -505,7 +513,7 @@ pub async fn post_py() -> anyhow::Result<()> { status.config.sync_status_to_config(); status.config.write_to_default()?; - stop_tasks().await; + // stop_tasks().await; Ok(()) } @@ -518,7 +526,7 @@ async fn stop_tasks() { event!(Level::INFO, "Python 任务完成"); } _ = tokio::signal::ctrl_c() => { - call::PY_TASKS.lock().await.cancel_all(); + // call::PY_TASKS.lock().await.cancel_all(); event!(Level::INFO, "Python 任务被中断"); } } diff --git a/news.md b/news.md index 372170d..da0bca3 100644 --- a/news.md +++ b/news.md @@ -2,6 +2,7 @@ ## 0.8.2 +- ica 兼容版本号更新到 `2.12.28` - 现在支持通过读取环境变量里的 `VIRTUAL_ENV` 来获取虚拟环境路径 - 用于在虚拟环境中运行插件 - 添加了 `-h` 参数