Use .close()
instead of the private .destroy()
to stop leaking WebContents (#2990)
* Use `.close()` instead of the private `.destroy()` to stop leaking WebContents * Fix tests
This commit is contained in:
parent
6c3eced3e9
commit
da59e13477
|
@ -364,21 +364,21 @@ describe('main/views/MattermostBrowserView', () => {
|
||||||
|
|
||||||
it('should remove browser view from window', () => {
|
it('should remove browser view from window', () => {
|
||||||
const mattermostView = new MattermostBrowserView(view, {}, {});
|
const mattermostView = new MattermostBrowserView(view, {}, {});
|
||||||
mattermostView.browserView.webContents.destroy = jest.fn();
|
mattermostView.browserView.webContents.close = jest.fn();
|
||||||
mattermostView.destroy();
|
mattermostView.destroy();
|
||||||
expect(window.removeBrowserView).toBeCalledWith(mattermostView.browserView);
|
expect(window.removeBrowserView).toBeCalledWith(mattermostView.browserView);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should clear mentions', () => {
|
it('should clear mentions', () => {
|
||||||
const mattermostView = new MattermostBrowserView(view, {}, {});
|
const mattermostView = new MattermostBrowserView(view, {}, {});
|
||||||
mattermostView.browserView.webContents.destroy = jest.fn();
|
mattermostView.browserView.webContents.close = jest.fn();
|
||||||
mattermostView.destroy();
|
mattermostView.destroy();
|
||||||
expect(AppState.clear).toBeCalledWith(mattermostView.view.id);
|
expect(AppState.clear).toBeCalledWith(mattermostView.view.id);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should clear outstanding timeouts', () => {
|
it('should clear outstanding timeouts', () => {
|
||||||
const mattermostView = new MattermostBrowserView(view, {}, {});
|
const mattermostView = new MattermostBrowserView(view, {}, {});
|
||||||
mattermostView.browserView.webContents.destroy = jest.fn();
|
mattermostView.browserView.webContents.close = jest.fn();
|
||||||
const spy = jest.spyOn(global, 'clearTimeout');
|
const spy = jest.spyOn(global, 'clearTimeout');
|
||||||
mattermostView.retryLoad = 999;
|
mattermostView.retryLoad = 999;
|
||||||
mattermostView.removeLoading = 1000;
|
mattermostView.removeLoading = 1000;
|
||||||
|
|
|
@ -258,12 +258,7 @@ export class MattermostBrowserView extends EventEmitter {
|
||||||
WebContentsEventManager.removeWebContentsListeners(this.webContentsId);
|
WebContentsEventManager.removeWebContentsListeners(this.webContentsId);
|
||||||
AppState.clear(this.id);
|
AppState.clear(this.id);
|
||||||
MainWindow.get()?.removeBrowserView(this.browserView);
|
MainWindow.get()?.removeBrowserView(this.browserView);
|
||||||
|
this.browserView.webContents.close();
|
||||||
// workaround to eliminate zombie processes
|
|
||||||
// https://github.com/mattermost/desktop/pull/1519
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
// @ts-ignore
|
|
||||||
this.browserView.webContents.destroy();
|
|
||||||
|
|
||||||
this.isVisible = false;
|
this.isVisible = false;
|
||||||
if (this.retryLoad) {
|
if (this.retryLoad) {
|
||||||
|
|
|
@ -15,7 +15,7 @@ jest.mock('electron', () => ({
|
||||||
openDevTools: jest.fn(),
|
openDevTools: jest.fn(),
|
||||||
isDevToolsOpened: jest.fn(),
|
isDevToolsOpened: jest.fn(),
|
||||||
closeDevTools: jest.fn(),
|
closeDevTools: jest.fn(),
|
||||||
destroy: jest.fn(),
|
close: jest.fn(),
|
||||||
},
|
},
|
||||||
setBounds: jest.fn(),
|
setBounds: jest.fn(),
|
||||||
setAutoResize: jest.fn(),
|
setAutoResize: jest.fn(),
|
||||||
|
@ -106,7 +106,7 @@ describe('main/views/modalView', () => {
|
||||||
|
|
||||||
it('should remove browser view and destroy web contents on hide', () => {
|
it('should remove browser view and destroy web contents on hide', () => {
|
||||||
modalView.hide();
|
modalView.hide();
|
||||||
expect(modalView.view.webContents.destroy).toBeCalled();
|
expect(modalView.view.webContents.close).toBeCalled();
|
||||||
expect(window.removeBrowserView).toBeCalledWith(modalView.view);
|
expect(window.removeBrowserView).toBeCalledWith(modalView.view);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -99,12 +99,7 @@ export class ModalView<T, T2> {
|
||||||
this.view.webContents.closeDevTools();
|
this.view.webContents.closeDevTools();
|
||||||
}
|
}
|
||||||
this.windowAttached.removeBrowserView(this.view);
|
this.windowAttached.removeBrowserView(this.view);
|
||||||
|
this.view.webContents.close();
|
||||||
// workaround to eliminate zombie processes
|
|
||||||
// https://github.com/mattermost/desktop/pull/1519
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
// @ts-ignore
|
|
||||||
this.view.webContents.destroy();
|
|
||||||
|
|
||||||
delete this.windowAttached;
|
delete this.windowAttached;
|
||||||
this.status = Status.ACTIVE;
|
this.status = Status.ACTIVE;
|
||||||
|
|
|
@ -354,11 +354,7 @@ export class ViewManager {
|
||||||
log.error('Failed to remove URL view', e);
|
log.error('Failed to remove URL view', e);
|
||||||
}
|
}
|
||||||
|
|
||||||
// workaround to eliminate zombie processes
|
urlView.webContents.close();
|
||||||
// https://github.com/mattermost/desktop/pull/1519
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
// @ts-ignore
|
|
||||||
urlView.webContents.destroy();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const adjustWidth = (event: IpcMainEvent, width: number) => {
|
const adjustWidth = (event: IpcMainEvent, width: number) => {
|
||||||
|
|
Loading…
Reference in a new issue