diff --git a/src/main/windows/callsWidgetWindow.test.js b/src/main/windows/callsWidgetWindow.test.js index 0e9f52de..ab960709 100644 --- a/src/main/windows/callsWidgetWindow.test.js +++ b/src/main/windows/callsWidgetWindow.test.js @@ -531,6 +531,23 @@ describe('main/windows/callsWidgetWindow', () => { expect(popOut.webContents.on).toHaveBeenCalledWith('will-redirect', widgetWindow.onWillRedirect); }); + it('onPopOutClosed', () => { + const widgetWindow = new CallsWidgetWindow(mainWindow, mainView, widgetConfig); + expect(widgetWindow.popOut).toBeNull(); + + const popOut = new EventEmitter(); + popOut.webContents = { + on: jest.fn(), + id: 'webContentsId', + }; + + widgetWindow.onPopOutCreate(popOut); + expect(widgetWindow.popOut).toBe(popOut); + + popOut.emit('closed'); + expect(widgetWindow.popOut).toBeNull(); + }); + it('getWebContentsId', () => { baseWindow.webContents = { ...baseWindow.webContents, diff --git a/src/main/windows/callsWidgetWindow.ts b/src/main/windows/callsWidgetWindow.ts index 648a80ff..cb1c0f01 100644 --- a/src/main/windows/callsWidgetWindow.ts +++ b/src/main/windows/callsWidgetWindow.ts @@ -243,6 +243,7 @@ export default class CallsWidgetWindow extends EventEmitter { private onPopOutCreate = (win: BrowserWindow) => { this.popOut = win; + this.popOut.on('closed', this.onPopOutClosed); // Let the webContentsEventManager handle links that try to open a new window. webContentsEventManager.addWebContentsEventListeners(this.popOut.webContents); @@ -251,6 +252,12 @@ export default class CallsWidgetWindow extends EventEmitter { this.popOut.webContents.on('will-redirect', this.onWillRedirect); } + private onPopOutClosed = () => { + log.debug('CallsWidgetWindow.onPopOutClosed'); + this.popOut?.removeAllListeners('closed'); + this.popOut = null; + } + // eslint-disable-next-line @typescript-eslint/no-unused-vars private onWillRedirect = (event: Event, url: string) => { // There's no reason we would allow a redirect from the call's popout. Eventually we may, so revise then. @@ -273,7 +280,7 @@ export default class CallsWidgetWindow extends EventEmitter { } public getPopOutWebContentsId() { - return this.popOut?.webContents.id; + return this.popOut?.webContents?.id; } public getURL() {