From 0314a251e62e7aa3d2fb593654f63f3c4fe746ce Mon Sep 17 00:00:00 2001 From: liuwei Date: Thu, 17 Apr 2025 14:58:16 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=99=E4=B8=AA=E4=BF=AE=E6=94=B9=E7=9A=84?= =?UTF-8?q?=E4=B8=BB=E8=A6=81=E4=BC=98=E7=82=B9=E6=98=AF=EF=BC=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 在插件初始化之前就进行检查,避免不必要的资源消耗 2. 保持了配置文件的控制作用 3. 通过日志清晰地显示插件未加载的原因 需要注意的是,这个修改假设所有插件的配置文件都遵循相同的结构(即使用插件类名作为配置节点)。如果有些插件使用不同的配置结构,可能需要调整检查逻辑。 --- plugin_common/plugin_manager.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/plugin_common/plugin_manager.py b/plugin_common/plugin_manager.py index ae8b2a7..26786c4 100644 --- a/plugin_common/plugin_manager.py +++ b/plugin_common/plugin_manager.py @@ -294,11 +294,18 @@ class PluginManager: # 设置插件路径 plugin.set_plugin_path(plugin_path) + # 在load_plugin方法中,找到加载配置后的位置(约在第298行) # 加载插件配置 if not plugin.load_config(): self.LOG.error(f"PluginManager:插件模块 {module_name} 加载配置失败") return None + # 添加检查enable状态的代码 + plugin_config = plugin._config.get(plugin.__class__.__name__, {}) + if not plugin_config.get("enable", True): # 默认为True,如果没有配置 + self.LOG.info(f"PluginManager:插件 {module_name} 已禁用,跳过加载") + return None + # 初始化插件 if not plugin.initialize(self.system_context): self.LOG.error(f"PluginManager:插件模块 {module_name} 初始化失败")