diff --git a/src/config.ts b/src/config.ts index 01f6f1c3..2a62e1d9 100644 --- a/src/config.ts +++ b/src/config.ts @@ -297,6 +297,9 @@ const DEFAULTS = o({ // If enabled, tabopen opens a new tab in the currently active tab's container. tabopencontaineraware: "false", + // If moodeindicator is enabled, containerindicator will color the border of the mode indicator with the container color. + containerindicator: "true", + // Performance related settings // number of most recent results to ask Firefox for. We display the top 20 or so most frequently visited ones. diff --git a/src/content.ts b/src/content.ts index 46872bdd..bbfa457c 100644 --- a/src/content.ts +++ b/src/content.ts @@ -83,6 +83,9 @@ if ( config.getAsync("modeindicator").then(mode => { if (mode !== "true") return + // Do we want container indicators? + let containerIndicator = config.get("containerindicator") + // Hide indicator in print mode // CSS not explicitly added to the dom doesn't make it to print mode: // https://bugzilla.mozilla.org/show_bug.cgi?id=1448507 @@ -100,6 +103,22 @@ config.getAsync("modeindicator").then(mode => { : "" statusIndicator.className = "cleanslate TridactylStatusIndicator " + privateMode + + // Dynamically sets the border container color. + if (containerIndicator === "true") { + webext + .activeTabContainer() + .then(container => { + statusIndicator.setAttribute( + "style", + `border: ${container.colorCode} solid 1.5px !important`, + ) + }) + .catch(error => { + logger.debug(error) + }) + } + // This listener makes the modeindicator disappear when the mouse goes over it statusIndicator.addEventListener("mouseenter", ev => { let target = ev.target as any diff --git a/src/lib/containers.ts b/src/lib/containers.ts index 7b2d01ec..6fe3397c 100644 --- a/src/lib/containers.ts +++ b/src/lib/containers.ts @@ -92,10 +92,7 @@ export async function update( icon: browser.contextualIdentities.IdentityIcon }, ) { - if ( - isValidColor(updateObj["color"]) && - isValidIcon(updateObj["icon"]) - ) { + if (isValidColor(updateObj["color"]) && isValidIcon(updateObj["icon"])) { try { browser.contextualIdentities.update(containerId, updateObj) } catch (e) { @@ -114,12 +111,7 @@ export async function getFromId(containerId: string): Promise<{}> { try { return await browser.contextualIdentities.get(containerId) } catch (e) { - logger.debug( - `[Container.getFromId] could not find a container with id: ${containerId}`, - ) - throw new Error( - "[Container.getFromId] could not find a container with that id", - ) + throw e } } diff --git a/src/lib/webext.ts b/src/lib/webext.ts index c28ce2ad..f8567355 100644 --- a/src/lib/webext.ts +++ b/src/lib/webext.ts @@ -72,6 +72,12 @@ export async function activeTabContainerId() { return (await activeTab()).cookieStoreId } +//#background_helper +export async function activeTabContainer() { + let containerId = await activeTabContainerId() + return await browserBg.contextualIdentities.get(containerId) +} + /** Compare major firefox versions */ export async function firefoxVersionAtLeast(desiredmajor: number) { const versionstr = (await browserBg.runtime.getBrowserInfo()).version