Minimize regex
convert id to number enable desktop only shortcut actions
This commit is contained in:
parent
0503eff71e
commit
d222d4ffc1
4 changed files with 35 additions and 24 deletions
|
@ -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]);
|
||||
});
|
||||
|
||||
|
|
|
@ -77,7 +77,8 @@ export const VesktopNative = {
|
|||
invoke<void>(IpcEvents.CLIPBOARD_COPY_IMAGE, imageBuffer, imageSrc)
|
||||
},
|
||||
keybind: {
|
||||
register: (id: string, shortcut: string) => invoke<void>(IpcEvents.KEYBIND_REGISTER, id, shortcut),
|
||||
uregister: (id: string) => invoke<void>(IpcEvents.KEYBIND_UNREGISTER, id)
|
||||
register: (id: number, shortcut: string, options: any) =>
|
||||
invoke<void>(IpcEvents.KEYBIND_REGISTER, id, shortcut),
|
||||
uregister: (id: number) => invoke<void>(IpcEvents.KEYBIND_UNREGISTER, id)
|
||||
}
|
||||
};
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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];
|
||||
|
|
Loading…
Reference in a new issue