Merge pull request #2774 from atom/browser-window-created

Add browser-window-created event for app module
This commit is contained in:
Cheng Zhao 2015-09-14 17:44:50 +08:00
commit 1533d97e16
3 changed files with 32 additions and 9 deletions

View file

@ -45,6 +45,9 @@ BrowserWindow::_init = ->
@on 'focus', (event) =>
app.emit 'browser-window-focus', event, this
# Notify the creation of the window.
app.emit 'browser-window-created', {}, this
BrowserWindow.getFocusedWindow = ->
windows = BrowserWindow.getAllWindows()
return window for window in windows when window.isFocused()

View file

@ -118,6 +118,15 @@ Returns:
Emitted when a [browserWindow](browser-window.md) gets focused.
### Event: 'browser-window-created'
Returns:
* `event` Event
* `window` BrowserWindow
Emitted when a new [browserWindow](browser-window.md) is created.
### Event: 'select-certificate'
Emitted when a client certificate is requested.

View file

@ -26,19 +26,30 @@ describe 'app module', ->
assert.equal app.getName(), 'test-name'
app.setName 'Electron Test'
describe 'focus/blur event', ->
describe 'BrowserWindow events', ->
w = null
beforeEach ->
w.destroy() if w?
w = new BrowserWindow(show: false, width: 400, height: 400)
afterEach ->
w.destroy() if w?
w = null
it 'should emit focus event', (done) ->
it 'should emit browser-window-focus event when window is focused', (done) ->
app.once 'browser-window-focus', (e, window) ->
assert.equal w.id, window.id
done()
w = new BrowserWindow(show: false)
w.emit 'focus'
it 'should emit browser-window-blur event when window is blured', (done) ->
app.once 'browser-window-blur', (e, window) ->
assert.equal w.id, window.id
done()
app.once 'browser-window-focus', (e, window) ->
assert.equal w.id, window.id
w.emit 'blur'
w.emit 'focus'
w = new BrowserWindow(show: false)
w.emit 'blur'
it 'should emit browser-window-created event when window is created', (done) ->
app.once 'browser-window-created', (e, window) ->
setImmediate ->
assert.equal w.id, window.id
done()
w = new BrowserWindow(show: false)
w.emit 'blur'