Skip to content

Commit 11b257d

Browse files
authored
Simplify app transparency and background color handling (#1331)
1 parent d41d96c commit 11b257d

3 files changed

Lines changed: 13 additions & 10 deletions

File tree

frontend/app/app.less

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ body {
1212
color: var(--main-text-color);
1313
font: var(--base-font);
1414
overflow: hidden;
15-
background: var(--main-bg-color);
15+
background: rgb(from var(--main-bg-color) r g b / var(--window-opacity));
1616
-webkit-font-smoothing: auto;
1717
backface-visibility: hidden;
1818
transform: translateZ(0);

frontend/app/app.tsx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import { getElemAsStr } from "@/util/focusutil";
1717
import * as keyutil from "@/util/keyutil";
1818
import * as util from "@/util/util";
1919
import clsx from "clsx";
20-
import Color from "color";
2120
import debug from "debug";
2221
import { Provider, useAtomValue } from "jotai";
2322
import "overlayscrollbars/overlayscrollbars.css";
@@ -130,21 +129,24 @@ function AppSettingsUpdater() {
130129
const isTransparentOrBlur =
131130
(windowSettings?.["window:transparent"] || windowSettings?.["window:blur"]) ?? false;
132131
const opacity = util.boundNumber(windowSettings?.["window:opacity"] ?? 0.8, 0, 1);
133-
let baseBgColor = windowSettings?.["window:bgcolor"];
132+
const baseBgColor = windowSettings?.["window:bgcolor"];
134133
const mainDiv = document.getElementById("main");
135134
// console.log("window settings", windowSettings, isTransparentOrBlur, opacity, baseBgColor, mainDiv);
136135
if (isTransparentOrBlur) {
137136
mainDiv.classList.add("is-transparent");
138-
const rootStyles = getComputedStyle(document.documentElement);
139-
if (baseBgColor == null) {
140-
baseBgColor = rootStyles.getPropertyValue("--main-bg-color").trim();
137+
if (opacity != null) {
138+
document.body.style.setProperty("--window-opacity", `${opacity}`);
139+
} else {
140+
document.body.style.removeProperty("--window-opacity");
141141
}
142-
const color = new Color(baseBgColor);
143-
const rgbaColor = color.alpha(opacity).string();
144-
document.body.style.backgroundColor = rgbaColor;
145142
} else {
146143
mainDiv.classList.remove("is-transparent");
147-
document.body.style.backgroundColor = "var(--main-bg-color)";
144+
document.body.style.removeProperty("--window-opacity");
145+
}
146+
if (baseBgColor != null) {
147+
document.body.style.setProperty("--main-bg-color", baseBgColor);
148+
} else {
149+
document.body.style.removeProperty("--main-bg-color");
148150
}
149151
}, [windowSettings]);
150152
return null;

frontend/app/theme.less

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
:root {
88
--main-text-color: #f7f7f7;
99
--title-font-size: 18px;
10+
--window-opacity: 1;
1011
--secondary-text-color: rgb(195, 200, 194);
1112
--grey-text-color: #666;
1213
--main-bg-color: rgb(34, 34, 34);

0 commit comments

Comments
 (0)