diff --git a/app/src/index.ts b/app/src/index.ts
index 7f39bf6b7..79c0ffe15 100644
--- a/app/src/index.ts
+++ b/app/src/index.ts
@@ -41,6 +41,7 @@ export class App {
addScriptSync(`${Constants.PROTYLE_CDN}/js/lute/lute.min.js?v=${Constants.SIYUAN_VERSION}`, "protyleLuteScript");
addScript(`${Constants.PROTYLE_CDN}/js/protyle-html.js?v=${Constants.SIYUAN_VERSION}`, "protyleWcHtmlScript");
addBaseURL();
+ loadPlugins(this);
window.siyuan = {
transactions: [],
reqIds: {},
@@ -171,7 +172,6 @@ export class App {
bootSync();
fetchPost("/api/setting/getCloudUser", {}, userResponse => {
window.siyuan.user = userResponse.data;
- loadPlugins(this);
onGetConfig(response.data.start, this);
account.onSetaccount();
resizeDrag();
diff --git a/app/src/layout/util.ts b/app/src/layout/util.ts
index e7482bf30..6635c681e 100644
--- a/app/src/layout/util.ts
+++ b/app/src/layout/util.ts
@@ -26,7 +26,7 @@ import {saveScroll} from "../protyle/scroll/saveScroll";
import {pdfResize} from "../asset/renderAssets";
import {Backlink} from "./dock/Backlink";
import {openFileById} from "../editor/util";
-import {isWindow} from "../util/functions";
+import {isMobile, isWindow} from "../util/functions";
/// #if !BROWSER
import {setTabPosition} from "../window/setHeader";
/// #endif
@@ -472,8 +472,21 @@ export const JSONToLayout = (app: App, isStart: boolean) => {
});
}
app.plugins.forEach(item => {
- item.onLayoutReady();
+ try {
+ item.onLayoutReady();
+ } catch (e) {
+ console.error(`plugin ${item.name} onLayoutReady error:`, e);
+ }
+
+ item.topBarIcons.forEach(element=> {
+ if (isMobile()) {
+ document.querySelector("#menuAbout").after(element);
+ } else if (!isWindow()) {
+ document.querySelector("#" + (element.getAttribute("data-position") === "right" ? "barSearch" : "drag")).before(element);
+ }
+ });
});
+ // 等待 tab、dock 完成后再 init Tab model,dock
}, Constants.TIMEOUT_LOAD);
};
diff --git a/app/src/mobile/index.ts b/app/src/mobile/index.ts
index 0475cbb56..db4e5b4f2 100644
--- a/app/src/mobile/index.ts
+++ b/app/src/mobile/index.ts
@@ -34,6 +34,7 @@ class App {
addScriptSync(`${Constants.PROTYLE_CDN}/js/lute/lute.min.js?v=${Constants.SIYUAN_VERSION}`, "protyleLuteScript");
addScript(`${Constants.PROTYLE_CDN}/js/protyle-html.js?v=${Constants.SIYUAN_VERSION}`, "protyleWcHtmlScript");
addBaseURL();
+ loadPlugins(this);
window.siyuan = {
notebooks: [],
transactions: [],
@@ -79,7 +80,6 @@ class App {
setNoteBook(() => {
initFramework(this);
initRightMenu(this);
- loadPlugins(this);
openChangelog();
});
});
diff --git a/app/src/plugin/index.ts b/app/src/plugin/index.ts
index c3b0d7fb8..d2388c3b7 100644
--- a/app/src/plugin/index.ts
+++ b/app/src/plugin/index.ts
@@ -63,19 +63,16 @@ export class Plugin {
const iconElement = document.createElement("div");
if (isMobile()) {
iconElement.className = "b3-menu__item";
- iconElement.setAttribute("aria-label", options.title);
- iconElement.setAttribute("data-menu", "true");
iconElement.innerHTML = (options.icon.startsWith("icon") ? `` : options.icon) +
``;
iconElement.addEventListener("click", options.callback);
- document.querySelector("#menuAbout").after(iconElement);
} else if (!isWindow()) {
iconElement.className = "toolbar__item b3-tooltips b3-tooltips__sw";
iconElement.setAttribute("aria-label", options.title);
iconElement.setAttribute("data-menu", "true");
iconElement.innerHTML = options.icon.startsWith("icon") ? `` : options.icon;
iconElement.addEventListener("click", options.callback);
- document.querySelector("#" + (options.position === "right" ? "barSearch" : "drag")).before(iconElement);
+ iconElement.setAttribute("data-position", options.position );
}
this.topBarIcons.push(iconElement);
return iconElement;
diff --git a/app/src/plugin/loader.ts b/app/src/plugin/loader.ts
index 7abd0a499..fd314b03a 100644
--- a/app/src/plugin/loader.ts
+++ b/app/src/plugin/loader.ts
@@ -1,4 +1,4 @@
-import {fetchPost} from "../util/fetch";
+import {fetchPost, fetchSyncPost} from "../util/fetch";
import {App} from "../index";
import {Plugin} from "./index";
/// #if !MOBILE
@@ -18,17 +18,16 @@ 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 = (app: App) => {
- fetchPost("/api/petal/loadPetals", {}, response => {
- let css = "";
- response.data.forEach((item: IPluginData) => {
- loadPluginJS(app, item);
- css += item.css || "" + "\n";
- });
- const styleElement = document.createElement("style");
- styleElement.textContent = css;
- document.head.append(styleElement);
+export const loadPlugins = async (app: App) => {
+ const response = await fetchSyncPost("/api/petal/loadPetals");
+ let css = "";
+ response.data.forEach((item: IPluginData) => {
+ loadPluginJS(app, item);
+ css += item.css || "" + "\n";
});
+ const styleElement = document.createElement("style");
+ styleElement.textContent = css;
+ document.head.append(styleElement);
};
const loadPluginJS = (app: App, item: IPluginData) => {
@@ -58,7 +57,7 @@ const loadPluginJS = (app: App, item: IPluginData) => {
try {
plugin.onload();
} catch (e) {
- console.error(`plugin ${item.name} load error:`, e);
+ console.error(`plugin ${item.name} onload error:`, e);
}
return plugin;
};
diff --git a/app/src/plugin/uninstall.ts b/app/src/plugin/uninstall.ts
index 33777ff66..8b8240523 100644
--- a/app/src/plugin/uninstall.ts
+++ b/app/src/plugin/uninstall.ts
@@ -7,7 +7,11 @@ export const uninstall = (app: App, name: string) => {
app.plugins.find((plugin: Plugin, index) => {
if (plugin.name === name) {
// rm command
- plugin.onunload();
+ try {
+ plugin.onunload();
+ } catch (e) {
+ console.error(`plugin ${plugin.name} onunload error:`, e);
+ }
// rm tab
const modelsKeys = Object.keys(plugin.models);
getAllModels().custom.forEach(custom => {
diff --git a/app/src/window/index.ts b/app/src/window/index.ts
index 11118a4c0..b2123ece1 100644
--- a/app/src/window/index.ts
+++ b/app/src/window/index.ts
@@ -30,6 +30,7 @@ class App {
addScriptSync(`${Constants.PROTYLE_CDN}/js/lute/lute.min.js?v=${Constants.SIYUAN_VERSION}`, "protyleLuteScript");
addScript(`${Constants.PROTYLE_CDN}/js/protyle-html.js?v=${Constants.SIYUAN_VERSION}`, "protyleWcHtmlScript");
addBaseURL();
+ loadPlugins(this);
window.siyuan = {
transactions: [],
reqIds: {},
@@ -135,7 +136,6 @@ class App {
window.siyuan.menus = new Menus(this);
fetchPost("/api/setting/getCloudUser", {}, userResponse => {
window.siyuan.user = userResponse.data;
- loadPlugins(this);
init(this);
setTitle(window.siyuan.languages.siyuanNote);
initMessage();