Skip to content

Commit 81ee998

Browse files
Anton Dudakovantondudakov
authored andcommitted
extracted reopenInContainer function which made it possible to remove
async from the `init()`
1 parent 6a2c50a commit 81ee998

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

src/js/background/backgroundLogic.js

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const backgroundLogic = {
1414
NUMBER_OF_KEYBOARD_SHORTCUTS: 10,
1515
unhideQueue: [],
1616

17-
async init() {
17+
init() {
1818
browser.commands.onCommand.addListener(async function (command) {
1919
if (command === "sort_tabs") {
2020
backgroundLogic.sortTabs();
@@ -36,19 +36,7 @@ const backgroundLogic = {
3636
}
3737

3838
if (command === reopenKey) {
39-
const currentTab = await browser.tabs.query({active: true, currentWindow: true});
40-
if (currentTab.length > 0) {
41-
const tab = currentTab[0];
42-
43-
await browser.tabs.create({
44-
url: tab.url,
45-
cookieStoreId: cookieStoreId,
46-
index: tab.index + 1,
47-
active: tab.active
48-
});
49-
50-
await browser.tabs.remove(tab.id);
51-
}
39+
backgroundLogic.reopenInContainer(cookieStoreId);
5240
return;
5341
}
5442
}
@@ -88,12 +76,27 @@ const backgroundLogic = {
8876
browser.commands.reset("sort_tabs");
8977
}
9078
}
79+
80+
async reopenInContainer(cookieStoreId) {
81+
const currentTab = await browser.tabs.query({ active: true, currentWindow: true })
82+
83+
if (currentTab.length > 0) {
84+
const tab = currentTab[0];
85+
86+
browser.tabs.create({
87+
url: tab.url,
88+
cookieStoreId: cookieStoreId,
89+
index: tab.index + 1,
90+
active: tab.active
91+
});
92+
93+
browser.tabs.remove(tab.id);
9194
}
9295
},
9396

9497
updateTranslationInManifest() {
9598
for (let index = 0; index < 10; index++) {
96-
const adjustedIndex = index + 1;
99+
const adjustedIndex = index + 1; // We want to start from 1 instead of 0 in the UI.
97100
browser.commands.update({
98101
name: `open_container_${index}`,
99102
description: browser.i18n.getMessage("containerShortcut", `${adjustedIndex}`)

0 commit comments

Comments
 (0)