diff --git a/shell/browser/ui/cocoa/atom_ns_window_delegate.mm b/shell/browser/ui/cocoa/atom_ns_window_delegate.mm index f685377843105..371bfd2f13347 100644 --- a/shell/browser/ui/cocoa/atom_ns_window_delegate.mm +++ b/shell/browser/ui/cocoa/atom_ns_window_delegate.mm @@ -88,11 +88,11 @@ - (NSRect)windowWillUseStandardFrame:(NSWindow*)window return frame; } -- (void)windowDidBecomeMain:(NSNotification*)notification { +- (void)windowDidBecomeKey:(NSNotification*)notification { shell_->NotifyWindowFocus(); } -- (void)windowDidResignMain:(NSNotification*)notification { +- (void)windowDidResignKey:(NSNotification*)notification { shell_->NotifyWindowBlur(); } diff --git a/spec/api-browser-window-spec.js b/spec/api-browser-window-spec.js index e310090dc7809..8dd37d158b3ab 100644 --- a/spec/api-browser-window-spec.js +++ b/spec/api-browser-window-spec.js @@ -1637,6 +1637,34 @@ describe('BrowserWindow module', () => { }) }) + describe('focus event', () => { + it('should not emit if focusing on a main window with a modal open', (done) => { + const childWindowClosed = false + const child = new BrowserWindow({ + parent: w, + modal: true, + show: false + }) + + child.once('ready-to-show', () => { + child.show() + }) + + child.on('show', () => { + w.once('focus', () => { + expect(child.isDestroyed()).to.equal(true) + done() + }) + w.focus() // this should not trigger the above listener + child.close() + }) + + // act + child.loadURL(server.url) + w.show() + }) + }) + describe('sheet-begin event', () => { let sheet = null