From 7d12963052f8be0883ebfe293a6c8ca6863feefa Mon Sep 17 00:00:00 2001 From: snowgitea Date: Wed, 1 Jul 2026 17:57:00 +0800 Subject: [PATCH] chore: src/modules/plugin/event/init.ts --- src/modules/plugin/event/init.ts | 36 ++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/modules/plugin/event/init.ts diff --git a/src/modules/plugin/event/init.ts b/src/modules/plugin/event/init.ts new file mode 100644 index 0000000..4a55409 --- /dev/null +++ b/src/modules/plugin/event/init.ts @@ -0,0 +1,36 @@ +import { CoolEvent, Event } from '@cool-midway/core'; +import { Inject } from '@midwayjs/core'; +import { PluginCenterService } from '../service/center'; + +// 插件初始化全局事件 +export const GLOBAL_EVENT_PLUGIN_INIT = 'globalPluginInit'; +// 插件移除全局事件 +export const GLOBAL_EVENT_PLUGIN_REMOVE = 'globalPluginRemove'; + +/** + * 接收事件 + */ +@CoolEvent() +export class PluginInitEvent { + @Inject() + pluginCenterService: PluginCenterService; + + /** + * 插件初始化事件,某个插件重新初始化 + * @param key + */ + @Event(GLOBAL_EVENT_PLUGIN_INIT) + async globalPluginInit(key: string) { + await this.pluginCenterService.initOne(key); + } + + /** + * 插件移除或者关闭事件 + * @param key + * @param isHook + */ + @Event(GLOBAL_EVENT_PLUGIN_REMOVE) + async globalPluginRemove(key: string, isHook: boolean) { + await this.pluginCenterService.remove(key, isHook); + } +}