fix: remove resize listener when BrowserWindow closed (#44000)

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
This commit is contained in:
trop[bot] 2024-09-27 14:46:22 -04:00 committed by GitHub
parent 481f9b25a7
commit ce2163da2f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -68,10 +68,7 @@ export default class BrowserView {
// a webContents can be closed by the user while the BrowserView
// remains alive and attached to a BrowserWindow.
set ownerWindow (w: BrowserWindow | null) {
if (this.#ownerWindow && this.#resizeListener) {
this.#ownerWindow.off('resize', this.#resizeListener);
this.#resizeListener = null;
}
this.#removeResizeListener();
if (this.webContents && !this.webContents.isDestroyed()) {
this.webContents._setOwnerWindow(w);
@ -82,6 +79,7 @@ export default class BrowserView {
this.#lastWindowSize = w.getBounds();
w.on('resize', this.#resizeListener = this.#autoResize.bind(this));
w.on('closed', () => {
this.#removeResizeListener();
this.#ownerWindow = null;
this.#destroyListener = null;
});
@ -94,6 +92,13 @@ export default class BrowserView {
this.#ownerWindow?.contentView.removeChildView(this.webContentsView);
}
#removeResizeListener () {
if (this.#ownerWindow && this.#resizeListener) {
this.#ownerWindow.off('resize', this.#resizeListener);
this.#resizeListener = null;
}
}
#autoHorizontalProportion: {width: number, left: number} | null = null;
#autoVerticalProportion: {height: number, top: number} | null = null;
#autoResize () {