Rename functions/variables according to naming scheme, remove TODO, simplify

This commit is contained in:
tunefish 2018-03-16 19:42:13 +01:00
parent 628e85b81d
commit c58c981141
2 changed files with 13 additions and 19 deletions

View file

@ -1,5 +1,5 @@
const assignManager = { const assignManager = {
MENU_REOPEN_IN: "reopen-in-container", MENU_RELOAD_IN: "reopen-in-container",
MENU_ASSIGN_ID: "open-in-this-container", MENU_ASSIGN_ID: "open-in-this-container",
MENU_REMOVE_ID: "remove-open-in-this-container", MENU_REMOVE_ID: "remove-open-in-this-container",
MENU_SEPARATOR_ID: "separator", MENU_SEPARATOR_ID: "separator",
@ -181,7 +181,7 @@ const assignManager = {
}, },
async _onClickedHandler(info, tab) { async _onClickedHandler(info, tab) {
const reopenCookieStoreId = this.menuId2cookieStoreId(info.menuItemId); const reopenCookieStoreId = this.getReloadMenuIdFromCookieStoreId(info.menuItemId);
if (reopenCookieStoreId) { if (reopenCookieStoreId) {
const newTab = await browser.tabs.create({ const newTab = await browser.tabs.create({
@ -238,11 +238,11 @@ const assignManager = {
return backgroundLogic.getUserContextIdFromCookieStoreId(tab.cookieStoreId); return backgroundLogic.getUserContextIdFromCookieStoreId(tab.cookieStoreId);
}, },
cookieStoreId2menuId(cookieStoreId) { getCookieStoreIdFromReloadMenuId(cookieStoreId) {
return "reopen-in-" + cookieStoreId; return "reopen-in-" + cookieStoreId;
}, },
menuId2cookieStoreId(contextMenuId) { getReloadMenuIdFromCookieStoreId(contextMenuId) {
if (contextMenuId.startsWith("reopen-in-")) if (contextMenuId.startsWith("reopen-in-"))
return contextMenuId.substring(10); return contextMenuId.substring(10);
return false; return false;
@ -320,41 +320,35 @@ const assignManager = {
// We also can't change for always private mode // We also can't change for always private mode
// See: https://bugzilla.mozilla.org/show_bug.cgi?id=1352102 // See: https://bugzilla.mozilla.org/show_bug.cgi?id=1352102
browser.contextMenus.remove(this.MENU_ASSIGN_ID); browser.contextMenus.remove(this.MENU_ASSIGN_ID);
browser.contextualIdentities.query({}).then((identities) => { browser.contextMenus.remove(this.MENU_RELOAD_IN);
identities.forEach((identity) => {
this.removeContainerMenuEntry(identity);
});
}).catch(() => {});
browser.contextMenus.remove(this.MENU_REOPEN_IN);
browser.contextMenus.remove(this.MENU_REMOVE_ID); browser.contextMenus.remove(this.MENU_REMOVE_ID);
browser.contextMenus.remove(this.MENU_SEPARATOR_ID); browser.contextMenus.remove(this.MENU_SEPARATOR_ID);
browser.contextMenus.remove(this.MENU_HIDE_ID); browser.contextMenus.remove(this.MENU_HIDE_ID);
browser.contextMenus.remove(this.MENU_MOVE_ID); browser.contextMenus.remove(this.MENU_MOVE_ID);
}, },
addContainerMenuEntry(contextualIdentity, contexts) { addReloadMenuEntry(contextualIdentity, contexts) {
browser.contextMenus.create({ browser.contextMenus.create({
id: this.cookieStoreId2menuId(contextualIdentity.cookieStoreId), id: this.getCookieStoreIdFromReloadMenuId(contextualIdentity.cookieStoreId),
title: contextualIdentity.name, title: contextualIdentity.name,
// TODO: colorized icons? // TODO: colorized icons?
icons: { icons: {
"16": contextualIdentity.iconUrl "16": contextualIdentity.iconUrl
}, },
// TODO: hide entry for current container in context menu of tabs
contexts: contexts, contexts: contexts,
parentId: this.MENU_REOPEN_IN, parentId: this.MENU_RELOAD_IN,
}); });
}, },
removeContainerMenuEntry(contextualIdentity) { removeReloadMenuEntry(contextualIdentity) {
browser.contextMenus.remove(this.cookieStoreId2menuId(contextualIdentity.cookieStoreId)); browser.contextMenus.remove(this.getCookieStoreIdFromReloadMenuId(contextualIdentity.cookieStoreId));
}, },
async calculateContextMenu(tab) { async calculateContextMenu(tab) {
this.removeContextMenu(); this.removeContextMenu();
browser.contextMenus.create({ browser.contextMenus.create({
id: this.MENU_REOPEN_IN, id: this.MENU_RELOAD_IN,
title: "Reopen in container", title: "Reopen in container",
contexts: ["all", "tab"], contexts: ["all", "tab"],
}); });

View file

@ -78,13 +78,13 @@ const messageHandler = {
const userContextId = backgroundLogic.getUserContextIdFromCookieStoreId(contextualIdentity.cookieStoreId); const userContextId = backgroundLogic.getUserContextIdFromCookieStoreId(contextualIdentity.cookieStoreId);
backgroundLogic.deleteContainer(userContextId, true); backgroundLogic.deleteContainer(userContextId, true);
assignManager.removeContainerMenuEntry(contextualIdentity); assignManager.removeReloadMenuEntry(contextualIdentity);
}); });
} }
if (browser.contextualIdentities.onCreated) { if (browser.contextualIdentities.onCreated) {
browser.contextualIdentities.onCreated.addListener(({contextualIdentity}) => { browser.contextualIdentities.onCreated.addListener(({contextualIdentity}) => {
assignManager.addContainerMenuEntry(contextualIdentity, ["all", "tab"]); assignManager.addReloadMenuEntry(contextualIdentity, ["all", "tab"]);
}); });
} }