From 5c5cf02249f778a09902d3d535061700ccd7aee1 Mon Sep 17 00:00:00 2001 From: baku Date: Tue, 30 May 2017 19:10:27 +0200 Subject: [PATCH] Reset color and icon when disabled - issue #398 --- index.js | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/index.js b/index.js index 435e4fa..937dc61 100644 --- a/index.js +++ b/index.js @@ -42,6 +42,14 @@ const IDENTITY_ICONS = [ { name: "circle", image: "circle" }, ]; +const IDENTITY_COLORS_STANDARD = [ + "blue", "orange", "green", "pink", +]; + +const IDENTITY_ICONS_STANDARD = [ + "fingerprint", "briefcase", "dollar", "cart", +]; + const PREFS = [ [ "privacy.userContext.enabled", true ], [ "privacy.userContext.ui.enabled", false ], @@ -1407,6 +1415,8 @@ ContainerWindow.prototype = { this._shutdownFileMenu(); this._shutdownAllTabsMenu(); this._shutdownContextMenu(); + + this._shutdownContainers(); }, _shutDownPlusButtonMenuElement(buttonElement) { @@ -1473,6 +1483,36 @@ ContainerWindow.prototype = { return true; }, + + _shutdownContainers() { + ContextualIdentityProxy.getIdentities().forEach(identity => { + if (IDENTITY_ICONS_STANDARD.indexOf(identity.icon) !== -1 && + IDENTITY_COLORS_STANDARD.indexOf(identity.color) !== -1) { + return; + } + + if (IDENTITY_ICONS_STANDARD.indexOf(identity.icon) === -1) { + if (identity.userContextId <= IDENTITY_ICONS_STANDARD.length) { + identity.icon = IDENTITY_ICONS_STANDARD[identity.userContextId - 1]; + } else { + identity.icon = IDENTITY_ICONS_STANDARD[0]; + } + } + + if (IDENTITY_COLORS_STANDARD.indexOf(identity.color) === -1) { + if (identity.userContextId <= IDENTITY_COLORS_STANDARD.length) { + identity.color = IDENTITY_COLORS_STANDARD[identity.userContextId - 1]; + } else { + identity.color = IDENTITY_COLORS_STANDARD[0]; + } + } + + ContextualIdentityService.update(identity.userContextId, + identity.name, + identity.icon, + identity.color); + }); + } }; // uninstall/install events ---------------------------------------------------