From 0a480e2d89d73f7af9ac1b926b67ea1c828c98b3 Mon Sep 17 00:00:00 2001 From: aiek Date: Fri, 26 Jul 2024 19:13:34 +0300 Subject: [PATCH] Upload files to 'src/renderer' --- src/renderer/themedSplash.ts | 46 ++++++++++++++++++++++++++++++++++++ src/renderer/utils.ts | 20 ++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 src/renderer/themedSplash.ts create mode 100644 src/renderer/utils.ts diff --git a/src/renderer/themedSplash.ts b/src/renderer/themedSplash.ts new file mode 100644 index 0000000..8c76708 --- /dev/null +++ b/src/renderer/themedSplash.ts @@ -0,0 +1,46 @@ +/* + * SPDX-License-Identifier: GPL-3.0 + * Aerocord, a vesktop fork for older microsoft NT releases such as NT 6.0, 6.1, 6.2 and 6.3. + * Credits to vendicated and the rest of the vesktop contribuitors for making Vesktop! + */ + +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); diff --git a/src/renderer/utils.ts b/src/renderer/utils.ts new file mode 100644 index 0000000..70b9bcc --- /dev/null +++ b/src/renderer/utils.ts @@ -0,0 +1,20 @@ +/* + * SPDX-License-Identifier: GPL-3.0 + * Aerocord, a vesktop fork for older microsoft NT releases such as NT 6.0, 6.1, 6.2 and 6.3. + * Credits to vendicated and the rest of the vesktop contribuitors for making Vesktop! + */ + +export const { localStorage } = window; + +export const isFirstRun = (() => { + const key = "VCD_FIRST_RUN"; + if (localStorage.getItem(key) !== null) return false; + localStorage.setItem(key, "false"); + return true; +})(); + +const { platform } = navigator; + +export const isWindows = platform.startsWith("Win"); +export const isMac = platform.startsWith("Mac"); +export const isLinux = platform.startsWith("Linux");