Skip to content

Commit

Permalink
fixes janhq#234: relaunch app on plugin update
Browse files Browse the repository at this point in the history
  • Loading branch information
louis-jan committed Oct 4, 2023
1 parent 52abf55 commit a0c9dba
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
4 changes: 4 additions & 0 deletions electron/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions electron/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down
10 changes: 4 additions & 6 deletions web/app/_components/Preferences.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -99,13 +97,15 @@ export const Preferences = () => {
? "Plugin successfully uninstalled"
: "Plugin could not be uninstalled"
);
if (res) window.electronAPI.relaunch();
};

// Update all plugins on clicking update plugins
const update = async (plugin: string) => {
if (typeof window !== "undefined") {
// @ts-ignore
await window.pluggableElectronIpc.update([plugin], true);
window.electronAPI.relaunch();
}
// plugins.update(active.map((plg) => plg.name));
};
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a0c9dba

Please sign in to comment.