Added container color to the mode indicator. This functionality is hidden behind a config setting "containerindicator".

Related function 'activeTabContainer' was added to 'src/lib/webext.ts'.
Minor changes to getFromId error handling in 'src/lib/containers.ts'.
This commit is contained in:
Anton Vilhelm Ásgeirsson 2018-06-16 09:22:52 +00:00
parent dace4fb378
commit 01307ddc2c
4 changed files with 30 additions and 10 deletions

View file

@ -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.

View file

@ -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

View file

@ -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
}
}

View file

@ -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