From 48e4bccf0d24bb6ce53c4ecea567ed7750fe8949 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sun, 17 Jun 2018 20:21:39 +0900 Subject: Use async/await on background --- src/background/components/indicator.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'src/background/components/indicator.js') diff --git a/src/background/components/indicator.js b/src/background/components/indicator.js index cceb119..1ded329 100644 --- a/src/background/components/indicator.js +++ b/src/background/components/indicator.js @@ -8,19 +8,17 @@ export default class IndicatorComponent { messages.onMessage(this.onMessage.bind(this)); browser.browserAction.onClicked.addListener(this.onClicked); - browser.tabs.onActivated.addListener((info) => { - return browser.tabs.query({ currentWindow: true }).then(() => { - return this.onTabActivated(info); - }); + browser.tabs.onActivated.addListener(async(info) => { + await browser.tabs.query({ currentWindow: true }); + return this.onTabActivated(info); }); } - onTabActivated(info) { - return browser.tabs.sendMessage(info.tabId, { + async onTabActivated(info) { + let { enabled } = await browser.tabs.sendMessage(info.tabId, { type: messages.ADDON_ENABLED_QUERY, - }).then((resp) => { - return this.updateIndicator(resp.enabled); }); + return this.updateIndicator(enabled); } onClicked(tab) { -- cgit v1.2.3