From bba8899f672a1514940954b6fdaeaee3dc29a1f0 Mon Sep 17 00:00:00 2001 From: Vendicated Date: Sun, 9 Apr 2023 05:25:45 +0200 Subject: [PATCH] Implement frameless & windows ctrl q settings --- src/main/constants.ts | 3 ++- src/main/mainWindow.ts | 17 +++++++------ src/main/settings.ts | 38 ++++++++++++++++++---------- src/renderer/components/Settings.tsx | 4 +-- 4 files changed, 38 insertions(+), 24 deletions(-) diff --git a/src/main/constants.ts b/src/main/constants.ts index a08d364..0e3d688 100644 --- a/src/main/constants.ts +++ b/src/main/constants.ts @@ -4,11 +4,12 @@ import { join } from "path"; export const DATA_DIR = process.env.VENCORD_USER_DATA_DIR || join(app.getPath("userData"), "VencordDesktop"); // needs to be inline require because of circular dependency // as otherwise "DATA_DIR" (which is used by ./settings) will be uninitialised -export const VENCORD_FILES_DIR = require("./settings").Settings.vencordDir || join(DATA_DIR, "vencordDist"); export const VENCORD_SETTINGS_DIR = join(DATA_DIR, "settings"); export const VENCORD_QUICKCSS_FILE = join(VENCORD_SETTINGS_DIR, "quickCss.css"); export const VENCORD_SETTINGS_FILE = join(VENCORD_SETTINGS_DIR, "settings.json"); +export const VENCORD_FILES_DIR = require("./settings").Settings.vencordDir || join(DATA_DIR, "vencordDist"); + export const USER_AGENT = `VencordDesktop/${app.getVersion()} (https://github.com/Vencord/Electron)`; // dimensions shamelessly stolen from Discord Desktop :3 diff --git a/src/main/mainWindow.ts b/src/main/mainWindow.ts index 2036590..c2678a9 100644 --- a/src/main/mainWindow.ts +++ b/src/main/mainWindow.ts @@ -3,7 +3,7 @@ import { join } from "path"; import { ICON_PATH } from "../shared/paths"; import { createAboutWindow } from "./about"; import { DEFAULT_HEIGHT, DEFAULT_WIDTH, MIN_HEIGHT, MIN_WIDTH } from "./constants"; -import { Settings } from "./settings"; +import { Settings, VencordSettings } from "./settings"; import { makeLinksOpenExternally } from "./utils/makeLinksOpenExternally"; import { downloadVencordFiles } from "./utils/vencordLoader"; @@ -70,7 +70,9 @@ function initTray(win: BrowserWindow) { } function initMenuBar(win: BrowserWindow) { - console.log(process.platform); + const isWindows = process.platform === "win32"; + const wantCtrlQ = !isWindows || VencordSettings.winCtrlQ; + const menu = Menu.buildFromTemplate([ { label: "Vencord Desktop", @@ -120,18 +122,16 @@ function initMenuBar(win: BrowserWindow) { }, { label: "Quit", - accelerator: process.platform === "win32" ? void 0 : "CmdOrCtrl+Q", - // TODO: Setting - visible: process.platform !== "win32", + accelerator: wantCtrlQ ? "CmdOrCtrl+Q" : void 0, + visible: !isWindows, click() { app.quit(); } }, { label: "Quit", - accelerator: "Alt+F4", - visible: process.platform === "win32", - acceleratorWorksWhenHidden: false, + accelerator: isWindows ? "Alt+F4" : void 0, + visible: isWindows, click() { app.quit(); } @@ -217,6 +217,7 @@ export function createMainWindow() { preload: join(__dirname, "preload.js") }, icon: ICON_PATH, + frame: VencordSettings.frameless !== true, ...getWindowBoundsOptions() }); diff --git a/src/main/settings.ts b/src/main/settings.ts index 76a79d4..0bd6ade 100644 --- a/src/main/settings.ts +++ b/src/main/settings.ts @@ -2,30 +2,42 @@ import { readFileSync, writeFileSync } from "fs"; import { join } from "path"; import type { Settings as TSettings } from "shared/settings"; import { makeChangeListenerProxy } from "shared/utils/makeChangeListenerProxy"; -import { DATA_DIR } from "./constants"; +import { DATA_DIR, VENCORD_SETTINGS_FILE } from "./constants"; const SETTINGS_FILE = join(DATA_DIR, "settings.json"); -export let PlainSettings = {} as TSettings; -try { - const content = readFileSync(SETTINGS_FILE, "utf8"); +function loadSettings(file: string, name: string) { + let settings = {} as T; try { - PlainSettings = JSON.parse(content); - } catch (err) { - console.error("Failed to parse settings.json:", err); - } -} catch { } + const content = readFileSync(file, "utf8"); + try { + settings = JSON.parse(content); + } catch (err) { + console.error(`Failed to parse ${name} settings.json:`, err); + } + } catch { } -const makeSettingsProxy = (settings: TSettings) => makeChangeListenerProxy( - settings, - target => writeFileSync(SETTINGS_FILE, JSON.stringify(target, null, 4)) -); + const makeSettingsProxy = (settings: T) => makeChangeListenerProxy( + settings, + target => writeFileSync(file, JSON.stringify(target, null, 4)) + ); + return [settings, makeSettingsProxy] as const; +} + +let [PlainSettings, makeSettingsProxy] = loadSettings(SETTINGS_FILE, "VencordDesktop"); export let Settings = makeSettingsProxy(PlainSettings); +let [PlainVencordSettings, makeVencordSettingsProxy] = loadSettings(VENCORD_SETTINGS_FILE, "Vencord"); +export const VencordSettings = makeVencordSettingsProxy(PlainVencordSettings); + export function setSettings(settings: TSettings) { writeFileSync(SETTINGS_FILE, JSON.stringify(settings, null, 4)); PlainSettings = settings; Settings = makeSettingsProxy(settings); } +export { + PlainSettings, + PlainVencordSettings, +}; diff --git a/src/renderer/components/Settings.tsx b/src/renderer/components/Settings.tsx index f97f6e6..7ee2848 100644 --- a/src/renderer/components/Settings.tsx +++ b/src/renderer/components/Settings.tsx @@ -49,9 +49,9 @@ export default function SettingsUi() { ))} - Vencord Desktop Location + Vencord Location - Files are loaded from + Vencord files are loaded from {" "} {Settings.vencordDir ? (