From 4df51a9790b6b5545f9ce43e4c2c0209758cec7f Mon Sep 17 00:00:00 2001 From: joey Date: Wed, 1 Apr 2020 14:34:01 -0400 Subject: [PATCH] added comments --- src/js/background/backgroundLogic.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/js/background/backgroundLogic.js b/src/js/background/backgroundLogic.js index 67b8350..de9f402 100644 --- a/src/js/background/backgroundLogic.js +++ b/src/js/background/backgroundLogic.js @@ -240,6 +240,8 @@ const backgroundLogic = { async sortTabsByWindow() { let windows = await browser.windows.getAll(); let containers = new Set(); + + // loop through each tab to find all active containers for (const windowObj of windows) { const tabs = await browser.tabs.query({windowId: windowObj.id}); for (const tab of tabs) { @@ -248,10 +250,16 @@ const backgroundLogic = { } containers = Array.from(containers); + // for each container, move all related tabs to its window for (let i = 0; i < containers.length; i++) { + // if no window is available, then pass -1 const windowId = (i < windows.length) ? windows[i].id : -1; await this._sortTabsByWindowInternal(windowId, containers[i]); } + + // Logically, there shouldn't be any redundant windows + // but, maybe other addons/features conflicts, so double check to + // delete redundant windows here. windows = await browser.windows.getAll(); for (let i = containers.length; i < windows.length; i++) { await browser.windows.remove(windows[i].id);