Skip to content

Commit

Permalink
feat: add splash window theming
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanccn committed Jul 12, 2023
1 parent 72f83c3 commit 1f6d8b7
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 5 deletions.
21 changes: 17 additions & 4 deletions src/main/mainWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@
* Copyright (c) 2023 Vendicated and Vencord contributors
*/

import { app, BrowserWindow, BrowserWindowConstructorOptions, Menu, MenuItemConstructorOptions, Tray } from "electron";
import {
app,
BrowserWindow,
BrowserWindowConstructorOptions,
Menu,
MenuItemConstructorOptions,
nativeTheme,
Tray
} from "electron";
import { join } from "path";
import { IpcEvents } from "shared/IpcEvents";
import { isTruthy } from "shared/utils/guards";
Expand Down Expand Up @@ -274,17 +282,22 @@ function createMainWindow() {
},
icon: ICON_PATH,
frame: VencordSettings.store.frameless !== true,
...(Settings.store.transparencyOption !== "none"
...(Settings.store.transparencyOption && Settings.store.transparencyOption !== "none"
? {
backgroundColor: "#00000000",
backgroundMaterial: Settings.store.transparencyOption,
transparent: true
}
: {
backgroundColor: Settings.store.splashTheming
? Settings.store.splashBackground
: nativeTheme.shouldUseDarkColors
? "#313338"
: "#ffffff",
transparent: false
}),
...(Settings.store.staticTitle ? { title: "Vencord" } : {}),
...(VencordSettings.store.macosTranslucency
...((VencordSettings.store.macosTranslucency as boolean)
? {
vibrancy: "sidebar",
backgroundColor: "#ffffff00"
Expand Down Expand Up @@ -332,7 +345,7 @@ function createMainWindow() {
const runVencordMain = once(() => require(join(VENCORD_FILES_DIR, "vencordDesktopMain.js")));

export async function createWindows() {
const splash = createSplashWindow();
const splash = await createSplashWindow();

await ensureVencordFiles();
runVencordMain();
Expand Down
11 changes: 10 additions & 1 deletion src/main/splash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,19 @@ import { join } from "path";
import { SplashProps } from "shared/browserWinProperties";
import { VIEW_DIR } from "shared/paths";

export function createSplashWindow() {
import { Settings } from "./settings";

export async function createSplashWindow() {
const splash = new BrowserWindow(SplashProps);

splash.loadFile(join(VIEW_DIR, "splash.html"));

if (Settings.store.splashTheming) {
if (Settings.store.splashColor)
splash.webContents.insertCSS(`body { --fg: ${Settings.store.splashColor} !important }`);
if (Settings.store.splashBackground)
splash.webContents.insertCSS(`body { --bg: ${Settings.store.splashBackground} !important }`);
}

return splash;
}
1 change: 1 addition & 0 deletions src/renderer/components/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export default function SettingsUi() {
"Disable minimum window size",
"Allows you to make the window as small as your heart desires"
],
["splashTheming", "Splash theming", "Adapt the splash window colors to your custom theme", false],
[
"openLinksWithElectron",
"Open Links in app (experimental)",
Expand Down
1 change: 1 addition & 0 deletions src/renderer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import "./fixes";
import "./appBadge";
import "./patches";
import "./themedSplash";

console.log("read if cute :3");

Expand Down
26 changes: 26 additions & 0 deletions src/renderer/themedSplash.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* SPDX-License-Identifier: GPL-3.0
* Vencord Desktop, a desktop app aiming to give you a snappier Discord Experience
* Copyright (c) 2023 Vendicated and Vencord contributors
*/

import { Settings } from "./settings";

window.addEventListener("load", () => {
const bodyStyles = document.body.computedStyleMap();

Check failure on line 10 in src/renderer/themedSplash.ts

View workflow job for this annotation

GitHub Actions / test

Property 'computedStyleMap' does not exist on type 'HTMLElement'.

const color = bodyStyles.get("--text-normal");
const backgroundColor = bodyStyles.get("--background-primary");

if (color instanceof CSSUnparsedValue && typeof color[0] === "string" && CSS.supports("color", color[0])) {

Check failure on line 15 in src/renderer/themedSplash.ts

View workflow job for this annotation

GitHub Actions / test

Cannot find name 'CSSUnparsedValue'.
Settings.store.splashColor = color[0];
}

if (
backgroundColor instanceof CSSUnparsedValue &&

Check failure on line 20 in src/renderer/themedSplash.ts

View workflow job for this annotation

GitHub Actions / test

Cannot find name 'CSSUnparsedValue'.
typeof backgroundColor[0] === "string" &&
CSS.supports("background-color", backgroundColor[0])
) {
Settings.store.splashBackground = backgroundColor[0];
}
});
4 changes: 4 additions & 0 deletions src/shared/settings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,8 @@ export interface Settings {
appBadge?: boolean;

firstLaunch?: boolean;

splashTheming?: boolean;
splashColor?: string;
splashBackground?: string;
}

0 comments on commit 1f6d8b7

Please sign in to comment.