@bbki.ng/site 1.8.8 → 1.8.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # @bbki.ng/site
2
2
 
3
+ ## 1.8.9
4
+
3
5
  ## 1.8.8
4
6
 
5
7
  ## 1.8.7
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bbki.ng/site",
3
- "version": "1.8.8",
3
+ "version": "1.8.9",
4
4
  "description": "code behind bbki.ng",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -5,6 +5,7 @@ import { PluginInput } from "@/plugin/Plugin";
5
5
  import { toast } from "sonner";
6
6
  import { GlobalRoutesContext } from "@/context/global_routes_provider";
7
7
  import { PluginManager } from "@/plugin/PluginManager";
8
+ import { apiFetcher } from "@/utils";
8
9
 
9
10
  type inputResolve = (value: string | PromiseLike<string>) => void;
10
11
 
@@ -60,6 +61,9 @@ export const useDependencies = (): depHooksRes => {
60
61
  }
61
62
  pluginUIRef.current.setHtml(html);
62
63
  },
64
+ fetchPlugins: async () => {
65
+ return apiFetcher("plugin");
66
+ },
63
67
  showForm: async (input) => {
64
68
  setOpen(true);
65
69
  setInput(input);
@@ -1,11 +1,14 @@
1
1
  import { PluginInput } from "@/plugin/Plugin";
2
+ import { PluginConfig } from "@/plugin/Plugin";
2
3
 
3
4
  export interface Dependencies {
4
5
  toast: (content: string) => void;
5
6
  loading: (show: boolean) => void;
6
7
  showForm: (input: PluginInput) => Promise<string>;
7
8
  showUI: (html: string) => void;
9
+
8
10
  addRoute: (name: string, to: string) => void;
9
11
  removeRoute: (name: string) => void;
10
12
  callPlugin: (id: number, method: string) => Promise<any>;
13
+ fetchPlugins: () => Promise<PluginConfig[]>;
11
14
  }
@@ -70,10 +70,12 @@ export class PluginManager {
70
70
 
71
71
  PluginManager.instance = new PluginManager(dependencies);
72
72
  dependencies.loading(true);
73
- await PluginManager.instance.fetchPluginConfig();
73
+ const remotePlugins = await dependencies.fetchPlugins();
74
+ remotePlugins.forEach((p: PluginConfig) => PluginManager.instance.pluginConfigMap.set(p.id, p));
75
+
74
76
  await PluginManager.instance.restoreInstalledPlugins();
75
77
  dependencies.loading(false);
76
- // dependencies.toast("Plugin manager initialized");
78
+ // dependencies.toast("Plugins initialized");
77
79
  PluginManager.dispatchEvent<null>(PluginEvent.INIT, null);
78
80
 
79
81
  // @ts-ignore
@@ -165,32 +167,4 @@ export class PluginManager {
165
167
  private pluginConfigMap: Map<number, PluginConfig> = new Map();
166
168
 
167
169
  private plugins: Map<number, Plugin> = new Map();
168
-
169
- async fetchPluginConfig(): Promise<Map<number, PluginConfig>> {
170
- if (this.pluginConfigMap.size > 0) {
171
- return this.pluginConfigMap;
172
- }
173
-
174
- this.pluginConfigMap.set(1, {
175
- name: "now",
176
- id: 1,
177
- version: "1.0.0",
178
- description: "A now page plugin",
179
- url: "https://zjh-im-res.oss-cn-shenzhen.aliyuncs.com/plugins/now.wasm",
180
- status: 0,
181
- route: "近况",
182
- });
183
-
184
- // this.pluginConfigMap.set(2, {
185
- // name: "core",
186
- // id: 2,
187
- // version: "1.0.0",
188
- // description: "core",
189
- // url: "https://zjh-im-res.oss-cn-shenzhen.aliyuncs.com/plugins/reactable.core.wasm",
190
- // status: 0,
191
- // builtIn: true,
192
- // })
193
-
194
- return this.pluginConfigMap;
195
- }
196
170
  }