From a0c9dbad4ff0683e9fd7d43af7892bc1001a31aa Mon Sep 17 00:00:00 2001 From: Louis Date: Tue, 3 Oct 2023 16:38:58 +0700 Subject: [PATCH] fixes #234: relaunch app on plugin update --- electron/main.ts | 4 ++++ electron/preload.ts | 2 ++ web/app/_components/Preferences.tsx | 10 ++++------ 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/electron/main.ts b/electron/main.ts index 246661db7..058afd835 100644 --- a/electron/main.ts +++ b/electron/main.ts @@ -144,6 +144,10 @@ function handleIPCs() { ipcMain.handle("openExternalUrl", async (_event, url) => { shell.openExternal(url); }); + ipcMain.handle("relaunch", async (_event, url) => { + dispose(requiredModules); + app.relaunch(); + }); /** * Used to delete a file from the user data folder diff --git a/electron/preload.ts b/electron/preload.ts index 59dc53992..c3dd73646 100644 --- a/electron/preload.ts +++ b/electron/preload.ts @@ -17,6 +17,8 @@ contextBridge.exposeInMainWorld("electronAPI", { openExternalUrl: (url: string) => ipcRenderer.invoke("openExternalUrl", url), + relaunch: () => ipcRenderer.invoke("relaunch"), + deleteFile: (filePath: string) => ipcRenderer.invoke("deleteFile", filePath), downloadFile: (url: string, path: string) => diff --git a/web/app/_components/Preferences.tsx b/web/app/_components/Preferences.tsx index e1634d3e6..4f2c62878 100644 --- a/web/app/_components/Preferences.tsx +++ b/web/app/_components/Preferences.tsx @@ -81,9 +81,7 @@ export const Preferences = () => { // Send the filename of the to be installed plugin // to the main process for installation const installed = await plugins.install([pluginFile]); - if (typeof window !== "undefined") { - window.location.reload(); - } + if (installed) window.electronAPI.relaunch(); }; // Uninstall a plugin on clicking uninstall @@ -99,6 +97,7 @@ export const Preferences = () => { ? "Plugin successfully uninstalled" : "Plugin could not be uninstalled" ); + if (res) window.electronAPI.relaunch(); }; // Update all plugins on clicking update plugins @@ -106,6 +105,7 @@ export const Preferences = () => { if (typeof window !== "undefined") { // @ts-ignore await window.pluggableElectronIpc.update([plugin], true); + window.electronAPI.relaunch(); } // plugins.update(active.map((plg) => plg.name)); }; @@ -176,9 +176,7 @@ export const Preferences = () => { type="submit" className={classNames( "rounded-md px-3.5 py-2.5 text-sm font-semibold text-white shadow-sm focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600", - fileName - ? "bg-indigo-600 hover:bg-indigo-500" - : "bg-gray-500" + fileName ? "bg-indigo-600 hover:bg-indigo-500" : "bg-gray-500" )} > Install Plugin