diff --git a/pkg/plugin/host.py b/pkg/plugin/host.py index 7868403c..d4bdeff1 100644 --- a/pkg/plugin/host.py +++ b/pkg/plugin/host.py @@ -36,8 +36,10 @@ def walk_plugin_path(module, prefix=''): """遍历插件路径""" for item in pkgutil.iter_modules(module.__path__): if item.ispkg: + logging.debug("扫描插件包: {}".format(item.name)) walk_plugin_path(__import__(module.__name__ + '.' + item.name, fromlist=['']), prefix + item.name + '.') else: + logging.debug("扫描插件模块: {}".format(item.name)) logging.info('加载模块: {}'.format(prefix + item.name)) importlib.import_module(module.__name__ + '.' + item.name) @@ -142,6 +144,9 @@ class EventContext: def __init__(self, name: str): self.name = name self.eid = EventContext.eid + self.__prevent_default__ = False + self.__prevent_postorder__ = False + self.__return_value__ = {} EventContext.eid += 1 @@ -182,6 +187,7 @@ class PluginHost: def emit(self, event_name: str, **kwargs) -> EventContext: """ 触发事件 """ event_context = EventContext(event_name) + logging.debug("触发事件: {} ({})".format(event_name, event_context.eid)) for plugin in __plugins__.values(): for hook in plugin['hooks'].get(event_name, []): try: diff --git a/pkg/utils/reloader.py b/pkg/utils/reloader.py index fc9f80d8..7e436678 100644 --- a/pkg/utils/reloader.py +++ b/pkg/utils/reloader.py @@ -4,6 +4,7 @@ import threading import importlib import pkgutil import pkg.utils.context +import pkg.plugin.host def walk(module, prefix=''): @@ -32,9 +33,12 @@ def reload_all(notify=True): importlib.reload(__import__('config')) importlib.reload(__import__('main')) importlib.reload(__import__('banlist')) - importlib.reload(__import__('plugins')) pkg.utils.context.context = context + # 重载插件 + import plugins + walk(plugins) + # 执行启动流程 logging.info("执行程序启动流程") threading.Thread(target=main.main, args=(False,), daemon=False).start()