fix: Correct modal focus behavior on macOS (#19063)

* wip: wish i could hack the main window focus away

* main -> key

* remove useless code

* test: Add focus event spec

* test: more robust spec

* test: simplify test

* duplicate non-firing macOS event listener 😳

* destroy 🚨

* chore: remove unused variable
This commit is contained in:
trop[bot]
2019-07-02 09:20:15 -07:00
committed by Shelley Vohr
parent 3d60f82d03
commit 32ad5be74e
2 changed files with 29 additions and 2 deletions

View File

@@ -84,11 +84,11 @@
return frame;
}
- (void)windowDidBecomeMain:(NSNotification*)notification {
- (void)windowDidBecomeKey:(NSNotification*)notification {
shell_->NotifyWindowFocus();
}
- (void)windowDidResignMain:(NSNotification*)notification {
- (void)windowDidResignKey:(NSNotification*)notification {
shell_->NotifyWindowBlur();
}

View File

@@ -2480,6 +2480,33 @@ describe('BrowserWindow module', () => {
})
})
describe('focus event', () => {
it('should not emit if focusing on a main window with a modal open', (done) => {
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