Implement dialog (alert/confirm) blocking as a user switch after the first dialog
* This is to enable more browser-like behavior so that users who run third-party code will not be DOS'ed with alerts and confirms. This is already handled like this in most major browsers so this will greatly help these developers
This commit is contained in:
parent
a3d4d461a3
commit
795447f61a
7 changed files with 47 additions and 43 deletions
|
@ -438,39 +438,6 @@ ipcMain.on('ELECTRON_BROWSER_SEND_TO', function (event, sendToAll, webContentsId
|
|||
}
|
||||
})
|
||||
|
||||
// Implements window.alert(message, title)
|
||||
ipcMain.on('ELECTRON_BROWSER_WINDOW_ALERT', function (event, message, title) {
|
||||
if (message == null) message = ''
|
||||
if (title == null) title = ''
|
||||
|
||||
const dialogProperties = {
|
||||
message: `${message}`,
|
||||
title: `${title}`,
|
||||
buttons: ['OK']
|
||||
}
|
||||
event.returnValue = event.sender.isOffscreen()
|
||||
? electron.dialog.showMessageBox(dialogProperties)
|
||||
: electron.dialog.showMessageBox(
|
||||
event.sender.getOwnerBrowserWindow(), dialogProperties)
|
||||
})
|
||||
|
||||
// Implements window.confirm(message, title)
|
||||
ipcMain.on('ELECTRON_BROWSER_WINDOW_CONFIRM', function (event, message, title) {
|
||||
if (message == null) message = ''
|
||||
if (title == null) title = ''
|
||||
|
||||
const dialogProperties = {
|
||||
message: `${message}`,
|
||||
title: `${title}`,
|
||||
buttons: ['OK', 'Cancel'],
|
||||
cancelId: 1
|
||||
}
|
||||
event.returnValue = !(event.sender.isOffscreen()
|
||||
? electron.dialog.showMessageBox(dialogProperties)
|
||||
: electron.dialog.showMessageBox(
|
||||
event.sender.getOwnerBrowserWindow(), dialogProperties))
|
||||
})
|
||||
|
||||
// Implements window.close()
|
||||
ipcMain.on('ELECTRON_BROWSER_WINDOW_CLOSE', function (event) {
|
||||
const window = event.sender.getOwnerBrowserWindow()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue