Implement frameless & windows ctrl q settings

This commit is contained in:
Vendicated 2023-04-09 05:25:45 +02:00
parent ba0e8fedd0
commit bba8899f67
No known key found for this signature in database
GPG key ID: A1DC0CFB5615D905
4 changed files with 38 additions and 24 deletions

View file

@ -4,11 +4,12 @@ import { join } from "path";
export const DATA_DIR = process.env.VENCORD_USER_DATA_DIR || join(app.getPath("userData"), "VencordDesktop"); export const DATA_DIR = process.env.VENCORD_USER_DATA_DIR || join(app.getPath("userData"), "VencordDesktop");
// needs to be inline require because of circular dependency // needs to be inline require because of circular dependency
// as otherwise "DATA_DIR" (which is used by ./settings) will be uninitialised // 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_SETTINGS_DIR = join(DATA_DIR, "settings");
export const VENCORD_QUICKCSS_FILE = join(VENCORD_SETTINGS_DIR, "quickCss.css"); 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_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)`; export const USER_AGENT = `VencordDesktop/${app.getVersion()} (https://github.com/Vencord/Electron)`;
// dimensions shamelessly stolen from Discord Desktop :3 // dimensions shamelessly stolen from Discord Desktop :3

View file

@ -3,7 +3,7 @@ import { join } from "path";
import { ICON_PATH } from "../shared/paths"; import { ICON_PATH } from "../shared/paths";
import { createAboutWindow } from "./about"; import { createAboutWindow } from "./about";
import { DEFAULT_HEIGHT, DEFAULT_WIDTH, MIN_HEIGHT, MIN_WIDTH } from "./constants"; 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 { makeLinksOpenExternally } from "./utils/makeLinksOpenExternally";
import { downloadVencordFiles } from "./utils/vencordLoader"; import { downloadVencordFiles } from "./utils/vencordLoader";
@ -70,7 +70,9 @@ function initTray(win: BrowserWindow) {
} }
function initMenuBar(win: BrowserWindow) { function initMenuBar(win: BrowserWindow) {
console.log(process.platform); const isWindows = process.platform === "win32";
const wantCtrlQ = !isWindows || VencordSettings.winCtrlQ;
const menu = Menu.buildFromTemplate([ const menu = Menu.buildFromTemplate([
{ {
label: "Vencord Desktop", label: "Vencord Desktop",
@ -120,18 +122,16 @@ function initMenuBar(win: BrowserWindow) {
}, },
{ {
label: "Quit", label: "Quit",
accelerator: process.platform === "win32" ? void 0 : "CmdOrCtrl+Q", accelerator: wantCtrlQ ? "CmdOrCtrl+Q" : void 0,
// TODO: Setting visible: !isWindows,
visible: process.platform !== "win32",
click() { click() {
app.quit(); app.quit();
} }
}, },
{ {
label: "Quit", label: "Quit",
accelerator: "Alt+F4", accelerator: isWindows ? "Alt+F4" : void 0,
visible: process.platform === "win32", visible: isWindows,
acceleratorWorksWhenHidden: false,
click() { click() {
app.quit(); app.quit();
} }
@ -217,6 +217,7 @@ export function createMainWindow() {
preload: join(__dirname, "preload.js") preload: join(__dirname, "preload.js")
}, },
icon: ICON_PATH, icon: ICON_PATH,
frame: VencordSettings.frameless !== true,
...getWindowBoundsOptions() ...getWindowBoundsOptions()
}); });

View file

@ -2,30 +2,42 @@ import { readFileSync, writeFileSync } from "fs";
import { join } from "path"; import { join } from "path";
import type { Settings as TSettings } from "shared/settings"; import type { Settings as TSettings } from "shared/settings";
import { makeChangeListenerProxy } from "shared/utils/makeChangeListenerProxy"; 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"); const SETTINGS_FILE = join(DATA_DIR, "settings.json");
export let PlainSettings = {} as TSettings; function loadSettings<T extends object = any>(file: string, name: string) {
try { let settings = {} as T;
const content = readFileSync(SETTINGS_FILE, "utf8");
try { try {
PlainSettings = JSON.parse(content); const content = readFileSync(file, "utf8");
} catch (err) { try {
console.error("Failed to parse settings.json:", err); settings = JSON.parse(content);
} } catch (err) {
} catch { } console.error(`Failed to parse ${name} settings.json:`, err);
}
} catch { }
const makeSettingsProxy = (settings: TSettings) => makeChangeListenerProxy( const makeSettingsProxy = (settings: T) => makeChangeListenerProxy(
settings, settings,
target => writeFileSync(SETTINGS_FILE, JSON.stringify(target, null, 4)) target => writeFileSync(file, JSON.stringify(target, null, 4))
); );
return [settings, makeSettingsProxy] as const;
}
let [PlainSettings, makeSettingsProxy] = loadSettings<TSettings>(SETTINGS_FILE, "VencordDesktop");
export let Settings = makeSettingsProxy(PlainSettings); export let Settings = makeSettingsProxy(PlainSettings);
let [PlainVencordSettings, makeVencordSettingsProxy] = loadSettings<any>(VENCORD_SETTINGS_FILE, "Vencord");
export const VencordSettings = makeVencordSettingsProxy(PlainVencordSettings);
export function setSettings(settings: TSettings) { export function setSettings(settings: TSettings) {
writeFileSync(SETTINGS_FILE, JSON.stringify(settings, null, 4)); writeFileSync(SETTINGS_FILE, JSON.stringify(settings, null, 4));
PlainSettings = settings; PlainSettings = settings;
Settings = makeSettingsProxy(settings); Settings = makeSettingsProxy(settings);
} }
export {
PlainSettings,
PlainVencordSettings,
};

View file

@ -49,9 +49,9 @@ export default function SettingsUi() {
</FormSwitch> </FormSwitch>
))} ))}
<FormTitle>Vencord Desktop Location</FormTitle> <FormTitle>Vencord Location</FormTitle>
<FormText> <FormText>
Files are loaded from Vencord files are loaded from
{" "} {" "}
{Settings.vencordDir {Settings.vencordDir
? ( ? (