mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-20 08:30:12 +01:00
This commit is contained in:
parent
09096229ce
commit
c0fb594133
4 changed files with 14 additions and 10 deletions
|
|
@ -61,7 +61,7 @@ export class App {
|
||||||
if (data) {
|
if (data) {
|
||||||
switch (data.cmd) {
|
switch (data.cmd) {
|
||||||
case "reloadPlugin":
|
case "reloadPlugin":
|
||||||
reloadPlugin(this);
|
reloadPlugin(this, data.data);
|
||||||
break;
|
break;
|
||||||
case "syncMergeResult":
|
case "syncMergeResult":
|
||||||
reloadSync(this, data.data);
|
reloadSync(this, data.data);
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ export const onMessage = (app: App, data: IWebSocketData) => {
|
||||||
if (data) {
|
if (data) {
|
||||||
switch (data.cmd) {
|
switch (data.cmd) {
|
||||||
case "reloadPlugin":
|
case "reloadPlugin":
|
||||||
reloadPlugin(app);
|
reloadPlugin(app, data.data);
|
||||||
break;
|
break;
|
||||||
case "syncMergeResult":
|
case "syncMergeResult":
|
||||||
reloadSync(app, data.data);
|
reloadSync(app, data.data);
|
||||||
|
|
|
||||||
|
|
@ -25,12 +25,14 @@ 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 = async (app: App) => {
|
export const loadPlugins = async (app: App, names?: string[]) => {
|
||||||
const response = await fetchSyncPost("/api/petal/loadPetals", {frontend: getFrontend()});
|
const response = await fetchSyncPost("/api/petal/loadPetals", {frontend: getFrontend()});
|
||||||
let css = "";
|
let css = "";
|
||||||
// 为加快启动速度,不进行 await
|
// 为加快启动速度,不进行 await
|
||||||
response.data.forEach((item: IPluginData) => {
|
response.data.forEach((item: IPluginData) => {
|
||||||
|
if (!names || (names && !names.includes(item.name))) {
|
||||||
loadPluginJS(app, item);
|
loadPluginJS(app, item);
|
||||||
|
}
|
||||||
css += item.css || "" + "\n";
|
css += item.css || "" + "\n";
|
||||||
});
|
});
|
||||||
const pluginsStyle = document.getElementById("pluginsStyle");
|
const pluginsStyle = document.getElementById("pluginsStyle");
|
||||||
|
|
@ -197,13 +199,15 @@ export const afterLoadPlugin = (plugin: Plugin) => {
|
||||||
/// #endif
|
/// #endif
|
||||||
};
|
};
|
||||||
|
|
||||||
export const reloadPlugin = (app: App) => {
|
export const reloadPlugin = async (app: App, data: { upsertPlugins: string[], removePlugins: string[] }) => {
|
||||||
app.plugins.forEach((item) => {
|
data.removePlugins.concat(data.upsertPlugins).forEach((item) => {
|
||||||
uninstall(this, item.name);
|
uninstall(this, item);
|
||||||
});
|
});
|
||||||
loadPlugins(this).then(() => {
|
loadPlugins(this, data.upsertPlugins).then(() => {
|
||||||
app.plugins.forEach(item => {
|
app.plugins.forEach(item => {
|
||||||
|
if (data.upsertPlugins.includes(item.name)) {
|
||||||
afterLoadPlugin(item);
|
afterLoadPlugin(item);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
/// #if !MOBILE
|
/// #if !MOBILE
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ class App {
|
||||||
if (data) {
|
if (data) {
|
||||||
switch (data.cmd) {
|
switch (data.cmd) {
|
||||||
case "reloadPlugin":
|
case "reloadPlugin":
|
||||||
reloadPlugin(this);
|
reloadPlugin(this, data.data);
|
||||||
break;
|
break;
|
||||||
case "syncMergeResult":
|
case "syncMergeResult":
|
||||||
reloadSync(this, data.data);
|
reloadSync(this, data.data);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue