inline and simplify closeTab()

This commit is contained in:
tophf 2017-11-24 18:39:15 +03:00
parent 978e5ca9f0
commit 59d32e6f2f

View File

@ -347,7 +347,11 @@ function onRuntimeMessage(request, sender, sendResponseInternal) {
return KEEP_CHANNEL_OPEN;
case 'closeTab':
closeTab(sender.tab.id, request).then(sendResponse);
chrome.tabs.remove(request.tabId || sender.tab.id, () => {
if (chrome.runtime.lastError) {
sendResponse(new Error(chrome.runtime.lastError.message));
}
});
return KEEP_CHANNEL_OPEN;
case 'openEditor':
@ -355,23 +359,3 @@ function onRuntimeMessage(request, sender, sendResponseInternal) {
return;
}
}
function closeTab(tabId, request) {
return new Promise(resolve => {
if (request.tabId) {
tabId = request.tabId;
}
chrome.tabs.remove(tabId, () => {
const {lastError} = chrome.runtime;
if (lastError) {
resolve({
success: false,
error: lastError.message || String(lastError)
});
return;
}
resolve({success: true});
});
});
}