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 = {};
|
const registered_keybinds = {};
|
||||||
|
|
||||||
handle(IpcEvents.KEYBIND_REGISTER, (_, id: string, shortcut: string) => {
|
handle(IpcEvents.KEYBIND_REGISTER, (_, id: number, shortcut: string, options: any) => {
|
||||||
globalShortcut.register(shortcut, () => {
|
globalShortcut.register(shortcut, () => {
|
||||||
// false here implies `keyup`
|
// false here implies `keyup`
|
||||||
// electron's global shortcut system doesn't really register keyup or down as far as i can tell
|
// 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;
|
registered_keybinds[id] = shortcut;
|
||||||
});
|
});
|
||||||
handle(IpcEvents.KEYBIND_UNREGISTER, (_, id: string) => {
|
handle(IpcEvents.KEYBIND_UNREGISTER, (_, id: number) => {
|
||||||
globalShortcut.unregister(registered_keybinds[id]);
|
globalShortcut.unregister(registered_keybinds[id]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -77,7 +77,8 @@ export const VesktopNative = {
|
||||||
invoke<void>(IpcEvents.CLIPBOARD_COPY_IMAGE, imageBuffer, imageSrc)
|
invoke<void>(IpcEvents.CLIPBOARD_COPY_IMAGE, imageBuffer, imageSrc)
|
||||||
},
|
},
|
||||||
keybind: {
|
keybind: {
|
||||||
register: (id: string, shortcut: string) => invoke<void>(IpcEvents.KEYBIND_REGISTER, id, shortcut),
|
register: (id: number, shortcut: string, options: any) =>
|
||||||
uregister: (id: string) => invoke<void>(IpcEvents.KEYBIND_UNREGISTER, id)
|
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");
|
const InviteActions = findByPropsLazy("resolveInvite");
|
||||||
|
|
||||||
export const keybindCallbacks: { [id: string]: Function } = {};
|
export const keybindCallbacks: { [id: number]: Function } = {};
|
||||||
|
|
||||||
export async function openInviteModal(code: string) {
|
export async function openInviteModal(code: string) {
|
||||||
const { invite } = await InviteActions.resolveInvite(code, "Desktop Modal");
|
const { invite } = await InviteActions.resolveInvite(code, "Desktop Modal");
|
||||||
|
|
|
@ -4,39 +4,49 @@
|
||||||
* Copyright (c) 2023 Vendicated and Vencord contributors
|
* Copyright (c) 2023 Vendicated and Vencord contributors
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { findByPropsLazy } from "@vencord/types/webpack";
|
||||||
import { keybindCallbacks } from "renderer";
|
import { keybindCallbacks } from "renderer";
|
||||||
|
|
||||||
import { addPatch } from "./shared";
|
import { addPatch } from "./shared";
|
||||||
|
const { toString } = findByPropsLazy("keyToCode");
|
||||||
|
|
||||||
addPatch({
|
addPatch({
|
||||||
patches: [
|
patches: [
|
||||||
{
|
{
|
||||||
find: ".default.Messages.KEYBINDS,children:",
|
find: ".default.Messages.KEYBINDS,children:",
|
||||||
replacement: {
|
replacement: [
|
||||||
match: /.\.isPlatformEmbedded/,
|
{
|
||||||
replace: "true"
|
// 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",
|
find: "[kb store] KeybindStore",
|
||||||
replacement: {
|
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"
|
// eslint-disable-next-line no-useless-escape
|
||||||
}
|
match: /inputEventRegister\((parseInt\(\i\),\i,\i,\i)\);else\{/,
|
||||||
},
|
replace: "$&$self.registerKeybind($1);return;"
|
||||||
{
|
},
|
||||||
find: "[kb store] KeybindStore",
|
{
|
||||||
replacement: {
|
// eslint-disable-next-line no-useless-escape
|
||||||
// WHY IS THE RADIX SPEICIFIED
|
match: /inputEventUnregister\((parseInt\(\i,10\))\);else\{/,
|
||||||
match: /(inputEventUnregister\(parseInt\((.{1,2}),10\)\);else\{)/,
|
replace: "$&$self.unregisterKeybind($1);return;"
|
||||||
replace: "$1$self.unregisterKeybind($2);return;"
|
}
|
||||||
}
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|
||||||
registerKeybind: function (id, shortcut, callback, toString) {
|
registerKeybind: function (id, shortcut, callback, options) {
|
||||||
keybindCallbacks[id] = callback;
|
keybindCallbacks[id] = callback;
|
||||||
VesktopNative.keybind.register(id, toString(shortcut));
|
VesktopNative.keybind.register(id, toString(shortcut), options);
|
||||||
},
|
},
|
||||||
unregisterKeybind: function (id) {
|
unregisterKeybind: function (id) {
|
||||||
delete keybindCallbacks[id];
|
delete keybindCallbacks[id];
|
||||||
|
|
Loading…
Reference in a new issue