From 2c2e8ed6025e81ad280e1459ef42fde055adf09a Mon Sep 17 00:00:00 2001 From: baku Date: Fri, 6 Jan 2017 20:05:33 +0100 Subject: [PATCH] Cleaning up existing methods --- index.js | 76 ++-------------------------------------- webextension/js/popup.js | 4 +-- 2 files changed, 5 insertions(+), 75 deletions(-) diff --git a/index.js b/index.js index 2e95af0..6f71099 100644 --- a/index.js +++ b/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; diff --git a/webextension/js/popup.js b/webextension/js/popup.js index 8440d7d..0e74484 100644 --- a/webextension/js/popup.js +++ b/webextension/js/popup.js @@ -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=> {