Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: https://github.com/siyuan-note/siyuan/issues/16485

Vanessa7154879ddcb9
diff --git a/app/src/config/bazaar.ts b/app/src/config/bazaar.ts
index dc7daa4c46..7242aab2ae 100644
--- a/app/src/config/bazaar.ts
+++ b/app/src/config/bazaar.ts
@@ -846,7 +846,7 @@ export const bazaar = {
bazaar.element.querySelectorAll("#configBazaarDownloaded .b3-card").forEach(item => {
item.classList.remove("b3-card--disabled");
});
- loadPlugins(app).then(() => {
+ loadPlugins(app, null, false).then(() => {
app.plugins.forEach(item => {
afterLoadPlugin(item);
});
diff --git a/app/src/plugin/index.ts b/app/src/plugin/index.ts
index ae21f87223..5511c75ca3 100644
--- a/app/src/plugin/index.ts
+++ b/app/src/plugin/index.ts
@@ -119,7 +119,7 @@ export class Plugin {
// 存储数据变更
// 兼容 3.4.1 以前同步数据使用重载插件的问题
uninstall(this.app, this.name, false);
- loadPlugins(this.app, [this.name]).then(() => {
+ loadPlugins(this.app, [this.name], false).then(() => {
afterLoadPlugin(this);
});
}
diff --git a/app/src/plugin/loader.ts b/app/src/plugin/loader.ts
index 5a4a611ef3..fcf296ec2d 100644
--- a/app/src/plugin/loader.ts
+++ b/app/src/plugin/loader.ts
@@ -27,15 +27,21 @@ const runCode = (code: string, sourceURL: string) => {
return window.eval("(function anonymous(require, module, exports){".concat(code, "\n})\n//# sourceURL=").concat(sourceURL, "\n"));
};
-export const loadPlugins = async (app: App, names?: string[]) => {
+export const loadPlugins = async (app: App, names?: string[], init = true) => {
const response = await fetchSyncPost("/api/petal/loadPetals", {frontend: getFrontend()});
const pluginsStyle = getPluginsStyle();
- response.data.forEach((item: IPluginData) => {
+ for (let i = 0; i < response.data.length; i++) {
+ const item = response.data[i] as IPluginData;
if (!names || (names && names.includes(item.name))) {
- loadPluginJS(app, item);
+ if (init) {
+ // 初始化时为加快启动速度,已特殊处理,不进行 await
+ loadPluginJS(app, item);
+ } else {
+ await loadPluginJS(app, item);
+ }
insertPluginCSS(item, pluginsStyle);
}
- });
+ }
};
const loadPluginJS = async (app: App, item: IPluginData) => {
@@ -228,7 +234,7 @@ export const reloadPlugin = async (app: App, data: {
upsertCodePlugins.forEach((item) => {
uninstall(app, item, false);
});
- loadPlugins(app, upsertCodePlugins).then(() => {
+ loadPlugins(app, upsertCodePlugins, false).then(() => {
app.plugins.forEach(item => {
if (upsertCodePlugins.includes(item.name)) {
afterLoadPlugin(item);