mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-22 09:30:14 +01:00
This commit is contained in:
parent
da0afd39a8
commit
a556716dcc
7 changed files with 35 additions and 22 deletions
|
|
@ -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;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue