diff --git a/src/js/background/assignManager.js b/src/js/background/assignManager.js index 81c1ef8..ddf0985 100644 --- a/src/js/background/assignManager.js +++ b/src/js/background/assignManager.js @@ -325,7 +325,7 @@ const assignManager = { browser.contextMenus.remove(this.MENU_ASSIGN_ID); browser.contextualIdentities.query({}).then((identities) => { identities.forEach((identity) => { - browser.contextMenus.remove(this.cookieStoreId2menuId(identity.cookieStoreId)); + this.removeContainerMenuEntry(identity); }); }).catch(() => {}); browser.contextMenus.remove(this.MENU_REOPEN_IN); @@ -335,6 +335,24 @@ const assignManager = { browser.contextMenus.remove(this.MENU_MOVE_ID); }, + addContainerMenuEntry(contextualIdentity, contexts) { + browser.contextMenus.create({ + id: this.cookieStoreId2menuId(contextualIdentity.cookieStoreId), + title: contextualIdentity.name, + // TODO: colorized icons? + icons: { + "16": contextualIdentity.iconUrl + }, + // TODO: hide entry for current container in context menu of tabs + contexts: contexts, + parentId: this.MENU_REOPEN_IN, + }); + }, + + removeContainerMenuEntry(contextualIdentity) { + browser.contextMenus.remove(this.cookieStoreId2menuId(contextualIdentity.cookieStoreId)); + }, + async calculateContextMenu(tab) { this.removeContextMenu(); @@ -346,18 +364,8 @@ const assignManager = { const identities = await browser.contextualIdentities.query({}); identities.forEach((identity) => { - browser.contextMenus.create({ - id: this.cookieStoreId2menuId(identity.cookieStoreId), - title: identity.name, - // TODO: colorized icons? - icons: { - "16": identity.iconUrl - }, - // TODO: hide entry for current container in context menu of tabs - contexts: (identity.cookieStoreId !== tab.cookieStoreId) ? - ["all", "tab"] : ["tab"], - parentId: this.MENU_REOPEN_IN, - }); + this.addContainerMenuEntry(identity, (identity.cookieStoreId !== tab.cookieStoreId) ? + ["all", "tab"] : ["tab"]); }); const siteSettings = await this._getAssignment(tab); diff --git a/src/js/background/messageHandler.js b/src/js/background/messageHandler.js index 1971953..2e39510 100644 --- a/src/js/background/messageHandler.js +++ b/src/js/background/messageHandler.js @@ -76,6 +76,14 @@ const messageHandler = { browser.contextualIdentities.onRemoved.addListener(({contextualIdentity}) => { const userContextId = backgroundLogic.getUserContextIdFromCookieStoreId(contextualIdentity.cookieStoreId); backgroundLogic.deleteContainer(userContextId, true); + + assignManager.removeContainerMenuEntry(contextualIdentity); + }); + } + + if (browser.contextualIdentities.onCreated) { + browser.contextualIdentities.onCreated.addListener(({contextualIdentity}) => { + assignManager.addContainerMenuEntry(contextualIdentity, ["all", "tab"]) }); }