simplify tabs.onAttached

This commit is contained in:
tophf 2017-08-27 17:36:20 +03:00
parent 58f966be98
commit ec95e8e7b4

View File

@ -481,21 +481,24 @@ getOwnTab().then(tab => {
useHistoryBack = sessionStorageHash('manageStylesHistory').value[ownTabId] === location.href; useHistoryBack = sessionStorageHash('manageStylesHistory').value[ownTabId] === location.href;
// When an edit page gets attached or detached, remember its state // When an edit page gets attached or detached, remember its state
// so we can do the same to the next one to open. // so we can do the same to the next one to open.
chrome.tabs.onAttached.addListener(tabId => { chrome.tabs.onAttached.addListener((tabId, info) => {
if (tabId === ownTabId) { if (tabId !== ownTabId) {
chrome.tabs.get(tabId, tab => { return;
chrome.windows.get(tab.windowId, {populate: true}, win => { }
if (info.newPosition !== 0) {
prefs.set('openEditInWindow', false);
return;
}
chrome.windows.get(info.newWindowId, {populate: true}, win => {
// If there's only one tab in this window, it's been dragged to new window // If there's only one tab in this window, it's been dragged to new window
const openEditInWindow = win.tabs.length === 1; const openEditInWindow = win.tabs.length === 1;
if (openEditInWindow && FIREFOX) { if (openEditInWindow && FIREFOX) {
// FF-only because Chrome retardedly resets the size during dragging // FF-only because Chrome retardedly resets the size during dragging
chrome.windows.update(tab.windowId, prefs.get('windowPosition')); chrome.windows.update(info.newWindowId, prefs.get('windowPosition'));
} }
prefs.set('openEditInWindow', openEditInWindow); prefs.set('openEditInWindow', openEditInWindow);
}); });
}); });
}
});
}); });
function goBackToManage(event) { function goBackToManage(event) {