From ae9fe7fcfd49b6b178e55f36cc3d12e286a6134c Mon Sep 17 00:00:00 2001 From: Vendicated Date: Sun, 8 Jan 2023 19:13:33 +0100 Subject: Fix Ctrl+Q shortcut working when Discord minimised --- src/patcher.ts | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/patcher.ts b/src/patcher.ts index 6766e0f..96cb23c 100644 --- a/src/patcher.ts +++ b/src/patcher.ts @@ -17,7 +17,7 @@ */ import { onceDefined } from "@utils/onceDefined"; -import electron, { app, BrowserWindowConstructorOptions, globalShortcut } from "electron"; +import electron, { app, BrowserWindowConstructorOptions, Menu } from "electron"; import { readFileSync } from "fs"; import { dirname, join } from "path"; @@ -44,9 +44,27 @@ app.setAppPath(asarPath); if (!process.argv.includes("--vanilla")) { // Repatch after host updates on Windows - if (process.platform === "win32") + 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() + }); + } + } + return originalBuild.call(this, template); + }; + } + class BrowserWindow extends electron.BrowserWindow { constructor(options: BrowserWindowConstructorOptions) { if (options?.webPreferences?.preload && options.title) { @@ -153,13 +171,6 @@ if (!process.argv.includes("--vanilla")) { responseHeaders["content-type"] = ["text/css"]; } cb({ cancel: false, responseHeaders }); - - - if (process.platform === "win32") { - globalShortcut.register("Control+Q", () => { - app.quit(); - }); - } }); }); } else { -- cgit