Skip to content

Commit

Permalink
Fixed bug #274. Switching from popup menu to main window was firing a…
Browse files Browse the repository at this point in the history
… window changed event, causing the newly focussed tab to unsuspend.
  • Loading branch information
deanoemcke committed Nov 11, 2015
1 parent e29e25a commit 0ba20dc
Showing 1 changed file with 25 additions and 11 deletions.
36 changes: 25 additions & 11 deletions src/js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,26 @@ var tgs = (function () {
}*/
}

function handleWindowFocusChanged(windowId) {

if (debug) {
console.log('window changed: ' + windowId);
}

chrome.tabs.query({active: true, windowId: windowId}, function(tabs) {
if (tabs && tabs.length === 1) {

lastSelectedTabs[windowId] = tabs[0].id;
globalCurrentTabId = tabs[0].id;

//update icon
requestTabInfo(tabs[0].id, function (info) {
updateIcon(info.status);
});
}
});
}

function handleTabFocusChanged(tabId, windowId) {

if (debug) {
Expand All @@ -368,6 +388,10 @@ var tgs = (function () {
resetTabTimer(lastSelectedTab);
}

//update icon
requestTabInfo(tabId, function (info) {
updateIcon(info.status);
});

//pause for a bit before assuming we're on a new tab as some users
//will key through intermediate tabs to get to the one they want.
Expand All @@ -384,11 +408,6 @@ var tgs = (function () {
function handleNewTabFocus(tabId) {
var unsuspend = gsUtils.getOption(gsUtils.UNSUSPEND_ON_FOCUS);

//update icon
requestTabInfo(tabId, function (info) {
updateIcon(info.status);
});

//if pref is set, then unsuspend newly focused tab
if (unsuspend) {
//get tab object so we can check if it is a special or suspended tab
Expand Down Expand Up @@ -963,12 +982,7 @@ var tgs = (function () {

// listen for focus changes
chrome.windows.onFocusChanged.addListener(function (windowId) {

chrome.tabs.query({active: true, windowId: windowId}, function(tabs) {
if (tabs && tabs.length === 1) {
handleTabFocusChanged(tabs[0].id, tabs[0].windowId);
}
});
handleWindowFocusChanged(windowId);
});
chrome.tabs.onActivated.addListener(function (activeInfo) {
handleTabFocusChanged(activeInfo.tabId, activeInfo.windowId);
Expand Down

0 comments on commit 0ba20dc

Please sign in to comment.