mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
Add win.setModal(modal) API
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user