Skip to content

Commit

Permalink
Merge branch 'fix-unpinned-race-condition'
Browse files Browse the repository at this point in the history
  • Loading branch information
raksooo committed Nov 23, 2022
2 parents 303176e + 47f6e31 commit 865f896
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
4 changes: 4 additions & 0 deletions gui/src/main/ipc-event-channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@ export let IpcMainEventChannel = createIpcMain(ipcSchema, ipcMain, undefined);
export function changeIpcWebContents(webContents: WebContents | undefined) {
IpcMainEventChannel = createIpcMain(ipcSchema, ipcMain, webContents);
}

export function unsetIpcWebContents() {
changeIpcWebContents(undefined);
}
19 changes: 13 additions & 6 deletions gui/src/main/user-interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ import log from '../shared/logging';
import { Scheduler } from '../shared/scheduler';
import { SHOULD_DISABLE_DEVTOOLS_OPEN, SHOULD_FORWARD_RENDERER_LOG } from './command-line-options';
import { DaemonRpc } from './daemon-rpc';
import { changeIpcWebContents, IpcMainEventChannel } from './ipc-event-channel';
import {
changeIpcWebContents,
IpcMainEventChannel,
unsetIpcWebContents,
} from './ipc-event-channel';
import { WebContentsConsoleInput } from './logging';
import { isMacOs11OrNewer } from './platform-version';
import TrayIconController, { TrayIconType } from './tray-icon-controller';
Expand Down Expand Up @@ -51,11 +55,6 @@ export default class UserInterface implements WindowControllerDelegate {
) {
const window = this.createWindow();

changeIpcWebContents(window.webContents);
window.webContents.on('destroyed', () => {
changeIpcWebContents(undefined);
});

this.windowController = this.createWindowController(window);
this.tray = this.createTray();
}
Expand Down Expand Up @@ -88,6 +87,10 @@ export default class UserInterface implements WindowControllerDelegate {

const window = this.windowController.window;

// Make sure the IPC wrapper always has the latest webcontents if any
window.webContents.on('destroyed', unsetIpcWebContents);
changeIpcWebContents(window.webContents);

this.registerWindowListener();
this.addContextMenu();

Expand Down Expand Up @@ -149,6 +152,10 @@ export default class UserInterface implements WindowControllerDelegate {
public async recreateWindow(isLoggedIn: boolean, tunnelState: TunnelState): Promise<void> {
if (this.tray) {
this.tray.removeAllListeners();
// Prevent the IPC webcontents reference to be reset when replacing window. Resetting wouldn't
// work since the old webContents is destroyed after the IPC wrapper has been updated with the
// new one.
this.windowController.webContents?.removeListener('destroyed', unsetIpcWebContents);

const window = this.createWindow();
changeIpcWebContents(window.webContents);
Expand Down

0 comments on commit 865f896

Please sign in to comment.