From b2ecb02335fa51a7c7eadab0acb3beb91c289802 Mon Sep 17 00:00:00 2001 From: Ven Date: Tue, 24 Jan 2023 01:42:57 +0100 Subject: Make Windows Ctrl+Q feature optional; add opt-in auto update (#451) --- src/patcher.ts | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) (limited to 'src/patcher.ts') diff --git a/src/patcher.ts b/src/patcher.ts index 82fc233..2da404f 100644 --- a/src/patcher.ts +++ b/src/patcher.ts @@ -43,33 +43,35 @@ require.main!.filename = join(asarPath, discordPkg.main); app.setAppPath(asarPath); if (!process.argv.includes("--vanilla")) { + let settings: typeof import("@api/settings").Settings = {} as any; + try { + settings = JSON.parse(readSettings()); + } catch { } + // Repatch after host updates on Windows if (process.platform === "win32") { require("./patchWin32Updater"); - const originalBuild = Menu.buildFromTemplate; - Menu.buildFromTemplate = function (template) { - if (template[0]?.label === "&File") { - const { submenu } = template[0]; - if (Array.isArray(submenu)) { - submenu.push({ - label: "Quit (Hidden)", - visible: false, - acceleratorWorksWhenHidden: true, - accelerator: "Control+Q", - click: () => app.quit() - }); + if (settings.winCtrlQ) { + const originalBuild = Menu.buildFromTemplate; + Menu.buildFromTemplate = function (template) { + if (template[0]?.label === "&File") { + const { submenu } = template[0]; + if (Array.isArray(submenu)) { + submenu.push({ + label: "Quit (Hidden)", + visible: false, + acceleratorWorksWhenHidden: true, + accelerator: "Control+Q", + click: () => app.quit() + }); + } } - } - return originalBuild.call(this, template); - }; + return originalBuild.call(this, template); + }; + } } - let settings = {} as any; - try { - settings = JSON.parse(readSettings()); - } catch { } - class BrowserWindow extends electron.BrowserWindow { constructor(options: BrowserWindowConstructorOptions) { if (options?.webPreferences?.preload && options.title) { -- cgit