From 18a6f04c071f7a0735eb39b8c67fd51a082d1a31 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 8 Jul 2019 15:54:08 +0200 Subject: WIP plugins: hook on client side --- server/lib/plugins/plugin-manager.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'server/lib/plugins') diff --git a/server/lib/plugins/plugin-manager.ts b/server/lib/plugins/plugin-manager.ts index b898e64fa..7cbfa8569 100644 --- a/server/lib/plugins/plugin-manager.ts +++ b/server/lib/plugins/plugin-manager.ts @@ -75,6 +75,27 @@ export class PluginManager { return registered } + getRegisteredPlugins () { + return this.registeredPlugins + } + + async runHook (hookName: string, param?: any) { + let result = param + + const wait = hookName.startsWith('static:') + + for (const hook of this.hooks[hookName]) { + try { + if (wait) result = await hook.handler(param) + else result = hook.handler() + } catch (err) { + logger.error('Cannot run hook %s of plugin %s.', hookName, hook.pluginName, { err }) + } + } + + return result + } + async unregister (name: string) { const plugin = this.getRegisteredPlugin(name) -- cgit v1.2.3