mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-21 09:00:12 +01:00
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");
|
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");
|
addScript(`${Constants.PROTYLE_CDN}/js/protyle-html.js?v=${Constants.SIYUAN_VERSION}`, "protyleWcHtmlScript");
|
||||||
addBaseURL();
|
addBaseURL();
|
||||||
|
loadPlugins(this);
|
||||||
window.siyuan = {
|
window.siyuan = {
|
||||||
transactions: [],
|
transactions: [],
|
||||||
reqIds: {},
|
reqIds: {},
|
||||||
|
|
@ -171,7 +172,6 @@ export class App {
|
||||||
bootSync();
|
bootSync();
|
||||||
fetchPost("/api/setting/getCloudUser", {}, userResponse => {
|
fetchPost("/api/setting/getCloudUser", {}, userResponse => {
|
||||||
window.siyuan.user = userResponse.data;
|
window.siyuan.user = userResponse.data;
|
||||||
loadPlugins(this);
|
|
||||||
onGetConfig(response.data.start, this);
|
onGetConfig(response.data.start, this);
|
||||||
account.onSetaccount();
|
account.onSetaccount();
|
||||||
resizeDrag();
|
resizeDrag();
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ import {saveScroll} from "../protyle/scroll/saveScroll";
|
||||||
import {pdfResize} from "../asset/renderAssets";
|
import {pdfResize} from "../asset/renderAssets";
|
||||||
import {Backlink} from "./dock/Backlink";
|
import {Backlink} from "./dock/Backlink";
|
||||||
import {openFileById} from "../editor/util";
|
import {openFileById} from "../editor/util";
|
||||||
import {isWindow} from "../util/functions";
|
import {isMobile, isWindow} from "../util/functions";
|
||||||
/// #if !BROWSER
|
/// #if !BROWSER
|
||||||
import {setTabPosition} from "../window/setHeader";
|
import {setTabPosition} from "../window/setHeader";
|
||||||
/// #endif
|
/// #endif
|
||||||
|
|
@ -472,8 +472,21 @@ export const JSONToLayout = (app: App, isStart: boolean) => {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
app.plugins.forEach(item => {
|
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);
|
}, Constants.TIMEOUT_LOAD);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,7 @@ class App {
|
||||||
addScriptSync(`${Constants.PROTYLE_CDN}/js/lute/lute.min.js?v=${Constants.SIYUAN_VERSION}`, "protyleLuteScript");
|
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");
|
addScript(`${Constants.PROTYLE_CDN}/js/protyle-html.js?v=${Constants.SIYUAN_VERSION}`, "protyleWcHtmlScript");
|
||||||
addBaseURL();
|
addBaseURL();
|
||||||
|
loadPlugins(this);
|
||||||
window.siyuan = {
|
window.siyuan = {
|
||||||
notebooks: [],
|
notebooks: [],
|
||||||
transactions: [],
|
transactions: [],
|
||||||
|
|
@ -79,7 +80,6 @@ class App {
|
||||||
setNoteBook(() => {
|
setNoteBook(() => {
|
||||||
initFramework(this);
|
initFramework(this);
|
||||||
initRightMenu(this);
|
initRightMenu(this);
|
||||||
loadPlugins(this);
|
|
||||||
openChangelog();
|
openChangelog();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -63,19 +63,16 @@ export class Plugin {
|
||||||
const iconElement = document.createElement("div");
|
const iconElement = document.createElement("div");
|
||||||
if (isMobile()) {
|
if (isMobile()) {
|
||||||
iconElement.className = "b3-menu__item";
|
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) +
|
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>`;
|
`<span class="b3-menu__label">${options.title}</span>`;
|
||||||
iconElement.addEventListener("click", options.callback);
|
iconElement.addEventListener("click", options.callback);
|
||||||
document.querySelector("#menuAbout").after(iconElement);
|
|
||||||
} else if (!isWindow()) {
|
} else if (!isWindow()) {
|
||||||
iconElement.className = "toolbar__item b3-tooltips b3-tooltips__sw";
|
iconElement.className = "toolbar__item b3-tooltips b3-tooltips__sw";
|
||||||
iconElement.setAttribute("aria-label", options.title);
|
iconElement.setAttribute("aria-label", options.title);
|
||||||
iconElement.setAttribute("data-menu", "true");
|
iconElement.setAttribute("data-menu", "true");
|
||||||
iconElement.innerHTML = options.icon.startsWith("icon") ? `<svg><use xlink:href="#${options.icon}"></use></svg>` : options.icon;
|
iconElement.innerHTML = options.icon.startsWith("icon") ? `<svg><use xlink:href="#${options.icon}"></use></svg>` : options.icon;
|
||||||
iconElement.addEventListener("click", options.callback);
|
iconElement.addEventListener("click", options.callback);
|
||||||
document.querySelector("#" + (options.position === "right" ? "barSearch" : "drag")).before(iconElement);
|
iconElement.setAttribute("data-position", options.position );
|
||||||
}
|
}
|
||||||
this.topBarIcons.push(iconElement);
|
this.topBarIcons.push(iconElement);
|
||||||
return iconElement;
|
return iconElement;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import {fetchPost} from "../util/fetch";
|
import {fetchPost, fetchSyncPost} from "../util/fetch";
|
||||||
import {App} from "../index";
|
import {App} from "../index";
|
||||||
import {Plugin} from "./index";
|
import {Plugin} from "./index";
|
||||||
/// #if !MOBILE
|
/// #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"));
|
return window.eval("(function anonymous(require, module, exports){".concat(code, "\n})\n//# sourceURL=").concat(sourceURL, "\n"));
|
||||||
};
|
};
|
||||||
|
|
||||||
export const loadPlugins = (app: App) => {
|
export const loadPlugins = async (app: App) => {
|
||||||
fetchPost("/api/petal/loadPetals", {}, response => {
|
const response = await fetchSyncPost("/api/petal/loadPetals");
|
||||||
let css = "";
|
let css = "";
|
||||||
response.data.forEach((item: IPluginData) => {
|
response.data.forEach((item: IPluginData) => {
|
||||||
loadPluginJS(app, item);
|
loadPluginJS(app, item);
|
||||||
css += item.css || "" + "\n";
|
css += item.css || "" + "\n";
|
||||||
});
|
|
||||||
const styleElement = document.createElement("style");
|
|
||||||
styleElement.textContent = css;
|
|
||||||
document.head.append(styleElement);
|
|
||||||
});
|
});
|
||||||
|
const styleElement = document.createElement("style");
|
||||||
|
styleElement.textContent = css;
|
||||||
|
document.head.append(styleElement);
|
||||||
};
|
};
|
||||||
|
|
||||||
const loadPluginJS = (app: App, item: IPluginData) => {
|
const loadPluginJS = (app: App, item: IPluginData) => {
|
||||||
|
|
@ -58,7 +57,7 @@ const loadPluginJS = (app: App, item: IPluginData) => {
|
||||||
try {
|
try {
|
||||||
plugin.onload();
|
plugin.onload();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(`plugin ${item.name} load error:`, e);
|
console.error(`plugin ${item.name} onload error:`, e);
|
||||||
}
|
}
|
||||||
return plugin;
|
return plugin;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,11 @@ export const uninstall = (app: App, name: string) => {
|
||||||
app.plugins.find((plugin: Plugin, index) => {
|
app.plugins.find((plugin: Plugin, index) => {
|
||||||
if (plugin.name === name) {
|
if (plugin.name === name) {
|
||||||
// rm command
|
// rm command
|
||||||
plugin.onunload();
|
try {
|
||||||
|
plugin.onunload();
|
||||||
|
} catch (e) {
|
||||||
|
console.error(`plugin ${plugin.name} onunload error:`, e);
|
||||||
|
}
|
||||||
// rm tab
|
// rm tab
|
||||||
const modelsKeys = Object.keys(plugin.models);
|
const modelsKeys = Object.keys(plugin.models);
|
||||||
getAllModels().custom.forEach(custom => {
|
getAllModels().custom.forEach(custom => {
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@ class App {
|
||||||
addScriptSync(`${Constants.PROTYLE_CDN}/js/lute/lute.min.js?v=${Constants.SIYUAN_VERSION}`, "protyleLuteScript");
|
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");
|
addScript(`${Constants.PROTYLE_CDN}/js/protyle-html.js?v=${Constants.SIYUAN_VERSION}`, "protyleWcHtmlScript");
|
||||||
addBaseURL();
|
addBaseURL();
|
||||||
|
loadPlugins(this);
|
||||||
window.siyuan = {
|
window.siyuan = {
|
||||||
transactions: [],
|
transactions: [],
|
||||||
reqIds: {},
|
reqIds: {},
|
||||||
|
|
@ -135,7 +136,6 @@ class App {
|
||||||
window.siyuan.menus = new Menus(this);
|
window.siyuan.menus = new Menus(this);
|
||||||
fetchPost("/api/setting/getCloudUser", {}, userResponse => {
|
fetchPost("/api/setting/getCloudUser", {}, userResponse => {
|
||||||
window.siyuan.user = userResponse.data;
|
window.siyuan.user = userResponse.data;
|
||||||
loadPlugins(this);
|
|
||||||
init(this);
|
init(this);
|
||||||
setTitle(window.siyuan.languages.siyuanNote);
|
setTitle(window.siyuan.languages.siyuanNote);
|
||||||
initMessage();
|
initMessage();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue