🐛 remove alpha channel from VS Code colors

This commit is contained in:
Nate Sesti 2024-01-11 16:24:58 -08:00
parent 3cf4583a4a
commit ec5dea275f
2 changed files with 24 additions and 11 deletions

View file

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

View file

@ -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<any>) {
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)
);
}
}
}
}, []);