refactor: make ELECTRON_INSPECTOR_CONFIRM handler async (#17378)

This commit is contained in:
Milan Burda 2019-03-14 23:29:40 +01:00 committed by Samuel Attard
parent cb4ede453f
commit f15d0b1ed7

View file

@ -97,22 +97,16 @@ ipcMainUtils.handle('ELECTRON_INSPECTOR_SELECT_FILE', async function (event) {
return [path, data] return [path, data]
}) })
ipcMainUtils.handle('ELECTRON_INSPECTOR_CONFIRM', function (event, message, title) { ipcMainUtils.handle('ELECTRON_INSPECTOR_CONFIRM', async function (event, message = '', title = '') {
return new Promise((resolve, reject) => {
assertChromeDevTools(event.sender, 'window.confirm()') assertChromeDevTools(event.sender, 'window.confirm()')
if (message == null) message = ''
if (title == null) title = ''
const options = { const options = {
message: `${message}`, message: String(message),
title: `${title}`, title: String(title),
buttons: ['OK', 'Cancel'], buttons: ['OK', 'Cancel'],
cancelId: 1 cancelId: 1
} }
const window = event.sender.getOwnerBrowserWindow() const window = event.sender.getOwnerBrowserWindow()
dialog.showMessageBox(window, options, (response) => { const { response } = await dialog.showMessageBox(window, options)
resolve(response === 0) return response === 0
})
})
}) })