Improve settings default handling

This commit is contained in:
Vendicated
2026-08-24 14:40:50 +02:00
parent 09ce424b30
commit fd7ada3cd8
14 changed files with 123 additions and 78 deletions
+1 -1
View File
@@ -40,7 +40,7 @@ function init() {
app.commandLine.removeSwitch("enable-features");
app.commandLine.removeSwitch("disable-features");
if (hardwareAcceleration === false || process.argv.includes("--disable-gpu")) {
if (!hardwareAcceleration || process.argv.includes("--disable-gpu")) {
enableHardwareAcceleration = false;
app.disableHardwareAcceleration();
} else {
+7 -8
View File
@@ -344,12 +344,11 @@ function buildBrowserWindowOptions(): BrowserWindowConstructorOptions {
const { transparent, macosVibrancyStyle } = VencordSettings.store;
const frameless = nativeTitleBar !== true;
const backgroundColor =
splashTheming !== false ? splashBackground : nativeTheme.shouldUseDarkColors ? "#313338" : "#ffffff";
const frameless = !nativeTitleBar;
const backgroundColor = splashTheming ? splashBackground : nativeTheme.shouldUseDarkColors ? "#313338" : "#ffffff";
const options: BrowserWindowConstructorOptions = {
show: Settings.store.enableSplashScreen === false && !CommandLine.values["start-minimized"],
show: !Settings.store.enableSplashScreen && !CommandLine.values["start-minimized"],
backgroundColor,
webPreferences: {
nodeIntegration: false,
@@ -363,8 +362,8 @@ function buildBrowserWindowOptions(): BrowserWindowConstructorOptions {
},
frame: !frameless,
autoHideMenuBar: enableMenu,
hasShadow: enableShadow !== false,
roundedCorners: enableRoundedCorners !== false,
hasShadow: enableShadow,
roundedCorners: enableRoundedCorners,
...getWindowBoundsOptions()
};
@@ -410,7 +409,7 @@ function createMainWindow() {
if (process.platform === "darwin" && Settings.store.nativeTitleBar) win.setWindowButtonVisibility(false);
win.on("close", e => {
const useTray = !isDeckGameMode && Settings.store.minimizeToTray !== false && Settings.store.tray !== false;
const useTray = !isDeckGameMode && Settings.store.minimizeToTray && Settings.store.tray;
if (isQuitting || (process.platform !== "darwin" && !useTray)) return;
e.preventDefault();
@@ -470,7 +469,7 @@ export async function createWindows() {
const startMinimized = CommandLine.values["start-minimized"];
let splash: BrowserWindow | undefined;
if (Settings.store.enableSplashScreen !== false) {
if (Settings.store.enableSplashScreen) {
splash = createSplashWindow(startMinimized);
// SteamOS letterboxes and scales it terribly, so just full screen it
+8 -2
View File
@@ -7,15 +7,17 @@
import { type Settings as TVencordSettings } from "@vencord/types/Vencord";
import { mkdirSync, readFileSync, writeFileSync } from "fs";
import { dirname, join } from "path";
import { DefaultVesktopSettings } from "shared/defaultSettings";
import type { Settings as TSettings, State as TState } from "shared/settings";
import { SettingsStore } from "shared/utils/SettingsStore";
import { DATA_DIR, VENCORD_SETTINGS_FILE } from "./constants";
import { mergeDefaults } from "./utils/mergeDefaults";
const SETTINGS_FILE = join(DATA_DIR, "settings.json");
const STATE_FILE = join(DATA_DIR, "state.json");
function loadSettings<T extends object = any>(file: string, name: string) {
function loadSettings<T extends object = any>(file: string, name: string, defaults?: T) {
let settings = {} as T;
try {
const content = readFileSync(file, "utf8");
@@ -26,6 +28,10 @@ function loadSettings<T extends object = any>(file: string, name: string) {
}
} catch {}
if (defaults) {
mergeDefaults(settings, defaults);
}
const store = new SettingsStore(settings);
store.addGlobalChangeListener(o => {
try {
@@ -39,6 +45,6 @@ function loadSettings<T extends object = any>(file: string, name: string) {
return store;
}
export const Settings = loadSettings<TSettings>(SETTINGS_FILE, "Vesktop settings");
export const Settings = loadSettings<TSettings>(SETTINGS_FILE, "Vesktop settings", DefaultVesktopSettings);
export const VencordSettings = loadSettings<TVencordSettings>(VENCORD_SETTINGS_FILE, "Vencord settings");
export const State = loadSettings<TState>(STATE_FILE, "Vesktop state");
+1 -1
View File
@@ -26,7 +26,7 @@ export function createSplashWindow(startMinimized = false) {
const { splashBackground, splashColor, splashTheming, splashPixelated } = Settings.store;
if (splashTheming !== false) {
if (splashTheming) {
if (splashColor) {
const semiTransparentSplashColor = splashColor.replace("rgb(", "rgba(").replace(")", ", 0.2)");
+24
View File
@@ -0,0 +1,24 @@
/*
* Vesktop, a desktop app aiming to give you a snappier Discord Experience
* Copyright (c) 2026 Vendicated and Vesktop contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/
/**
* Recursively merges defaults into an object and returns the same object
* @param obj Object
* @param defaults Defaults
* @returns obj
*/
export function mergeDefaults<T>(obj: T, defaults: T): T {
for (const key in defaults) {
const v = defaults[key];
if (typeof v === "object" && !Array.isArray(v)) {
obj[key] ??= {} as any;
mergeDefaults(obj[key], v);
} else {
obj[key] ??= v;
}
}
return obj;
}