fix: potential "Object has been destroyed" error in BrowserWindow.getFocusedWindow (#35520)

This commit is contained in:
Milan Burda 2022-09-12 23:46:05 +02:00 committed by GitHub
parent c14f52aeb7
commit b3a744db8a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -72,9 +72,8 @@ BrowserWindow.getAllWindows = () => {
BrowserWindow.getFocusedWindow = () => { BrowserWindow.getFocusedWindow = () => {
for (const window of BrowserWindow.getAllWindows()) { for (const window of BrowserWindow.getAllWindows()) {
const hasWC = window.webContents && !window.webContents.isDestroyed(); if (!window.isDestroyed() && window.webContents && !window.webContents.isDestroyed()) {
if (!window.isDestroyed() && hasWC) { if (window.isFocused() || window.webContents.isDevToolsFocused()) return window;
if (window.isFocused() || window.isDevToolsFocused()) return window;
} }
} }
return null; return null;