feat: add splash window theming (#52)

Co-authored-by: V <vendicated@riseup.net>
This commit is contained in:
Ryan Cao
2023-10-14 11:04:44 +08:00
committed by GitHub
parent 0d93e08e99
commit 841cdcf672
6 changed files with 82 additions and 3 deletions

View File

@@ -0,0 +1,46 @@
/*
* SPDX-License-Identifier: GPL-3.0
* Vesktop, a desktop app aiming to give you a snappier Discord Experience
* Copyright (c) 2023 Vendicated and Vencord contributors
*/
import { Settings } from "./settings";
function isValidColor(color: CSSStyleValue | undefined): color is CSSUnparsedValue & { [0]: string } {
return color instanceof CSSUnparsedValue && typeof color[0] === "string" && CSS.supports("color", color[0]);
}
function resolveColor(color: string) {
const span = document.createElement("span");
span.style.color = color;
span.style.display = "none";
document.body.append(span);
const rgbColor = getComputedStyle(span).color;
span.remove();
return rgbColor;
}
const updateSplashColors = () => {
const bodyStyles = document.body.computedStyleMap();
const color = bodyStyles.get("--text-normal");
const backgroundColor = bodyStyles.get("--background-primary");
if (isValidColor(color)) {
Settings.store.splashColor = resolveColor(color[0]);
}
if (isValidColor(backgroundColor)) {
Settings.store.splashBackground = resolveColor(backgroundColor[0]);
}
};
if (document.readyState === "complete") {
updateSplashColors();
} else {
window.addEventListener("load", updateSplashColors);
}
window.addEventListener("beforeunload", updateSplashColors);