refactor: make ELECTRON_INSPECTOR_SELECT_FILE handler async (#17235)

This commit is contained in:
Milan Burda 2019-03-06 22:22:45 +01:00 коммит произвёл Alexey Kuzmin
Родитель 6cb7b8d3a4
Коммит 2733697819
1 изменённых файлов: 12 добавлений и 18 удалений

Просмотреть файл

@ -3,9 +3,12 @@
const { dialog, Menu } = require('electron')
const fs = require('fs')
const url = require('url')
const util = require('util')
const ipcMainUtils = require('@electron/internal/browser/ipc-main-internal-utils')
const readFile = util.promisify(fs.readFile)
const convertToMenuTemplate = function (event, items) {
return items.map(function (item) {
const transformed = item.type === 'subMenu' ? {
@ -82,25 +85,16 @@ ipcMainUtils.handle('ELECTRON_INSPECTOR_CONTEXT_MENU', function (event, items, i
menu.popup({ window })
})
ipcMainUtils.handle('ELECTRON_INSPECTOR_SELECT_FILE', function (event) {
return new Promise((resolve, reject) => {
assertChromeDevTools(event.sender, 'window.UI.createFileSelectorElement()')
ipcMainUtils.handle('ELECTRON_INSPECTOR_SELECT_FILE', async function (event) {
assertChromeDevTools(event.sender, 'window.UI.createFileSelectorElement()')
dialog.showOpenDialog({}, function (result) {
if (!result.canceled) {
const path = result.filePaths[0]
fs.readFile(path, (error, data) => {
if (error) {
reject(error)
} else {
resolve([path, data])
}
})
} else {
resolve([])
}
})
})
const result = await dialog.showOpenDialog({})
if (result.canceled) return []
const path = result.filePaths[0]
const data = await readFile(path)
return [path, data]
})
ipcMainUtils.handle('ELECTRON_INSPECTOR_CONFIRM', function (event, message, title) {