This commit is contained in:
parent
da0afd39a8
commit
a556716dcc
7 changed files with 35 additions and 22 deletions
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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") ? `<svg class="b3-menu__icon"><use xlink:href="#${options.icon}"></use></svg>` : options.icon) +
|
||||
`<span class="b3-menu__label">${options.title}</span>`;
|
||||
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") ? `<svg><use xlink:href="#${options.icon}"></use></svg>` : 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;
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
|
@ -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 => {
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Add table
Reference in a new issue