Defend against destroyed window when updating zoom factor

This commit is contained in:
Evan Hahn 2021-09-30 17:29:06 -05:00 committed by GitHub
parent 03ec561891
commit 9e856e19a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 3 deletions

12
main.js
View File

@ -320,14 +320,20 @@ function handleCommonWindowEvents(window) {
// Works only for mainWindow because it has `enablePreferredSizeMode`
let lastZoomFactor = window.webContents.getZoomFactor();
const onZoomChanged = () => {
if (
window.isDestroyed() ||
!window.webContents ||
window.webContents.isDestroyed()
) {
return;
}
const zoomFactor = window.webContents.getZoomFactor();
if (lastZoomFactor === zoomFactor) {
return;
}
if (window.webContents) {
window.webContents.send('callbacks:call:persistZoomFactor', [zoomFactor]);
}
window.webContents.send('callbacks:call:persistZoomFactor', [zoomFactor]);
lastZoomFactor = zoomFactor;
};