mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-22 09:30:14 +01:00
This commit is contained in:
parent
a14e1b5917
commit
169586e9aa
1 changed files with 5 additions and 4 deletions
|
|
@ -22,6 +22,7 @@ const runCode = (code: string, sourceURL: string) => {
|
||||||
export const loadPlugins = async (app: App) => {
|
export const loadPlugins = async (app: App) => {
|
||||||
const response = await fetchSyncPost("/api/petal/loadPetals");
|
const response = await fetchSyncPost("/api/petal/loadPetals");
|
||||||
let css = "";
|
let css = "";
|
||||||
|
// 为加快启动速度,不进行 await
|
||||||
response.data.forEach((item: IPluginData) => {
|
response.data.forEach((item: IPluginData) => {
|
||||||
loadPluginJS(app, item);
|
loadPluginJS(app, item);
|
||||||
css += item.css || "" + "\n";
|
css += item.css || "" + "\n";
|
||||||
|
|
@ -31,7 +32,7 @@ export const loadPlugins = async (app: App) => {
|
||||||
document.head.append(styleElement);
|
document.head.append(styleElement);
|
||||||
};
|
};
|
||||||
|
|
||||||
const loadPluginJS = (app: App, item: IPluginData) => {
|
const loadPluginJS = async (app: App, item: IPluginData) => {
|
||||||
const exportsObj: { [key: string]: any } = {};
|
const exportsObj: { [key: string]: any } = {};
|
||||||
const moduleObj = {exports: exportsObj};
|
const moduleObj = {exports: exportsObj};
|
||||||
try {
|
try {
|
||||||
|
|
@ -56,15 +57,15 @@ const loadPluginJS = (app: App, item: IPluginData) => {
|
||||||
});
|
});
|
||||||
app.plugins.push(plugin);
|
app.plugins.push(plugin);
|
||||||
try {
|
try {
|
||||||
plugin.onload();
|
await plugin.onload();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(`plugin ${item.name} onload error:`, e);
|
console.error(`plugin ${item.name} onload error:`, e);
|
||||||
}
|
}
|
||||||
return plugin;
|
return plugin;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const loadPlugin = (app: App, item: IPluginData) => {
|
export const loadPlugin = async (app: App, item: IPluginData) => {
|
||||||
const plugin = loadPluginJS(app, item);
|
const plugin = await loadPluginJS(app, item);
|
||||||
const styleElement = document.createElement("style");
|
const styleElement = document.createElement("style");
|
||||||
styleElement.textContent = item.css;
|
styleElement.textContent = item.css;
|
||||||
document.head.append(styleElement);
|
document.head.append(styleElement);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue