diff --git a/src/main/ipc.ts b/src/main/ipc.ts index 0c7b11c3..71dd5120 100644 --- a/src/main/ipc.ts +++ b/src/main/ipc.ts @@ -142,15 +142,15 @@ handle(IpcEvents.CLIPBOARD_COPY_IMAGE, async (_, buf: ArrayBuffer, src: string) const registered_keybinds = {}; -handle(IpcEvents.KEYBIND_REGISTER, (_, id: string, shortcut: string) => { +handle(IpcEvents.KEYBIND_REGISTER, (_, id: number, shortcut: string, options: any) => { globalShortcut.register(shortcut, () => { // false here implies `keyup` // electron's global shortcut system doesn't really register keyup or down as far as i can tell - mainWin.webContents.executeJavaScript(`Vesktop.keybindCallbacks["${id}"](false)`); + mainWin.webContents.executeJavaScript(`Vesktop.keybindCallbacks[${id}](false)`); }); registered_keybinds[id] = shortcut; }); -handle(IpcEvents.KEYBIND_UNREGISTER, (_, id: string) => { +handle(IpcEvents.KEYBIND_UNREGISTER, (_, id: number) => { globalShortcut.unregister(registered_keybinds[id]); }); diff --git a/src/preload/VesktopNative.ts b/src/preload/VesktopNative.ts index a755ae5c..01af5cba 100644 --- a/src/preload/VesktopNative.ts +++ b/src/preload/VesktopNative.ts @@ -77,7 +77,8 @@ export const VesktopNative = { invoke(IpcEvents.CLIPBOARD_COPY_IMAGE, imageBuffer, imageSrc) }, keybind: { - register: (id: string, shortcut: string) => invoke(IpcEvents.KEYBIND_REGISTER, id, shortcut), - uregister: (id: string) => invoke(IpcEvents.KEYBIND_UNREGISTER, id) + register: (id: number, shortcut: string, options: any) => + invoke(IpcEvents.KEYBIND_REGISTER, id, shortcut), + uregister: (id: number) => invoke(IpcEvents.KEYBIND_UNREGISTER, id) } }; diff --git a/src/renderer/index.ts b/src/renderer/index.ts index a1c3de9c..cd0e00ca 100644 --- a/src/renderer/index.ts +++ b/src/renderer/index.ts @@ -21,7 +21,7 @@ export { Settings }; const InviteActions = findByPropsLazy("resolveInvite"); -export const keybindCallbacks: { [id: string]: Function } = {}; +export const keybindCallbacks: { [id: number]: Function } = {}; export async function openInviteModal(code: string) { const { invite } = await InviteActions.resolveInvite(code, "Desktop Modal"); diff --git a/src/renderer/patches/keybinds.ts b/src/renderer/patches/keybinds.ts index 209b579e..d159b57d 100644 --- a/src/renderer/patches/keybinds.ts +++ b/src/renderer/patches/keybinds.ts @@ -4,39 +4,49 @@ * Copyright (c) 2023 Vendicated and Vencord contributors */ +import { findByPropsLazy } from "@vencord/types/webpack"; import { keybindCallbacks } from "renderer"; import { addPatch } from "./shared"; +const { toString } = findByPropsLazy("keyToCode"); addPatch({ patches: [ { find: ".default.Messages.KEYBINDS,children:", - replacement: { - match: /.\.isPlatformEmbedded/, - replace: "true" - } + replacement: [ + { + // eslint-disable-next-line no-useless-escape + match: /\i\.isPlatformEmbedded/g, + replace: "true" + }, + { + // eslint-disable-next-line no-useless-escape + match: /\(0,\i.isDesktop\)\(\)/g, + replace: "true" + } + ] }, { find: "[kb store] KeybindStore", - replacement: { - match: /(inputEventRegister\(parseInt\((.{1,2})\),(.{1,2}),(.{1,2}),(.{1,2})\);else\{)([^;]*;[^;]*;.{1,2}\.keyup&&.{1,2}\.bindGlobal\(\(0,(.{1,2}\.toString)\))/, - replace: "$1$self.registerKeybind($2,$3,$4,$7);return;$6" - } - }, - { - find: "[kb store] KeybindStore", - replacement: { - // WHY IS THE RADIX SPEICIFIED - match: /(inputEventUnregister\(parseInt\((.{1,2}),10\)\);else\{)/, - replace: "$1$self.unregisterKeybind($2);return;" - } + replacement: [ + { + // eslint-disable-next-line no-useless-escape + match: /inputEventRegister\((parseInt\(\i\),\i,\i,\i)\);else\{/, + replace: "$&$self.registerKeybind($1);return;" + }, + { + // eslint-disable-next-line no-useless-escape + match: /inputEventUnregister\((parseInt\(\i,10\))\);else\{/, + replace: "$&$self.unregisterKeybind($1);return;" + } + ] } ], - registerKeybind: function (id, shortcut, callback, toString) { + registerKeybind: function (id, shortcut, callback, options) { keybindCallbacks[id] = callback; - VesktopNative.keybind.register(id, toString(shortcut)); + VesktopNative.keybind.register(id, toString(shortcut), options); }, unregisterKeybind: function (id) { delete keybindCallbacks[id];