refactor: make CHROME_GET_MESSAGES handler async (#17148)

This commit is contained in:
Milan Burda 2019-02-28 04:30:35 +01:00 committed by Charles Kerr
parent bfa07ec4be
commit 64078324bf

View file

@ -12,6 +12,9 @@ const path = require('path')
const url = require('url')
const util = require('util')
const readFile = util.promisify(fs.readFile)
const writeFile = util.promisify(fs.writeFile)
// Mapping between extensionId(hostname) and manifest.
const manifestMap = {} // extensionId => manifest
const manifestNameMap = {} // name => manifest
@ -232,9 +235,9 @@ const getMessagesPath = (extensionId) => {
}
}
ipcMainUtils.handle('CHROME_GET_MESSAGES', function (event, extensionId) {
ipcMainUtils.handle('CHROME_GET_MESSAGES', async function (event, extensionId) {
const messagesPath = getMessagesPath(extensionId)
return fs.readFileSync(messagesPath)
return readFile(messagesPath)
})
const validStorageTypes = new Set(['sync', 'local'])
@ -267,9 +270,6 @@ const mkdirp = util.promisify((dir, callback) => {
})
})
const readFile = util.promisify(fs.readFile)
const writeFile = util.promisify(fs.writeFile)
ipcMainUtils.handle('CHROME_STORAGE_READ', async function (event, storageType, extensionId) {
const filePath = getChromeStoragePath(storageType, extensionId)