address feedback
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
/* global MAC_CONSTANTS */
|
||||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
/* 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,
|
* 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/. */
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
@@ -11,33 +12,35 @@ const backgroundLogic = {
|
|||||||
"about:home",
|
"about:home",
|
||||||
"about:blank"
|
"about:blank"
|
||||||
]),
|
]),
|
||||||
NUMBER_OF_KEYBOARD_SHORTCUTS: 10,
|
// Use shared constants for counts
|
||||||
|
// NOTE: Keep in sync with MAC_CONSTANTS.NUMBER_OF_KEYBOARD_SHORTCUTS
|
||||||
unhideQueue: [],
|
unhideQueue: [],
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
browser.commands.onCommand.addListener(async function (command) {
|
browser.commands.onCommand.addListener(async function (command) {
|
||||||
if (command === "sort_tabs") {
|
if (command === "sort_tabs") {
|
||||||
backgroundLogic.sortTabs();
|
backgroundLogic.sortTabs();
|
||||||
return;
|
} 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;
|
||||||
for (let i=0; i < backgroundLogic.NUMBER_OF_KEYBOARD_SHORTCUTS; i++) {
|
|
||||||
const key = "open_container_" + i;
|
|
||||||
const reopenKey = "reopen_in_container_" + i;
|
|
||||||
const cookieStoreId = identityState.keyboardShortcut[key];
|
const cookieStoreId = identityState.keyboardShortcut[key];
|
||||||
|
|
||||||
if (cookieStoreId === "none") {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (command === key) {
|
if (command === key) {
|
||||||
|
if (cookieStoreId !== "none") {
|
||||||
browser.tabs.create({cookieStoreId});
|
browser.tabs.create({cookieStoreId});
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
if (command === reopenKey) {
|
}
|
||||||
|
}
|
||||||
|
} 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);
|
backgroundLogic.reopenInContainer(cookieStoreId);
|
||||||
return;
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -81,7 +84,7 @@ const backgroundLogic = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
async reopenInContainer(cookieStoreId) {
|
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) {
|
if (currentTab.length > 0) {
|
||||||
const tab = currentTab[0];
|
const tab = currentTab[0];
|
||||||
@@ -112,14 +115,14 @@ const backgroundLogic = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
updateTranslationInManifest() {
|
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.
|
const adjustedIndex = index + 1; // We want to start from 1 instead of 0 in the UI.
|
||||||
browser.commands.update({
|
browser.commands.update({
|
||||||
name: `open_container_${index}`,
|
name: `${MAC_CONSTANTS.OPEN_CONTAINER_PREFIX}${index}`,
|
||||||
description: browser.i18n.getMessage("containerShortcut", `${adjustedIndex}`)
|
description: browser.i18n.getMessage("containerShortcut", `${adjustedIndex}`)
|
||||||
});
|
});
|
||||||
browser.commands.update({
|
browser.commands.update({
|
||||||
name: `reopen_in_container_${index}`,
|
name: `${MAC_CONSTANTS.REOPEN_IN_CONTAINER_PREFIX}${index}`,
|
||||||
description: browser.i18n.getMessage("reopenInContainerShortcut", `${adjustedIndex}`)
|
description: browser.i18n.getMessage("reopenInContainerShortcut", `${adjustedIndex}`)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -324,8 +327,7 @@ const backgroundLogic = {
|
|||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// As we get a blank tab here we will need to await the tabs creation
|
// 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;
|
hiddenDefaultTabToClose = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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,
|
||||||
|
};
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
/* global MAC_CONSTANTS */
|
||||||
window.identityState = {
|
window.identityState = {
|
||||||
keyboardShortcut: {},
|
keyboardShortcut: {},
|
||||||
storageArea: {
|
storageArea: {
|
||||||
@@ -50,18 +51,23 @@ window.identityState = {
|
|||||||
|
|
||||||
async loadKeyboardShortcuts () {
|
async loadKeyboardShortcuts () {
|
||||||
const identities = await browser.contextualIdentities.query({});
|
const identities = await browser.contextualIdentities.query({});
|
||||||
for (let i=0; i < backgroundLogic.NUMBER_OF_KEYBOARD_SHORTCUTS; i++) {
|
for (let i=0; i < MAC_CONSTANTS.NUMBER_OF_KEYBOARD_SHORTCUTS; i++) {
|
||||||
const key = "open_container_" + i;
|
const openKey = MAC_CONSTANTS.OPEN_CONTAINER_PREFIX + i;
|
||||||
const storageObject = await this.area.get(key);
|
const reopenKey = MAC_CONSTANTS.REOPEN_IN_CONTAINER_PREFIX + i;
|
||||||
if (storageObject[key]){
|
const storageObject = await this.area.get(openKey);
|
||||||
identityState.keyboardShortcut[key] = storageObject[key];
|
|
||||||
|
if (storageObject[openKey]){
|
||||||
|
identityState.keyboardShortcut[openKey] = storageObject[openKey];
|
||||||
|
identityState.keyboardShortcut[reopenKey] = storageObject[openKey];
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (identities[i]) {
|
if (identities[i]) {
|
||||||
identityState.keyboardShortcut[key] = identities[i].cookieStoreId;
|
identityState.keyboardShortcut[openKey] = identities[i].cookieStoreId;
|
||||||
|
identityState.keyboardShortcut[reopenKey] = identities[i].cookieStoreId;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
identityState.keyboardShortcut[key] = "none";
|
identityState.keyboardShortcut[openKey] = "none";
|
||||||
|
identityState.keyboardShortcut[reopenKey] = "none";
|
||||||
}
|
}
|
||||||
return identityState.keyboardShortcut;
|
return identityState.keyboardShortcut;
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
-->
|
-->
|
||||||
<script type="text/javascript" src="../utils.js"></script>
|
<script type="text/javascript" src="../utils.js"></script>
|
||||||
<script type="text/javascript" src="../proxified-containers.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="backgroundLogic.js"></script>
|
||||||
<script type="text/javascript" src="mozillaVpnBackground.js"></script>
|
<script type="text/javascript" src="mozillaVpnBackground.js"></script>
|
||||||
<script type="text/javascript" src="assignManager.js"></script>
|
<script type="text/javascript" src="assignManager.js"></script>
|
||||||
|
|||||||
@@ -111,63 +111,33 @@
|
|||||||
"description": "__MSG_containerShortcut__"
|
"description": "__MSG_containerShortcut__"
|
||||||
},
|
},
|
||||||
"reopen_in_container_0": {
|
"reopen_in_container_0": {
|
||||||
"suggested_key": {
|
|
||||||
"default": "Alt+Shift+1"
|
|
||||||
},
|
|
||||||
"description": "__MSG_reopenInContainerShortcut__"
|
"description": "__MSG_reopenInContainerShortcut__"
|
||||||
},
|
},
|
||||||
"reopen_in_container_1": {
|
"reopen_in_container_1": {
|
||||||
"suggested_key": {
|
|
||||||
"default": "Alt+Shift+2"
|
|
||||||
},
|
|
||||||
"description": "__MSG_reopenInContainerShortcut__"
|
"description": "__MSG_reopenInContainerShortcut__"
|
||||||
},
|
},
|
||||||
"reopen_in_container_2": {
|
"reopen_in_container_2": {
|
||||||
"suggested_key": {
|
|
||||||
"default": "Alt+Shift+3"
|
|
||||||
},
|
|
||||||
"description": "__MSG_reopenInContainerShortcut__"
|
"description": "__MSG_reopenInContainerShortcut__"
|
||||||
},
|
},
|
||||||
"reopen_in_container_3": {
|
"reopen_in_container_3": {
|
||||||
"suggested_key": {
|
|
||||||
"default": "Alt+Shift+4"
|
|
||||||
},
|
|
||||||
"description": "__MSG_reopenInContainerShortcut__"
|
"description": "__MSG_reopenInContainerShortcut__"
|
||||||
},
|
},
|
||||||
"reopen_in_container_4": {
|
"reopen_in_container_4": {
|
||||||
"suggested_key": {
|
|
||||||
"default": "Alt+Shift+5"
|
|
||||||
},
|
|
||||||
"description": "__MSG_reopenInContainerShortcut__"
|
"description": "__MSG_reopenInContainerShortcut__"
|
||||||
},
|
},
|
||||||
"reopen_in_container_5": {
|
"reopen_in_container_5": {
|
||||||
"suggested_key": {
|
|
||||||
"default": "Alt+Shift+6"
|
|
||||||
},
|
|
||||||
"description": "__MSG_reopenInContainerShortcut__"
|
"description": "__MSG_reopenInContainerShortcut__"
|
||||||
},
|
},
|
||||||
"reopen_in_container_6": {
|
"reopen_in_container_6": {
|
||||||
"suggested_key": {
|
|
||||||
"default": "Alt+Shift+7"
|
|
||||||
},
|
|
||||||
"description": "__MSG_reopenInContainerShortcut__"
|
"description": "__MSG_reopenInContainerShortcut__"
|
||||||
},
|
},
|
||||||
"reopen_in_container_7": {
|
"reopen_in_container_7": {
|
||||||
"suggested_key": {
|
|
||||||
"default": "Alt+Shift+8"
|
|
||||||
},
|
|
||||||
"description": "__MSG_reopenInContainerShortcut__"
|
"description": "__MSG_reopenInContainerShortcut__"
|
||||||
},
|
},
|
||||||
"reopen_in_container_8": {
|
"reopen_in_container_8": {
|
||||||
"suggested_key": {
|
|
||||||
"default": "Alt+Shift+9"
|
|
||||||
},
|
|
||||||
"description": "__MSG_reopenInContainerShortcut__"
|
"description": "__MSG_reopenInContainerShortcut__"
|
||||||
},
|
},
|
||||||
"reopen_in_container_9": {
|
"reopen_in_container_9": {
|
||||||
"suggested_key": {
|
|
||||||
"default": "Alt+Shift+0"
|
|
||||||
},
|
|
||||||
"description": "__MSG_reopenInContainerShortcut__"
|
"description": "__MSG_reopenInContainerShortcut__"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user