address feedback

This commit is contained in:
Anton Dudakov
2025-10-01 18:45:59 +04:00
parent 37a2b67224
commit eda79aaf05
5 changed files with 60 additions and 75 deletions
+24 -22
View File
@@ -1,3 +1,4 @@
/* global MAC_CONSTANTS */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
@@ -11,33 +12,35 @@ const backgroundLogic = {
"about:home",
"about:blank"
]),
NUMBER_OF_KEYBOARD_SHORTCUTS: 10,
// Use shared constants for counts
// NOTE: Keep in sync with MAC_CONSTANTS.NUMBER_OF_KEYBOARD_SHORTCUTS
unhideQueue: [],
init() {
browser.commands.onCommand.addListener(async function (command) {
if (command === "sort_tabs") {
backgroundLogic.sortTabs();
return;
}
for (let i=0; i < backgroundLogic.NUMBER_OF_KEYBOARD_SHORTCUTS; i++) {
const key = "open_container_" + i;
const reopenKey = "reopen_in_container_" + i;
} else if (command.startsWith(MAC_CONSTANTS.OPEN_CONTAINER_PREFIX)) {
for (let i = 0; i < MAC_CONSTANTS.NUMBER_OF_KEYBOARD_SHORTCUTS; i++) {
const key = MAC_CONSTANTS.OPEN_CONTAINER_PREFIX + i;
const cookieStoreId = identityState.keyboardShortcut[key];
if (cookieStoreId === "none") {
continue;
}
if (command === key) {
if (cookieStoreId !== "none") {
browser.tabs.create({cookieStoreId});
return;
}
if (command === reopenKey) {
break;
}
}
} else if (command.startsWith(MAC_CONSTANTS.REOPEN_IN_CONTAINER_PREFIX)) {
for (let i = 0; i < MAC_CONSTANTS.NUMBER_OF_KEYBOARD_SHORTCUTS; i++) {
const key = MAC_CONSTANTS.REOPEN_IN_CONTAINER_PREFIX + i;
const cookieStoreId = identityState.keyboardShortcut[key];
if (command === key) {
if (cookieStoreId !== "none") {
backgroundLogic.reopenInContainer(cookieStoreId);
return;
}
break;
}
}
}
});
@@ -81,7 +84,7 @@ const backgroundLogic = {
},
async reopenInContainer(cookieStoreId) {
const currentTab = await browser.tabs.query({ active: true, currentWindow: true })
const currentTab = await browser.tabs.query({active: true, currentWindow: true});
if (currentTab.length > 0) {
const tab = currentTab[0];
@@ -112,14 +115,14 @@ const backgroundLogic = {
},
updateTranslationInManifest() {
for (let index = 0; index < 10; index++) {
for (let index = 0; index < MAC_CONSTANTS.NUMBER_OF_KEYBOARD_SHORTCUTS; index++) {
const adjustedIndex = index + 1; // We want to start from 1 instead of 0 in the UI.
browser.commands.update({
name: `open_container_${index}`,
name: `${MAC_CONSTANTS.OPEN_CONTAINER_PREFIX}${index}`,
description: browser.i18n.getMessage("containerShortcut", `${adjustedIndex}`)
});
browser.commands.update({
name: `reopen_in_container_${index}`,
name: `${MAC_CONSTANTS.REOPEN_IN_CONTAINER_PREFIX}${index}`,
description: browser.i18n.getMessage("reopenInContainerShortcut", `${adjustedIndex}`)
});
}
@@ -324,8 +327,7 @@ const backgroundLogic = {
});
} else {
// As we get a blank tab here we will need to await the tabs creation
newWindowObj = await browser.windows.create({
});
newWindowObj = await browser.windows.create({});
hiddenDefaultTabToClose = true;
}
+6
View File
@@ -0,0 +1,6 @@
// Shared constants for background scripts
window.MAC_CONSTANTS = {
OPEN_CONTAINER_PREFIX: "open_container_",
REOPEN_IN_CONTAINER_PREFIX: "reopen_in_container_",
NUMBER_OF_KEYBOARD_SHORTCUTS: 10,
};
+13 -7
View File
@@ -1,3 +1,4 @@
/* global MAC_CONSTANTS */
window.identityState = {
keyboardShortcut: {},
storageArea: {
@@ -50,18 +51,23 @@ window.identityState = {
async loadKeyboardShortcuts () {
const identities = await browser.contextualIdentities.query({});
for (let i=0; i < backgroundLogic.NUMBER_OF_KEYBOARD_SHORTCUTS; i++) {
const key = "open_container_" + i;
const storageObject = await this.area.get(key);
if (storageObject[key]){
identityState.keyboardShortcut[key] = storageObject[key];
for (let i=0; i < MAC_CONSTANTS.NUMBER_OF_KEYBOARD_SHORTCUTS; i++) {
const openKey = MAC_CONSTANTS.OPEN_CONTAINER_PREFIX + i;
const reopenKey = MAC_CONSTANTS.REOPEN_IN_CONTAINER_PREFIX + i;
const storageObject = await this.area.get(openKey);
if (storageObject[openKey]){
identityState.keyboardShortcut[openKey] = storageObject[openKey];
identityState.keyboardShortcut[reopenKey] = storageObject[openKey];
continue;
}
if (identities[i]) {
identityState.keyboardShortcut[key] = identities[i].cookieStoreId;
identityState.keyboardShortcut[openKey] = identities[i].cookieStoreId;
identityState.keyboardShortcut[reopenKey] = identities[i].cookieStoreId;
continue;
}
identityState.keyboardShortcut[key] = "none";
identityState.keyboardShortcut[openKey] = "none";
identityState.keyboardShortcut[reopenKey] = "none";
}
return identityState.keyboardShortcut;
},
+1
View File
@@ -15,6 +15,7 @@
-->
<script type="text/javascript" src="../utils.js"></script>
<script type="text/javascript" src="../proxified-containers.js"></script>
<script type="text/javascript" src="constants.js"></script>
<script type="text/javascript" src="backgroundLogic.js"></script>
<script type="text/javascript" src="mozillaVpnBackground.js"></script>
<script type="text/javascript" src="assignManager.js"></script>
-30
View File
@@ -111,63 +111,33 @@
"description": "__MSG_containerShortcut__"
},
"reopen_in_container_0": {
"suggested_key": {
"default": "Alt+Shift+1"
},
"description": "__MSG_reopenInContainerShortcut__"
},
"reopen_in_container_1": {
"suggested_key": {
"default": "Alt+Shift+2"
},
"description": "__MSG_reopenInContainerShortcut__"
},
"reopen_in_container_2": {
"suggested_key": {
"default": "Alt+Shift+3"
},
"description": "__MSG_reopenInContainerShortcut__"
},
"reopen_in_container_3": {
"suggested_key": {
"default": "Alt+Shift+4"
},
"description": "__MSG_reopenInContainerShortcut__"
},
"reopen_in_container_4": {
"suggested_key": {
"default": "Alt+Shift+5"
},
"description": "__MSG_reopenInContainerShortcut__"
},
"reopen_in_container_5": {
"suggested_key": {
"default": "Alt+Shift+6"
},
"description": "__MSG_reopenInContainerShortcut__"
},
"reopen_in_container_6": {
"suggested_key": {
"default": "Alt+Shift+7"
},
"description": "__MSG_reopenInContainerShortcut__"
},
"reopen_in_container_7": {
"suggested_key": {
"default": "Alt+Shift+8"
},
"description": "__MSG_reopenInContainerShortcut__"
},
"reopen_in_container_8": {
"suggested_key": {
"default": "Alt+Shift+9"
},
"description": "__MSG_reopenInContainerShortcut__"
},
"reopen_in_container_9": {
"suggested_key": {
"default": "Alt+Shift+0"
},
"description": "__MSG_reopenInContainerShortcut__"
}
},