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");
// 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

View file

@ -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()
});

View file

@ -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<T extends object = any>(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<TSettings>(SETTINGS_FILE, "VencordDesktop");
export let Settings = makeSettingsProxy(PlainSettings);
let [PlainVencordSettings, makeVencordSettingsProxy] = loadSettings<any>(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,
};

View file

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