From ec5dea275f497bdb3f349f897af84240725345b6 Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Thu, 11 Jan 2024 16:24:58 -0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20remove=20alpha=20channel=20from?= =?UTF-8?q?=20VS=20Code=20colors?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gui/src/components/index.ts | 17 ++++++++++++++--- gui/src/hooks/useSetup.ts | 18 ++++++++++-------- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/gui/src/components/index.ts b/gui/src/components/index.ts index d6935e682..93de7238e 100644 --- a/gui/src/components/index.ts +++ b/gui/src/components/index.ts @@ -1,6 +1,7 @@ import { Tooltip } from "react-tooltip"; import styled, { keyframes } from "styled-components"; import { getFontSize } from "../util"; +import { isJetBrains } from "../util/ide"; export const VSC_SECONDARY_DARK_VAR = "--vscode-input-background"; export const VSC_BACKGROUND_VAR = "--vscode-sideBar-background"; @@ -30,9 +31,19 @@ export const vscEditorBackground = `var(${VSC_EDITOR_BACKGROUND_VAR}, ${VSC_BACK if (typeof document !== "undefined") { for (const colorVar of VSC_THEME_COLOR_VARS) { - const cached = localStorage.getItem(colorVar); - if (cached) { - document.body.style.setProperty(colorVar, cached); + if (isJetBrains()) { + const cached = localStorage.getItem(colorVar); + if (cached) { + document.body.style.setProperty(colorVar, cached); + } + } + + // Remove alpha channel from colors + const value = getComputedStyle(document.documentElement).getPropertyValue( + colorVar + ); + if (colorVar.startsWith("#") && value.length > 7) { + document.body.style.setProperty(colorVar, value.slice(0, 7)); } } } diff --git a/gui/src/hooks/useSetup.ts b/gui/src/hooks/useSetup.ts index 133a07a65..831444b56 100644 --- a/gui/src/hooks/useSetup.ts +++ b/gui/src/hooks/useSetup.ts @@ -1,7 +1,7 @@ import { Dispatch } from "@reduxjs/toolkit"; import { useEffect } from "react"; import { setServerStatusMessage } from "../redux/slices/miscSlice"; -import { errorPopup, postToIde } from "../util/ide"; +import { errorPopup, isJetBrains, postToIde } from "../util/ide"; import { intermediateToFinalConfig, @@ -116,14 +116,16 @@ function useSetup(dispatch: Dispatch) { return () => window.removeEventListener("message", eventListener); }, [defaultModelTitle]); - // Save theme colors to local storage + // Save theme colors to local storage for immediate loading in JetBrains useEffect(() => { - for (const colorVar of VSC_THEME_COLOR_VARS) { - if (document.body.style.getPropertyValue(colorVar)) { - localStorage.setItem( - colorVar, - document.body.style.getPropertyValue(colorVar) - ); + if (isJetBrains()) { + for (const colorVar of VSC_THEME_COLOR_VARS) { + if (document.body.style.getPropertyValue(colorVar)) { + localStorage.setItem( + colorVar, + document.body.style.getPropertyValue(colorVar) + ); + } } } }, []);