diff --git a/app/src/index.ts b/app/src/index.ts index b285206f3..e8e652693 100644 --- a/app/src/index.ts +++ b/app/src/index.ts @@ -25,8 +25,7 @@ import {getAllTabs} from "./layout/getAll"; import {getLocalStorage} from "./protyle/util/compatibility"; import {getSearch} from "./util/functions"; import {hideAllElements} from "./protyle/ui/hideElements"; -import {afterLoadPlugin, loadPlugins} from "./plugin/loader"; -import {uninstall} from "./plugin/uninstall"; +import {loadPlugins, reloadPlugin} from "./plugin/loader"; import "./assets/scss/base.scss"; export class App { @@ -61,14 +60,7 @@ export class App { if (data) { switch (data.cmd) { case "reloadPlugin": - this.plugins.forEach((plugin) => { - uninstall(this, plugin.name); - }); - loadPlugins(this).then(() => { - this.plugins.forEach(item => { - afterLoadPlugin(item); - }); - }); + reloadPlugin(this); break; case "syncMergeResult": reloadSync(this, data.data); diff --git a/app/src/mobile/util/onMessage.ts b/app/src/mobile/util/onMessage.ts index 7ad4b5b3d..f1b073743 100644 --- a/app/src/mobile/util/onMessage.ts +++ b/app/src/mobile/util/onMessage.ts @@ -2,10 +2,14 @@ import {openMobileFileById} from "../editor"; import {processSync, progressLoading, progressStatus, reloadSync, transactionError} from "../../dialog/processSystem"; import {Constants} from "../../constants"; import {App} from "../../index"; +import {reloadPlugin} from "../../plugin/loader"; export const onMessage = (app: App, data: IWebSocketData) => { if (data) { switch (data.cmd) { + case "reloadPlugin": + reloadPlugin(app); + break; case "syncMergeResult": reloadSync(app, data.data); break; diff --git a/app/src/plugin/loader.ts b/app/src/plugin/loader.ts index abeee81fa..68bf1b0f6 100644 --- a/app/src/plugin/loader.ts +++ b/app/src/plugin/loader.ts @@ -7,6 +7,7 @@ import {resizeTopBar, saveLayout} from "../layout/util"; import {API} from "./API"; import {getFrontend, isMobile, isWindow} from "../util/functions"; import {Constants} from "../constants"; +import {uninstall} from "./uninstall"; const requireFunc = (key: string) => { const modules = { @@ -231,3 +232,14 @@ export const afterLoadPlugin = (plugin: Plugin) => { saveLayout(); /// #endif }; + +export const reloadPlugin = (app: App) => { + app.plugins.forEach((item) => { + uninstall(this, item.name); + }); + loadPlugins(this).then(() => { + app.plugins.forEach(item => { + afterLoadPlugin(item); + }); + }); +}; diff --git a/app/src/window/index.ts b/app/src/window/index.ts index 1d6df797e..695cf4e6b 100644 --- a/app/src/window/index.ts +++ b/app/src/window/index.ts @@ -19,7 +19,7 @@ import {initMessage} from "../dialog/message"; import {getAllTabs} from "../layout/getAll"; import {getLocalStorage} from "../protyle/util/compatibility"; import {init} from "../window/init"; -import {loadPlugins} from "../plugin/loader"; +import {loadPlugins, reloadPlugin} from "../plugin/loader"; import {hideAllElements} from "../protyle/ui/hideElements"; class App { @@ -51,6 +51,9 @@ class App { }); if (data) { switch (data.cmd) { + case "reloadPlugin": + reloadPlugin(this); + break; case "syncMergeResult": reloadSync(this, data.data); break;