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/actions/tab.js | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'src/background/actions/tab.js') diff --git a/src/background/actions/tab.js b/src/background/actions/tab.js index 0d439fd..5cf1e8c 100644 --- a/src/background/actions/tab.js +++ b/src/background/actions/tab.js @@ -1,19 +1,20 @@ import actions from './index'; -const openNewTab = (url, openerTabId, background = false, adjacent = false) => { - if (adjacent) { - return browser.tabs.query({ - active: true, currentWindow: true - }).then((tabs) => { - return browser.tabs.create({ - url, - openerTabId, - active: !background, - index: tabs[0].index + 1 - }); - }); +const openNewTab = async( + url, openerTabId, background = false, adjacent = false +) => { + if (!adjacent) { + return browser.tabs.create({ url, active: !background }); } - return browser.tabs.create({ url, active: !background }); + let tabs = await browser.tabs.query({ + active: true, currentWindow: true + }); + return browser.tabs.create({ + url, + openerTabId, + active: !background, + index: tabs[0].index + 1 + }); }; const openToTab = (url, tab) => { -- cgit v1.2.3