Add win.setModal(modal) API
This commit is contained in:
parent
1a4b4a65c9
commit
3f34f80433
1 changed files with 17 additions and 1 deletions
|
@ -97,6 +97,23 @@ BrowserWindow.prototype._init = function () {
|
|||
})
|
||||
}
|
||||
|
||||
BrowserWindow.prototype.setModal = function (modal) {
|
||||
const parent = this.getParentWindow()
|
||||
if (!parent) {
|
||||
throw new Error('setModal can only be called for child window')
|
||||
}
|
||||
|
||||
let closeListener = () => parent.enable()
|
||||
if (modal) {
|
||||
parent.disable()
|
||||
this.once('closed', closeListener)
|
||||
this.show()
|
||||
} else {
|
||||
parent.enable()
|
||||
this.removeListener('closed', closeListener)
|
||||
}
|
||||
}
|
||||
|
||||
BrowserWindow.getFocusedWindow = () => {
|
||||
for (let window of BrowserWindow.getAllWindows()) {
|
||||
if (window.isFocused()) return window
|
||||
|
@ -117,7 +134,6 @@ BrowserWindow.fromDevToolsWebContents = (webContents) => {
|
|||
}
|
||||
|
||||
// Helpers.
|
||||
|
||||
Object.assign(BrowserWindow.prototype, {
|
||||
loadURL (...args) {
|
||||
return this.webContents.loadURL.apply(this.webContents, args)
|
||||
|
|
Loading…
Add table
Reference in a new issue