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 = @getWebContents()
|
||||||
@webContents.once 'destroyed', => @webContents = null
|
@webContents.once 'destroyed', => @webContents = null
|
||||||
|
|
||||||
# Remember the window.
|
# Remember the window ID.
|
||||||
id = BrowserWindow.windows.add this
|
Object.defineProperty this, 'id',
|
||||||
|
value: BrowserWindow.windows.add(this)
|
||||||
|
enumerable: true
|
||||||
|
|
||||||
# Remove the window from weak map immediately when it's destroyed, since we
|
# Remove the window from weak map immediately when it's destroyed, since we
|
||||||
# could be iterating windows before GC happened.
|
# could be iterating windows before GC happened.
|
||||||
@once 'closed', ->
|
@once 'closed', =>
|
||||||
BrowserWindow.windows.remove id if BrowserWindow.windows.has id
|
BrowserWindow.windows.remove @id if BrowserWindow.windows.has @id
|
||||||
|
|
||||||
BrowserWindow::openDevTools = ->
|
BrowserWindow::openDevTools = ->
|
||||||
@_openDevTools()
|
@_openDevTools()
|
||||||
|
@ -67,6 +69,9 @@ BrowserWindow.fromDevToolsWebContents = (webContents) ->
|
||||||
windows = BrowserWindow.getAllWindows()
|
windows = BrowserWindow.getAllWindows()
|
||||||
return window for window in windows when webContents.equal window.devToolsWebContents
|
return window for window in windows when webContents.equal window.devToolsWebContents
|
||||||
|
|
||||||
|
BrowserWindow.fromId = (id) ->
|
||||||
|
BrowserWindow.windows.get id
|
||||||
|
|
||||||
# Helpers.
|
# Helpers.
|
||||||
BrowserWindow::loadUrl = -> @webContents.loadUrl.apply @webContents, arguments
|
BrowserWindow::loadUrl = -> @webContents.loadUrl.apply @webContents, arguments
|
||||||
BrowserWindow::send = -> @webContents.send.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[0], size[0]
|
||||||
assert.equal after[1], size[1]
|
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', ->
|
describe '"use-content-size" option', ->
|
||||||
it 'make window created with content size when used', ->
|
it 'make window created with content size when used', ->
|
||||||
w.destroy()
|
w.destroy()
|
||||||
|
|
Loading…
Reference in a new issue