看着没问题?

This commit is contained in:
shenjack 2025-01-06 21:23:26 +08:00
parent 974c2577c3
commit 9711af9444
Signed by: shenjack
GPG Key ID: 7B1134A979775551
5 changed files with 48 additions and 4 deletions

View File

@ -255,6 +255,19 @@ impl IcaClientPy {
/// 返回是否成功
pub fn reload_plugin_status(&self) -> bool { PyStatus::get_mut().config.reload_from_default() }
/// 设置某个插件的状态
pub fn set_plugin_status(&self, plugin_name: String, status: bool) {
PyStatus::get_mut().set_status(&plugin_name, status);
}
pub fn get_plugin_status(&self, plugin_name: String) -> Option<bool> {
PyStatus::get().get_status(&plugin_name)
}
/// 同步状态到配置文件
/// 这样关闭的时候就会保存状态
pub fn sync_status_to_config(&self) { PyStatus::get_mut().config.sync_status_to_config(); }
/// 重新加载插件
///
/// 返回是否成功

View File

@ -77,6 +77,19 @@ impl TailchatClientPy {
/// 返回是否成功
pub fn reload_plugin_status(&self) -> bool { PyStatus::get_mut().config.reload_from_default() }
/// 设置某个插件的状态
pub fn set_plugin_status(&self, plugin_name: String, status: bool) {
PyStatus::get_mut().set_status(&plugin_name, status);
}
pub fn get_plugin_status(&self, plugin_name: String) -> Option<bool> {
PyStatus::get().get_status(&plugin_name)
}
/// 同步状态到配置文件
/// 这样关闭的时候就会保存状态
pub fn sync_status_to_config(&self) { PyStatus::get_mut().config.sync_status_to_config(); }
/// 重新加载插件
///
/// 返回是否成功

View File

@ -162,6 +162,13 @@ impl PluginConfigFile {
});
}
pub fn write_to_default(&self) -> Result<(), std::io::Error> {
let config_path = MainStatus::global_config().py().config_path.clone();
let config_path = Path::new(&config_path);
let path = config_path.join(CONFIG_FILE_NAME);
self.write_to_file(&path)
}
pub fn write_to_file(&self, path: &PathBuf) -> Result<(), std::io::Error> {
let config_path = path.join(CONFIG_FILE_NAME);
std::fs::write(config_path, self.data.to_string())?;

View File

@ -434,9 +434,8 @@ pub fn init_py() {
}
pub fn post_py() -> anyhow::Result<()> {
PyStatus::get_mut().config.sync_status_to_config();
PyStatus::get()
.config
.write_to_file(&PathBuf::from(MainStatus::global_config().py().config_path))?;
let status = PyStatus::get_mut();
status.config.sync_status_to_config();
status.config.write_to_default()?;
Ok(())
}

12
news.md
View File

@ -23,6 +23,12 @@
- 用于重新加载插件状态
- 添加了 `reload_plugin(plugin_name: str)` api
- 用于重新加载指定插件
- 添加了 `set_plugin_status(plugin_name: str, status: bool)` api
- 用于设置插件的启用状态
- 添加了 `get_plugin_status(plugin_name: str) -> bool` api
- 用于获取插件的启用状态
- 添加了 `sync_status_to_config` api
- 用于将内存中的插件状态同步到配置文件中
### tailchat 1.2.5
@ -30,6 +36,12 @@
- 用于重新加载插件状态
- 添加了 `reload_plugin(plugin_name: str)` api
- 用于重新加载指定插件
- 添加了 `set_plugin_status(plugin_name: str, status: bool)` api
- 用于设置插件的启用状态
- 添加了 `get_plugin_status(plugin_name: str) -> bool` api
- 用于获取插件的启用状态
- 添加了 `sync_status_to_config` api
- 用于将内存中的插件状态同步到配置文件中
## 0.7.4