From 64078324bfdd316f1a8e21c77d5b68c45f06355a Mon Sep 17 00:00:00 2001 From: Milan Burda Date: Thu, 28 Feb 2019 04:30:35 +0100 Subject: [PATCH] refactor: make CHROME_GET_MESSAGES handler async (#17148) --- lib/browser/chrome-extension.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/browser/chrome-extension.js b/lib/browser/chrome-extension.js index 39b62236475c..9b1420b9976b 100644 --- a/lib/browser/chrome-extension.js +++ b/lib/browser/chrome-extension.js @@ -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)