summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorOskar Nyberg <oskar@mullvad.net>2022-11-23 17:54:38 +0100
committerOskar Nyberg <oskar@mullvad.net>2022-11-23 17:54:38 +0100
commit865f896eb68db1053284560945bd917ee7832722 (patch)
treedd13a8dc0f6844584d6194f738218553e72570ed
parent303176ee7ed1663a315153dcf42d5ddbc19b8e16 (diff)
parent47f6e3148f6e0e84d4e08603e8f5dab1a7d39612 (diff)
downloadmullvadvpn-865f896eb68db1053284560945bd917ee7832722.tar.xz
mullvadvpn-865f896eb68db1053284560945bd917ee7832722.zip
Merge branch 'fix-unpinned-race-condition'
-rw-r--r--gui/src/main/ipc-event-channel.ts4
-rw-r--r--gui/src/main/user-interface.ts19
2 files changed, 17 insertions, 6 deletions
diff --git a/gui/src/main/ipc-event-channel.ts b/gui/src/main/ipc-event-channel.ts
index 80fed8a034..a42b2bc1f1 100644
--- a/gui/src/main/ipc-event-channel.ts
+++ b/gui/src/main/ipc-event-channel.ts
@@ -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);
+}
diff --git a/gui/src/main/user-interface.ts b/gui/src/main/user-interface.ts
index 6cb985b845..2c1ac03f27 100644
--- a/gui/src/main/user-interface.ts
+++ b/gui/src/main/user-interface.ts
@@ -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';
@@ -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();
}
@@ -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();
@@ -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);