Skip to content

Commit 36610dc

Browse files
committed
Expose an app restart API to the renderer
1 parent 66e6875 commit 36610dc

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/index.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,4 +638,14 @@ ipcMain.handle('open-context-menu', ipcHandler((options: ContextMenuDefinition)
638638
));
639639

640640
ipcMain.handle('get-desktop-version', ipcHandler(() => DESKTOP_VERSION));
641-
ipcMain.handle('get-server-auth-token', ipcHandler(() => AUTH_TOKEN));
641+
ipcMain.handle('get-server-auth-token', ipcHandler(() => AUTH_TOKEN));
642+
643+
let restarting = false;
644+
ipcMain.handle('restart-app', ipcHandler(() => {
645+
if (restarting) return;
646+
restarting = true;
647+
console.log('Restarting...');
648+
649+
app.relaunch();
650+
app.quit();
651+
}));

src/preload.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,8 @@ contextBridge.exposeInMainWorld('desktopApi', {
2828
selectApplication: () =>
2929
ipcRenderer.invoke('select-application'),
3030
openContextMenu: (options: ContextMenuDefinition) =>
31-
ipcRenderer.invoke('open-context-menu', options)
31+
ipcRenderer.invoke('open-context-menu', options),
32+
33+
restartApp: () =>
34+
ipcRenderer.invoke('restart-app')
3235
});

0 commit comments

Comments
 (0)