MM-51850 - Calls: Fix for crash after closing popout (#2647) (#2649)

(cherry picked from commit 4fe66b298d)
This commit is contained in:
Christopher Poile 2023-03-31 12:57:03 -04:00 committed by GitHub
parent 595f0abf3d
commit d92860c49d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 1 deletions

View file

@ -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,

View file

@ -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() {