Add webContents.getFocusedWebContents()
This commit is contained in:
parent
7877fa7c0a
commit
06e595e7cc
1 changed files with 14 additions and 2 deletions
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
const {EventEmitter} = require('events')
|
const {EventEmitter} = require('events')
|
||||||
const {app, ipcMain, session, Menu, NavigationController} = require('electron')
|
const {app, ipcMain, session, Menu, NavigationController} = require('electron')
|
||||||
|
const {getAllWebContents} = process.atomBinding('web_contents')
|
||||||
|
|
||||||
// session is not used here, the purpose is to make sure session is initalized
|
// session is not used here, the purpose is to make sure session is initalized
|
||||||
// before the webContents module.
|
// before the webContents module.
|
||||||
|
@ -245,7 +246,18 @@ module.exports = {
|
||||||
fromId (id) {
|
fromId (id) {
|
||||||
return binding.fromId(id)
|
return binding.fromId(id)
|
||||||
},
|
},
|
||||||
getAllWebContents () {
|
|
||||||
return binding.getAllWebContents()
|
getFocusedWebContents () {
|
||||||
|
let focused = null
|
||||||
|
for (let contents of getAllWebContents()) {
|
||||||
|
if (!contents.isFocused()) continue
|
||||||
|
|
||||||
|
// Return webview web contents which may be embedded inside another
|
||||||
|
// web contents that is also reporting as focused
|
||||||
|
if (contents.getType() === 'webview') return contents
|
||||||
|
|
||||||
|
if (focused == null) focused = contents
|
||||||
|
}
|
||||||
|
return focused
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue