Skip to content

A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.

refactor(pluginKit): improve plugin registration process

robin62d2d2a8b356
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);
+ });
});
}