Skip to content

Commit

Permalink
horror
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanccn committed Jul 15, 2023
1 parent da0c28a commit ee39440
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 13 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
"watch": "pnpm build --watch"
},
"dependencies": {
"arrpc": "github:OpenAsar/arrpc#061d473dc742266fc7f61587ed18e666543fed1e",
"tinycolor2": "^1.6.0"
"arrpc": "github:OpenAsar/arrpc#061d473dc742266fc7f61587ed18e666543fed1e"
},
"devDependencies": {
"@fal-works/esbuild-plugin-global-externals": "^2.1.2",
Expand Down
7 changes: 0 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions src/main/splash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import { BrowserWindow } from "electron";
import { join } from "path";
import { SplashProps } from "shared/browserWinProperties";
import { VIEW_DIR } from "shared/paths";
import tinycolor from "tinycolor2";

import { Settings } from "./settings";
import { alpha } from "./utils/color";

export function createSplashWindow() {
const splash = new BrowserWindow(SplashProps);
Expand All @@ -21,9 +21,7 @@ export function createSplashWindow() {
if (splashTheming) {
if (splashColor) {
splash.webContents.insertCSS(`body { --fg: ${splashColor} !important }`);
const semiTrans = tinycolor(splashColor);
semiTrans.setAlpha(0.2);
splash.webContents.insertCSS(`body { --fg-semi-trans: ${semiTrans.toRgbString()} !important }`);
splash.webContents.insertCSS(`body { --fg-semi-trans: ${alpha(splashColor, 0.2)} !important }`);
}

if (splashBackground) {
Expand Down
42 changes: 42 additions & 0 deletions src/main/utils/color.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* 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
*/

const digitRegex = "([\\d.%]+)";
const validFormats = ["rgb", "hsl", "hwb", "lab", "lch", "oklab", "oklch"] as const;

const colorRegexes = [
...validFormats.map(fmt => new RegExp(`(${fmt})\\(${new Array(3).fill(digitRegex).join(" *, *")}\\)`)),
...validFormats.map(fmt => new RegExp(`(${fmt})a\\(${new Array(4).fill(digitRegex).join(" *, *")}\\)`)),
...validFormats.map(fmt => new RegExp(`(${fmt})\\(${new Array(3).fill(digitRegex).join(" +")}\\)`)),
...validFormats.map(
fmt => new RegExp(`(${fmt})a\\(${new Array(3).fill(digitRegex).join(" +")} ?/ ?${digitRegex}\\)`)
)
];

const hexRegex = /^#([\da-fA-F]{6})$/;
const hexAlphaRegex = /^#([\da-fA-F]{6})[\da-fA-F]{2}$/;

export const alpha = (original: string, alpha: number): string => {
for (const regex of colorRegexes) {
const match = original.match(regex);
if (match) {
const [, format, a, b, c] = match;
return `${format}a(${a} ${b} ${c} / ${alpha})`;
}
}

for (const regex of [hexRegex, hexAlphaRegex]) {
const match = original.match(regex);
if (match) {
const [, str] = match;
return `#${str}${Math.round(alpha * 255)
.toString(16)
.padStart(2, "0")}`;
}
}

return original;
};

0 comments on commit ee39440

Please sign in to comment.