Update context menu when a container is created/deleted
This commit is contained in:
parent
2a6775ab12
commit
396c96efc9
2 changed files with 29 additions and 13 deletions
|
@ -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);
|
||||
|
|
|
@ -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"])
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue