Add win.setModal(modal) API

This commit is contained in:
Cheng Zhao 2016-06-17 17:49:35 +09:00
parent 1a4b4a65c9
commit 3f34f80433

View file

@ -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 = () => { BrowserWindow.getFocusedWindow = () => {
for (let window of BrowserWindow.getAllWindows()) { for (let window of BrowserWindow.getAllWindows()) {
if (window.isFocused()) return window if (window.isFocused()) return window
@ -117,7 +134,6 @@ BrowserWindow.fromDevToolsWebContents = (webContents) => {
} }
// Helpers. // Helpers.
Object.assign(BrowserWindow.prototype, { Object.assign(BrowserWindow.prototype, {
loadURL (...args) { loadURL (...args) {
return this.webContents.loadURL.apply(this.webContents, args) return this.webContents.loadURL.apply(this.webContents, args)