Fix Ctrl+Q shortcut working when Discord minimised

This commit is contained in:
Vendicated 2023-01-08 19:13:33 +01:00
parent f0240ec345
commit ae9fe7fcfd
No known key found for this signature in database
GPG key ID: A1DC0CFB5615D905

View file

@ -17,7 +17,7 @@
*/ */
import { onceDefined } from "@utils/onceDefined"; import { onceDefined } from "@utils/onceDefined";
import electron, { app, BrowserWindowConstructorOptions, globalShortcut } from "electron"; import electron, { app, BrowserWindowConstructorOptions, Menu } from "electron";
import { readFileSync } from "fs"; import { readFileSync } from "fs";
import { dirname, join } from "path"; import { dirname, join } from "path";
@ -44,9 +44,27 @@ app.setAppPath(asarPath);
if (!process.argv.includes("--vanilla")) { if (!process.argv.includes("--vanilla")) {
// Repatch after host updates on Windows // Repatch after host updates on Windows
if (process.platform === "win32") if (process.platform === "win32") {
require("./patchWin32Updater"); 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 { class BrowserWindow extends electron.BrowserWindow {
constructor(options: BrowserWindowConstructorOptions) { constructor(options: BrowserWindowConstructorOptions) {
if (options?.webPreferences?.preload && options.title) { if (options?.webPreferences?.preload && options.title) {
@ -153,13 +171,6 @@ if (!process.argv.includes("--vanilla")) {
responseHeaders["content-type"] = ["text/css"]; responseHeaders["content-type"] = ["text/css"];
} }
cb({ cancel: false, responseHeaders }); cb({ cancel: false, responseHeaders });
if (process.platform === "win32") {
globalShortcut.register("Control+Q", () => {
app.quit();
});
}
}); });
}); });
} else { } else {