This is an automated email from the ASF dual-hosted git repository.

robin0716 pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/incubator-answer.git

commit 62d2d2a8b356043ca1eb5ff8c4d6d46c9c76c7c4
Author: robin <[email protected]>
AuthorDate: Tue Oct 8 16:50:14 2024 +0800

    refactor(pluginKit): improve plugin registration process
---
 ui/src/utils/pluginKit/index.ts | 31 ++++++++++++++++++++++---------
 1 file changed, 22 insertions(+), 9 deletions(-)

diff --git a/ui/src/utils/pluginKit/index.ts b/ui/src/utils/pluginKit/index.ts
index 12cd0247..920b0a3c 100644
--- a/ui/src/utils/pluginKit/index.ts
+++ b/ui/src/utils/pluginKit/index.ts
@@ -49,12 +49,12 @@ class Plugins {
 
   constructor() {
     this.registerBuiltin();
-    this.registerPlugins();
-
-    getPluginsStatus().then((plugins) => {
-      this.registeredPlugins = plugins;
-      this.activatePlugins(plugins);
-    });
+    this.registerPlugins()
+      .then(getPluginsStatus)
+      .then((plugins) => {
+        this.registeredPlugins = plugins;
+        this.activatePlugins(plugins);
+      });
   }
 
   validate(plugin: Plugin) {
@@ -75,6 +75,15 @@ class Plugins {
     return true;
   }
 
+  async loadPlugins() {
+    return Promise.all(
+      Object.keys(allPlugins).map(async (key) => {
+        const plugin = await allPlugins[key]();
+        return plugin;
+      }),
+    );
+  }
+
   registerBuiltin() {
     Object.keys(builtin).forEach((key) => {
       const plugin = builtin[key];
@@ -86,9 +95,13 @@ class Plugins {
   }
 
   registerPlugins() {
-    Object.keys(allPlugins).forEach((key) => {
-      const plugin = allPlugins[key];
-      this.register(plugin);
+    return new Promise((resolve) => {
+      this.loadPlugins().then((plugins) => {
+        plugins.forEach((plugin) => {
+          this.register(plugin);
+        });
+        resolve(true);
+      });
     });
   }
 

Reply via email to