Skip to content

Added unsort tabs functionality #2731

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 10 additions & 18 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 29 additions & 5 deletions src/js/background/backgroundLogic.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

const DEFAULT_TAB = "about:newtab";

// let originalTabs = [];

const backgroundLogic = {
NEW_TAB_PAGES: new Set([
"about:startpage",
Expand Down Expand Up @@ -330,11 +332,33 @@ const backgroundLogic = {
},

async sortTabs() {
const windows = await browser.windows.getAll();
for (let windowObj of windows) { // eslint-disable-line prefer-const
// First the pinned tabs, then the normal ones.
await this._sortTabsInternal(windowObj, true);
await this._sortTabsInternal(windowObj, false);
const windowObj = await browser.windows.getCurrent();
const tabs = await browser.tabs.query({windowId: windowObj.id});
for (const tab of tabs){
if(!(windowObj.id in ORIGINAL_TABS)){
ORIGINAL_TABS[windowObj.id] = [];
}
ORIGINAL_TABS[windowObj.id].push(tab.id);
}
let jsonarray = JSON.stringify(ORIGINAL_TABS);
localStorage.setItem("originalTabs", jsonarray);

// First the pinned tabs, then the normal ones.
await this._sortTabsInternal(windowObj, true);
await this._sortTabsInternal(windowObj, false);

},

async _unsortTabsInternal(windowObj){
let pos = 0;
let parsedOriginalTabs = JSON.parse(localStorage.getItem("originalTabs"));
let windowSpecificOriginalTabs = parsedOriginalTabs[windowObj.id];
for (const tab of windowSpecificOriginalTabs) {
++pos;
browser.tabs.move(tab, {
windowId: windowObj.id,
index: pos
});
}
},

Expand Down
3 changes: 3 additions & 0 deletions src/js/background/messageHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ const messageHandler = {
case "sortTabs":
backgroundLogic.sortTabs();
break;
case "unsortTabs":
backgroundLogic.unsortTabs();
break;
case "showTabs":
backgroundLogic.unhideContainer(m.cookieStoreId);
break;
Expand Down
21 changes: 21 additions & 0 deletions src/js/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,17 @@ Logic.registerPanel(P_CONTAINERS_LIST, {
window.close();
}
});
Utils.addEnterHandler(document.querySelector("#unsort-containers-link"), async () => {
try {
await browser.runtime.sendMessage({
method: "unsortTabs"
});
window.close();
} catch (e) {
window.close();
}

});

const mozillaVpnToutName = "moz-tout-main-panel";
const mozillaVpnPermissionsWarningDotName = "moz-permissions-warning-dot";
Expand Down Expand Up @@ -911,6 +922,16 @@ Logic.registerPanel(P_CONTAINERS_LIST, {
document.addEventListener("input", Logic.filterContainerList);

MozillaVPN.handleContainerList(identities);
// document.querySelector("#unsort-containers-link").setAttribute("disabled", "true");
if (localStorage.getItem("originalTabs") == null){
document.querySelector("#unsort-containers-link").setAttribute("disabled", "true");
}

else {
document.querySelector("#unsort-containers-link").removeAttribute("disabled");
}

// console.log(localStorage.getItem("originalTabs"));

// reset path
this._previousPanelPath = [];
Expand Down
1 change: 1 addition & 0 deletions src/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const DEFAULT_FAVICON = "/img/blank-favicon.svg";

// eslint-disable-next-line
const CONTAINER_ORDER_STORAGE_KEY = "container-order";
const ORIGINAL_TABS = {};

// TODO use export here instead of globals
const Utils = {
Expand Down
9 changes: 9 additions & 0 deletions src/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,15 @@ <h3 class="title">Firefox Multi-Account Containers</h3>
</span>
</td>
</tr>
<tr class="menu-item hover-highlight keyboard-nav" id="unsort-containers-link" tabindex="0">
<td>
<img class="menu-icon" alt="" src="/img/sort-16_1.svg" />
<span class="menu-text" data-i18n-message-id="unsortTabsByContainer"></span>
<span class="menu-arrow">
</span>
</td>

</tr>
<tr class="menu-item hover-highlight keyboard-nav" id="always-open-in" tabindex="0">
<td>
<img class="menu-icon" alt="" src="/img/container-openin-16.svg" />
Expand Down