fix: remove resize listener when BrowserWindow closed (#44001)
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:
parent
21a8a97c28
commit
8a35e24249
1 changed files with 9 additions and 4 deletions
|
@ -68,10 +68,7 @@ export default class BrowserView {
|
||||||
// a webContents can be closed by the user while the BrowserView
|
// a webContents can be closed by the user while the BrowserView
|
||||||
// remains alive and attached to a BrowserWindow.
|
// remains alive and attached to a BrowserWindow.
|
||||||
set ownerWindow (w: BrowserWindow | null) {
|
set ownerWindow (w: BrowserWindow | null) {
|
||||||
if (this.#ownerWindow && this.#resizeListener) {
|
this.#removeResizeListener();
|
||||||
this.#ownerWindow.off('resize', this.#resizeListener);
|
|
||||||
this.#resizeListener = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.webContents && !this.webContents.isDestroyed()) {
|
if (this.webContents && !this.webContents.isDestroyed()) {
|
||||||
this.webContents._setOwnerWindow(w);
|
this.webContents._setOwnerWindow(w);
|
||||||
|
@ -82,6 +79,7 @@ export default class BrowserView {
|
||||||
this.#lastWindowSize = w.getBounds();
|
this.#lastWindowSize = w.getBounds();
|
||||||
w.on('resize', this.#resizeListener = this.#autoResize.bind(this));
|
w.on('resize', this.#resizeListener = this.#autoResize.bind(this));
|
||||||
w.on('closed', () => {
|
w.on('closed', () => {
|
||||||
|
this.#removeResizeListener();
|
||||||
this.#ownerWindow = null;
|
this.#ownerWindow = null;
|
||||||
this.#destroyListener = null;
|
this.#destroyListener = null;
|
||||||
});
|
});
|
||||||
|
@ -94,6 +92,13 @@ export default class BrowserView {
|
||||||
this.#ownerWindow?.contentView.removeChildView(this.webContentsView);
|
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;
|
#autoHorizontalProportion: {width: number, left: number} | null = null;
|
||||||
#autoVerticalProportion: {height: number, top: number} | null = null;
|
#autoVerticalProportion: {height: number, top: number} | null = null;
|
||||||
#autoResize () {
|
#autoResize () {
|
||||||
|
|
Loading…
Reference in a new issue