fix: crash on parent window close and focur/blur (#46559)

This commit is contained in:
Shelley Vohr 2025-04-09 15:35:30 +02:00 committed by GitHub
parent 93a51cc756
commit 521108e2a5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 14 additions and 2 deletions

View file

@ -219,14 +219,14 @@ void BrowserWindow::CloseImmediately() {
}
void BrowserWindow::Focus() {
if (api_web_contents_->IsOffScreen())
if (api_web_contents_ && api_web_contents_->IsOffScreen())
FocusOnWebView();
else
BaseWindow::Focus();
}
void BrowserWindow::Blur() {
if (api_web_contents_->IsOffScreen())
if (api_web_contents_ && api_web_contents_->IsOffScreen())
BlurWebView();
else
BaseWindow::Blur();

View file

@ -4930,6 +4930,18 @@ describe('BrowserWindow module', () => {
expect(w.getChildWindows().length).to.equal(0);
});
it('can handle parent window close with focus or blur events', (done) => {
const w = new BrowserWindow({ show: false });
const c = new BrowserWindow({ show: false, parent: w });
c.on('closed', () => {
w.focus();
done();
});
w.close();
});
ifit(process.platform === 'darwin')('only shows the intended window when a child with siblings is shown', async () => {
const w = new BrowserWindow({ show: false });
const childOne = new BrowserWindow({ show: false, parent: w });