From ac4df58eec0b3c4a30937abac3f4608b10a343c9 Mon Sep 17 00:00:00 2001 From: ningmengchongshui <916415899@qq.com> Date: Sat, 15 Jun 2024 14:11:05 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E4=B8=8A=E4=B8=8B?= =?UTF-8?q?=E6=96=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/.gitignore | 3 --- src/core/plugins.loader.ts | 39 ++++++++++++++++++++++---------------- src/core/plugins/index.ts | 2 +- 3 files changed, 24 insertions(+), 20 deletions(-) delete mode 100644 plugins/.gitignore diff --git a/plugins/.gitignore b/plugins/.gitignore deleted file mode 100644 index a00b05c..0000000 --- a/plugins/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -genshin -system-plugin -miao-plugin \ No newline at end of file diff --git a/src/core/plugins.loader.ts b/src/core/plugins.loader.ts index 967b6d4..c0e424c 100644 --- a/src/core/plugins.loader.ts +++ b/src/core/plugins.loader.ts @@ -340,27 +340,34 @@ class PluginsLoader { * */ for (const plugin of priority) { - /** - * 上下文hook - */ - if (!plugin.getContext) continue + if (!plugin?.getContext) continue const context = { ...plugin.getContext(), ...plugin.getContext(false, true) } - if (!lodash.isEmpty(context)) { - let ret - for (const fnc in context) { - // 不是函数,错误插件错误写法 - if (typeof plugin[fnc] !== 'function') { - continue - } - ret ||= await plugin[fnc](context[fnc]) - } - // 返回continue时,继续响应后续插件 - if (ret === 'continue') continue - return + + if (lodash.isEmpty(context)) { + continue } + + // 不为空的时候 + let ret = false + + // 从方法里执行 + for (const fnc in context) { + // 不是函数,错误插件错误写法 + if (typeof plugin[fnc] !== 'function') { + continue + } + ret = await plugin[fnc](context[fnc]) + } + + // 不是约定的直接 + if (typeof ret != 'boolean' && ret !== true) { + break + } + + // } /** diff --git a/src/core/plugins/index.ts b/src/core/plugins/index.ts index 537c852..b8edc5d 100644 --- a/src/core/plugins/index.ts +++ b/src/core/plugins/index.ts @@ -210,7 +210,7 @@ export class Plugin { * @param isGroup * @returns */ - getContext(type: string, isGroup?: boolean) { + getContext(type?: string, isGroup?: boolean) { if (type) return State[this.conKey(isGroup)]?.[type] return State[this.conKey(isGroup)] }