Skip to content

Commit

Permalink
Discard tabs in the background
Browse files Browse the repository at this point in the history
  • Loading branch information
mastef committed Sep 22, 2024
1 parent 7374bf6 commit 89b2fed
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
12 changes: 3 additions & 9 deletions lib/TabManager.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -654,18 +654,12 @@ class TabManager extends React.Component {
browser.tabs.remove(tabId);
}
async discardTabs() {
var _this2 = this;
var tabs = Object.keys(this.state.selection).map(function(id) {
return parseInt(id);
return _this2.state.tabsbyid[id];
});
if (tabs.length) {
for (var i = 0; i < tabs.length; i++) {
if(!this.state.tabsbyid[tabs[i]].discarded) {
browser.tabs.discard(tabs[i]).catch(function(e) {
console.error(e);
console.log(e.message);
});
}
}
browser.runtime.sendMessage({command: "discard_tabs", tabs: tabs});
}
this.clearSelection();
}
Expand Down
14 changes: 14 additions & 0 deletions lib/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ browser.runtime.onStartup.addListener(
}
);

async function discardTabs(tabs) {
for (var i = 0; i < tabs.length; i++) {
if (!tabs[i].discarded) {
browser.tabs.discard(tabs[i].id).catch(function (e) {
console.error(e);
console.log(e.message);
});
}
}
}

async function moveTabsToWindow(windowId, tabs) {
for (var i = 0; i < tabs.length; i++) {
var t = tabs[i];
Expand Down Expand Up @@ -723,6 +734,9 @@ browser.runtime.onMessage.addListener(function(request, sender, sendResponse) {
case "update_tab_count":
updateTabCount();
break;
case "discard_tabs":
discardTabs(request.tabs);
break;
case "move_tabs_to_window":
moveTabsToWindow(request.window_id, request.tabs);
break;
Expand Down

0 comments on commit 89b2fed

Please sign in to comment.