Cleaning up existing methods
This commit is contained in:
parent
a6f9175224
commit
2c2e8ed602
2 changed files with 5 additions and 75 deletions
76
index.js
76
index.js
|
@ -41,16 +41,6 @@ function convert(identity) {
|
|||
return result;
|
||||
}
|
||||
|
||||
function getContainer(userContextId) {
|
||||
if (!userContextId) {
|
||||
return Promise.resolve(null);
|
||||
}
|
||||
|
||||
const identity = ContextualIdentityService.getIdentityFromId(userContextId);
|
||||
|
||||
return Promise.resolve(convert(identity));
|
||||
}
|
||||
|
||||
function queryContainers(details) {
|
||||
const identities = [];
|
||||
|
||||
|
@ -71,46 +61,6 @@ function queryContainers(details) {
|
|||
return Promise.resolve(identities);
|
||||
}
|
||||
|
||||
function createContainer(details) {
|
||||
const identity = ContextualIdentityService.create(details.name,
|
||||
details.icon,
|
||||
details.color);
|
||||
|
||||
return Promise.resolve(convert(identity));
|
||||
}
|
||||
|
||||
function updateContainer(userContextId, details) {
|
||||
if (!userContextId) {
|
||||
return Promise.resolve(null);
|
||||
}
|
||||
|
||||
const identity = ContextualIdentityService.getIdentityFromId(userContextId);
|
||||
|
||||
if (!identity) {
|
||||
return Promise.resolve(null);
|
||||
}
|
||||
|
||||
if (details.name !== null) {
|
||||
identity.name = details.name;
|
||||
}
|
||||
|
||||
if (details.color !== null) {
|
||||
identity.color = details.color;
|
||||
}
|
||||
|
||||
if (details.icon !== null) {
|
||||
identity.icon = details.icon;
|
||||
}
|
||||
|
||||
if (!ContextualIdentityService.update(identity.userContextId,
|
||||
identity.name, identity.icon,
|
||||
identity.color)) {
|
||||
return Promise.resolve(null);
|
||||
}
|
||||
|
||||
return Promise.resolve(convert(identity));
|
||||
}
|
||||
|
||||
function removeContainer(userContextId) {
|
||||
if (!userContextId) {
|
||||
return Promise.resolve(null);
|
||||
|
@ -132,14 +82,6 @@ function removeContainer(userContextId) {
|
|||
return Promise.resolve(convertedIdentity);
|
||||
}
|
||||
|
||||
const contextualIdentities = {
|
||||
get: getContainer,
|
||||
query: queryContainers,
|
||||
create: createContainer,
|
||||
update: updateContainer,
|
||||
remove: removeContainer
|
||||
};
|
||||
|
||||
function openTab(args) {
|
||||
let browserWin = Services.wm.getMostRecentWindow('navigator:browser');
|
||||
|
||||
|
@ -195,15 +137,15 @@ function removeTabs(ids) {
|
|||
function handleWebExtensionMessage(message, sender, sendReply) {
|
||||
switch (message.method) {
|
||||
case 'queryIdentities':
|
||||
sendReply(contextualIdentities.query(message.arguments));
|
||||
sendReply(queryContainers(message.arguments));
|
||||
break;
|
||||
case 'queryTabs':
|
||||
sendReply(queryTabs(message));
|
||||
break;
|
||||
case 'hideTab':
|
||||
case 'hideTabs':
|
||||
identitiesState[message.userContextId].hiddenTabUrls = message.tabUrlsToSave;
|
||||
break;
|
||||
case 'showTab':
|
||||
case 'showTabs':
|
||||
sendReply(identitiesState[message.userContextId].hiddenTabUrls);
|
||||
identitiesState[message.userContextId].hiddenTabUrls = [];
|
||||
break;
|
||||
|
@ -211,18 +153,6 @@ function handleWebExtensionMessage(message, sender, sendReply) {
|
|||
sendReply(removeTabs(message.tabIds));
|
||||
identitiesState[message.userContextId].hiddenTabUrls = [];
|
||||
break;
|
||||
case 'getTab':
|
||||
sendReply(contextualIdentities.get(message.arguments));
|
||||
break;
|
||||
case 'createTab':
|
||||
sendReply(contextualIdentities.create(message.arguments));
|
||||
break;
|
||||
case 'updateTab':
|
||||
sendReply(contextualIdentities.update(message.arguments));
|
||||
break;
|
||||
case 'removeTab':
|
||||
sendReply(contextualIdentities.remove(message.arguments));
|
||||
break;
|
||||
case 'getIdentitiesState':
|
||||
sendReply(identitiesState);
|
||||
break;
|
||||
|
|
|
@ -16,7 +16,7 @@ function hideContainerTabs(userContextId) {
|
|||
tabUrlsToSave.push(tab.url);
|
||||
});
|
||||
browser.runtime.sendMessage({
|
||||
method: 'hideTab',
|
||||
method: 'hideTabs',
|
||||
userContextId: userContextId,
|
||||
tabUrlsToSave: tabUrlsToSave
|
||||
}).then(()=> {
|
||||
|
@ -33,7 +33,7 @@ function showContainerTabs(userContextId) {
|
|||
const hideorshowIcon = document.querySelector(`#uci-${userContextId}-hideorshow-icon`);
|
||||
|
||||
browser.runtime.sendMessage({
|
||||
method: 'showTab',
|
||||
method: 'showTabs',
|
||||
userContextId: userContextId
|
||||
}).then(hiddenTabUrls=> {
|
||||
hiddenTabUrls.forEach(url=> {
|
||||
|
|
Loading…
Add table
Reference in a new issue