From f15d0b1ed777db90a2ee9a8f4ca8b68d2e81e979 Mon Sep 17 00:00:00 2001 From: Milan Burda Date: Thu, 14 Mar 2019 23:29:40 +0100 Subject: [PATCH] refactor: make ELECTRON_INSPECTOR_CONFIRM handler async (#17378) --- lib/browser/chrome-devtools.js | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/lib/browser/chrome-devtools.js b/lib/browser/chrome-devtools.js index 2204b3d163f6..030fdacac44b 100644 --- a/lib/browser/chrome-devtools.js +++ b/lib/browser/chrome-devtools.js @@ -97,22 +97,16 @@ ipcMainUtils.handle('ELECTRON_INSPECTOR_SELECT_FILE', async function (event) { return [path, data] }) -ipcMainUtils.handle('ELECTRON_INSPECTOR_CONFIRM', function (event, message, title) { - return new Promise((resolve, reject) => { - assertChromeDevTools(event.sender, 'window.confirm()') +ipcMainUtils.handle('ELECTRON_INSPECTOR_CONFIRM', async function (event, message = '', title = '') { + assertChromeDevTools(event.sender, 'window.confirm()') - if (message == null) message = '' - if (title == null) title = '' - - const options = { - message: `${message}`, - title: `${title}`, - buttons: ['OK', 'Cancel'], - cancelId: 1 - } - const window = event.sender.getOwnerBrowserWindow() - dialog.showMessageBox(window, options, (response) => { - resolve(response === 0) - }) - }) + const options = { + message: String(message), + title: String(title), + buttons: ['OK', 'Cancel'], + cancelId: 1 + } + const window = event.sender.getOwnerBrowserWindow() + const { response } = await dialog.showMessageBox(window, options) + return response === 0 })