inline and simplify closeTab()
This commit is contained in:
parent
978e5ca9f0
commit
59d32e6f2f
|
@ -347,7 +347,11 @@ function onRuntimeMessage(request, sender, sendResponseInternal) {
|
||||||
return KEEP_CHANNEL_OPEN;
|
return KEEP_CHANNEL_OPEN;
|
||||||
|
|
||||||
case 'closeTab':
|
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;
|
return KEEP_CHANNEL_OPEN;
|
||||||
|
|
||||||
case 'openEditor':
|
case 'openEditor':
|
||||||
|
@ -355,23 +359,3 @@ function onRuntimeMessage(request, sender, sendResponseInternal) {
|
||||||
return;
|
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});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user