Skip to content

Commit

Permalink
some wishful thinking code that may help to prevent tab loss when uni…
Browse files Browse the repository at this point in the history
…nstalling the extension (#40)
  • Loading branch information
deanoemcke committed Nov 13, 2015
1 parent 0069e39 commit 7e276b8
Showing 1 changed file with 31 additions and 14 deletions.
45 changes: 31 additions & 14 deletions src/js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,15 @@ var tgs = (function () {
});
}


function suspendAllTabsInAllWindows() {
chrome.tabs.query({}, function (tabs) {
tabs.forEach(function (currentTab) {
requestTabSuspension(currentTab, true);
});
});
}

function isSuspended(tab) {
return tab.url.indexOf('suspended.html') >= 0;
}
Expand All @@ -292,6 +301,14 @@ var tgs = (function () {
});
}

function unsuspendAllTabsInAllWindows() {
chrome.tabs.query({}, function (tabs) {
tabs.forEach(function (currentTab) {
if (isSuspended(currentTab)) unsuspendTab(currentTab);
});
});
}

function suspendSelectedTabs() {
chrome.tabs.query({highlighted: true, lastFocusedWindow: true}, function (selectedTabs) {
selectedTabs.forEach(function (tab) {
Expand Down Expand Up @@ -878,18 +895,10 @@ var tgs = (function () {
unsuspendAllTabs();

} else if (command === '5-suspend-all-windows') {
chrome.tabs.query({}, function (tabs) {
tabs.forEach(function (currentTab) {
requestTabSuspension(currentTab, true);
});
});
suspendAllTabsInAllWindows();

} else if (command === '6-unsuspend-all-windows') {
chrome.tabs.query({}, function (tabs) {
tabs.forEach(function (currentTab) {
if (isSuspended(currentTab)) unsuspendTab(currentTab);
});
});
unsuspendAllTabsInAllWindows();
}
});

Expand Down Expand Up @@ -998,13 +1007,21 @@ var tgs = (function () {
}


// attach listener to runtime
//attach listener to runtime
chrome.runtime.onMessage.addListener(messageRequestListener);
// attach listener to runtime for external messages, to allow
// interoperability with other extensions in the manner of an API
//attach listener to runtime for external messages, to allow
//interoperability with other extensions in the manner of an API
chrome.runtime.onMessageExternal.addListener(messageRequestListener);

// listen for focus changes
//wishful thinking here that a synchronus iteration through tab views will enable them
//to unsuspend before the application closes
chrome.runtime.onSuspend.addListener(function () {
chrome.extension.getViews({type: 'tab'}).forEach(function (view) {
view.location.reload();
});
});

//listen for focus changes
chrome.windows.onFocusChanged.addListener(function (windowId) {
handleWindowFocusChanged(windowId);
});
Expand Down

0 comments on commit 7e276b8

Please sign in to comment.