Add "id" property for BrowserWindow, fixes #218.
This commit is contained in:
parent
764deab5c1
commit
d49060d659
2 changed files with 13 additions and 4 deletions
|
@ -18,13 +18,15 @@ BrowserWindow::_init = ->
|
|||
@webContents = @getWebContents()
|
||||
@webContents.once 'destroyed', => @webContents = null
|
||||
|
||||
# Remember the window.
|
||||
id = BrowserWindow.windows.add this
|
||||
# Remember the window ID.
|
||||
Object.defineProperty this, 'id',
|
||||
value: BrowserWindow.windows.add(this)
|
||||
enumerable: true
|
||||
|
||||
# Remove the window from weak map immediately when it's destroyed, since we
|
||||
# could be iterating windows before GC happened.
|
||||
@once 'closed', ->
|
||||
BrowserWindow.windows.remove id if BrowserWindow.windows.has id
|
||||
@once 'closed', =>
|
||||
BrowserWindow.windows.remove @id if BrowserWindow.windows.has @id
|
||||
|
||||
BrowserWindow::openDevTools = ->
|
||||
@_openDevTools()
|
||||
|
@ -67,6 +69,9 @@ BrowserWindow.fromDevToolsWebContents = (webContents) ->
|
|||
windows = BrowserWindow.getAllWindows()
|
||||
return window for window in windows when webContents.equal window.devToolsWebContents
|
||||
|
||||
BrowserWindow.fromId = (id) ->
|
||||
BrowserWindow.windows.get id
|
||||
|
||||
# Helpers.
|
||||
BrowserWindow::loadUrl = -> @webContents.loadUrl.apply @webContents, arguments
|
||||
BrowserWindow::send = -> @webContents.send.apply @webContents, arguments
|
||||
|
|
|
@ -90,6 +90,10 @@ describe 'browser-window module', ->
|
|||
assert.equal after[0], size[0]
|
||||
assert.equal after[1], size[1]
|
||||
|
||||
describe 'BrowserWindow.fromId(id)', ->
|
||||
it 'returns the window with id', ->
|
||||
assert.equal w.id, BrowserWindow.fromId(w.id).id
|
||||
|
||||
describe '"use-content-size" option', ->
|
||||
it 'make window created with content size when used', ->
|
||||
w.destroy()
|
||||
|
|
Loading…
Reference in a new issue