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) {
|
||||
switch (data.cmd) {
|
||||
case "reloadPlugin":
|
||||
reloadPlugin(this);
|
||||
reloadPlugin(this, data.data);
|
||||
break;
|
||||
case "syncMergeResult":
|
||||
reloadSync(this, data.data);
|
||||
|
|
|
@ -8,7 +8,7 @@ export const onMessage = (app: App, data: IWebSocketData) => {
|
|||
if (data) {
|
||||
switch (data.cmd) {
|
||||
case "reloadPlugin":
|
||||
reloadPlugin(app);
|
||||
reloadPlugin(app, data.data);
|
||||
break;
|
||||
case "syncMergeResult":
|
||||
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"));
|
||||
};
|
||||
|
||||
export const loadPlugins = async (app: App) => {
|
||||
export const loadPlugins = async (app: App, names?: string[]) => {
|
||||
const response = await fetchSyncPost("/api/petal/loadPetals", {frontend: getFrontend()});
|
||||
let css = "";
|
||||
// 为加快启动速度,不进行 await
|
||||
response.data.forEach((item: IPluginData) => {
|
||||
loadPluginJS(app, item);
|
||||
if (!names || (names && !names.includes(item.name))) {
|
||||
loadPluginJS(app, item);
|
||||
}
|
||||
css += item.css || "" + "\n";
|
||||
});
|
||||
const pluginsStyle = document.getElementById("pluginsStyle");
|
||||
|
@ -197,13 +199,15 @@ export const afterLoadPlugin = (plugin: Plugin) => {
|
|||
/// #endif
|
||||
};
|
||||
|
||||
export const reloadPlugin = (app: App) => {
|
||||
app.plugins.forEach((item) => {
|
||||
uninstall(this, item.name);
|
||||
export const reloadPlugin = async (app: App, data: { upsertPlugins: string[], removePlugins: string[] }) => {
|
||||
data.removePlugins.concat(data.upsertPlugins).forEach((item) => {
|
||||
uninstall(this, item);
|
||||
});
|
||||
loadPlugins(this).then(() => {
|
||||
loadPlugins(this, data.upsertPlugins).then(() => {
|
||||
app.plugins.forEach(item => {
|
||||
afterLoadPlugin(item);
|
||||
if (data.upsertPlugins.includes(item.name)) {
|
||||
afterLoadPlugin(item);
|
||||
}
|
||||
});
|
||||
});
|
||||
/// #if !MOBILE
|
||||
|
|
|
@ -52,7 +52,7 @@ class App {
|
|||
if (data) {
|
||||
switch (data.cmd) {
|
||||
case "reloadPlugin":
|
||||
reloadPlugin(this);
|
||||
reloadPlugin(this, data.data);
|
||||
break;
|
||||
case "syncMergeResult":
|
||||
reloadSync(this, data.data);
|
||||
|
|
Loading…
Add table
Reference in a new issue