mirror of
https://github.com/Vencord/Vesktop.git
synced 2025-02-23 21:55:09 +00:00
Add keyup keydown support
update venbind
This commit is contained in:
parent
34a6043ea8
commit
e7a753113f
6 changed files with 62 additions and 21 deletions
|
@ -26,7 +26,7 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"arrpc": "github:OpenAsar/arrpc#5aadc307cb9bf4479f0a12364a253b07a77ace22",
|
"arrpc": "github:OpenAsar/arrpc#5aadc307cb9bf4479f0a12364a253b07a77ace22",
|
||||||
"electron-updater": "^6.3.9",
|
"electron-updater": "^6.3.9",
|
||||||
"venbind": "^0.0.2"
|
"venbind": "^0.0.3"
|
||||||
},
|
},
|
||||||
"optionalDependencies": {
|
"optionalDependencies": {
|
||||||
"@vencord/venmic": "^6.1.0"
|
"@vencord/venmic": "^6.1.0"
|
||||||
|
|
|
@ -76,10 +76,10 @@ function init() {
|
||||||
if (keybindIndex !== -1) {
|
if (keybindIndex !== -1) {
|
||||||
if (cmdLine[keybindIndex + 2] === "keyup" || cmdLine[keybindIndex + 2] === "keydown") {
|
if (cmdLine[keybindIndex + 2] === "keyup" || cmdLine[keybindIndex + 2] === "keydown") {
|
||||||
mainWin.webContents.executeJavaScript(
|
mainWin.webContents.executeJavaScript(
|
||||||
`Vesktop.keybindCallbacks[${cmdLine[keybindIndex + 1]}](${cmdLine[keybindIndex + 2] === "keydown" ? "true" : "false"})`
|
`Vesktop.triggerKeybind(${cmdLine[keybindIndex + 1]}, ${cmdLine[keybindIndex + 2] === "keydown" ? "false" : "true"})`
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
mainWin.webContents.executeJavaScript(`Vesktop.keybindCallbacks[${cmdLine[keybindIndex + 1]}](false)`);
|
mainWin.webContents.executeJavaScript(`Vesktop.triggerKeybind(${cmdLine[keybindIndex + 1]}, true)`);
|
||||||
}
|
}
|
||||||
} else if (data.IS_DEV) app.quit();
|
} else if (data.IS_DEV) app.quit();
|
||||||
else if (mainWin) {
|
else if (mainWin) {
|
||||||
|
|
|
@ -50,12 +50,12 @@ export function obtainVenbind() {
|
||||||
|
|
||||||
export function startVenbind() {
|
export function startVenbind() {
|
||||||
const venbind = obtainVenbind();
|
const venbind = obtainVenbind();
|
||||||
venbind?.startKeybinds(x => {
|
venbind?.startKeybinds((id, keyup) => {
|
||||||
mainWin.webContents.executeJavaScript(`Vesktop.keybindCallbacks[${x}](false)`);
|
mainWin.webContents.executeJavaScript(`Vesktop.triggerKeybind(${id}, ${keyup})`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
handle(IpcEvents.KEYBIND_REGISTER, (_, id: number, shortcut: string, options: any) => {
|
handle(IpcEvents.KEYBIND_REGISTER, (_, id: number, shortcut: string) => {
|
||||||
obtainVenbind()?.registerKeybind(shortcut, id);
|
obtainVenbind()?.registerKeybind(shortcut, id);
|
||||||
});
|
});
|
||||||
handle(IpcEvents.KEYBIND_UNREGISTER, (_, id: number) => {
|
handle(IpcEvents.KEYBIND_UNREGISTER, (_, id: number) => {
|
||||||
|
|
|
@ -80,8 +80,7 @@ export const VesktopNative = {
|
||||||
invoke<void>(IpcEvents.CLIPBOARD_COPY_IMAGE, imageBuffer, imageSrc)
|
invoke<void>(IpcEvents.CLIPBOARD_COPY_IMAGE, imageBuffer, imageSrc)
|
||||||
},
|
},
|
||||||
keybind: {
|
keybind: {
|
||||||
register: (id: number, shortcut: string, options: any) =>
|
register: (id: number, shortcut: string) => invoke<void>(IpcEvents.KEYBIND_REGISTER, id, shortcut),
|
||||||
invoke<void>(IpcEvents.KEYBIND_REGISTER, id, shortcut),
|
|
||||||
unregister: (id: number) => invoke<void>(IpcEvents.KEYBIND_UNREGISTER, id),
|
unregister: (id: number) => invoke<void>(IpcEvents.KEYBIND_UNREGISTER, id),
|
||||||
shouldPreRegister: () => sendSync<boolean>(IpcEvents.KEYBIND_SHOULD_PREREGISTER),
|
shouldPreRegister: () => sendSync<boolean>(IpcEvents.KEYBIND_SHOULD_PREREGISTER),
|
||||||
preRegister: (actions: { id: number; name: string }[]) => invoke<void>(IpcEvents.KEYBIND_PREREGISTER, actions)
|
preRegister: (actions: { id: number; name: string }[]) => invoke<void>(IpcEvents.KEYBIND_PREREGISTER, actions)
|
||||||
|
|
|
@ -21,7 +21,15 @@ export { Settings };
|
||||||
|
|
||||||
const InviteActions = findByPropsLazy("resolveInvite");
|
const InviteActions = findByPropsLazy("resolveInvite");
|
||||||
|
|
||||||
export const keybindCallbacks: { [id: number]: Function } = {};
|
export const keybindCallbacks: {
|
||||||
|
[id: number]: {
|
||||||
|
onTrigger: Function;
|
||||||
|
keyEvents: {
|
||||||
|
keyup: boolean;
|
||||||
|
keydown: boolean;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
} = {};
|
||||||
|
|
||||||
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");
|
||||||
|
@ -39,6 +47,15 @@ export async function openInviteModal(code: string) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function triggerKeybind(id: number, keyup: boolean) {
|
||||||
|
var cb = keybindCallbacks[id];
|
||||||
|
if (cb.keyEvents.keyup && keyup) {
|
||||||
|
cb.onTrigger(false);
|
||||||
|
} else if (cb.keyEvents.keydown && !keyup) {
|
||||||
|
cb.onTrigger(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const customSettingsSections = (
|
const customSettingsSections = (
|
||||||
Vencord.Plugins.plugins.Settings as any as { customSections: ((ID: Record<string, unknown>) => any)[] }
|
Vencord.Plugins.plugins.Settings as any as { customSections: ((ID: Record<string, unknown>) => any)[] }
|
||||||
).customSections;
|
).customSections;
|
||||||
|
|
|
@ -22,6 +22,7 @@ const actionReadableNames: { [key: string]: string } = {
|
||||||
NAVIGATE_FORWARD: "Navigate Forward",
|
NAVIGATE_FORWARD: "Navigate Forward",
|
||||||
DISCONNECT_FROM_VOICE_CHANNEL: "Disconnect From Voice Channel"
|
DISCONNECT_FROM_VOICE_CHANNEL: "Disconnect From Voice Channel"
|
||||||
};
|
};
|
||||||
|
const actions: { id: number; name: string }[] = [];
|
||||||
addPatch({
|
addPatch({
|
||||||
patches: [
|
patches: [
|
||||||
{
|
{
|
||||||
|
@ -72,12 +73,23 @@ addPatch({
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|
||||||
registerKeybind: function (id, shortcut, callback, options) {
|
registerKeybind: function (
|
||||||
|
id,
|
||||||
|
shortcut,
|
||||||
|
callback: Function,
|
||||||
|
options: {
|
||||||
|
keyup: boolean;
|
||||||
|
keydown: boolean;
|
||||||
|
}
|
||||||
|
) {
|
||||||
if (VesktopNative.keybind.shouldPreRegister()) {
|
if (VesktopNative.keybind.shouldPreRegister()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
keybindCallbacks[id] = callback;
|
keybindCallbacks[id] = {
|
||||||
VesktopNative.keybind.register(id, toShortcutString(shortcut), options);
|
onTrigger: callback,
|
||||||
|
keyEvents: options
|
||||||
|
};
|
||||||
|
VesktopNative.keybind.register(id, toShortcutString(shortcut));
|
||||||
},
|
},
|
||||||
unregisterKeybind: function (id) {
|
unregisterKeybind: function (id) {
|
||||||
if (VesktopNative.keybind.shouldPreRegister()) {
|
if (VesktopNative.keybind.shouldPreRegister()) {
|
||||||
|
@ -90,9 +102,12 @@ addPatch({
|
||||||
preRegisterKeybinds: function (allActions: {
|
preRegisterKeybinds: function (allActions: {
|
||||||
[action: string]: {
|
[action: string]: {
|
||||||
onTrigger: Function;
|
onTrigger: Function;
|
||||||
|
keyEvents: {
|
||||||
|
keyup: boolean;
|
||||||
|
keydown: boolean;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
}) {
|
}) {
|
||||||
const actions: { id: number; name: string }[] = [];
|
|
||||||
if (!VesktopNative.keybind.shouldPreRegister()) {
|
if (!VesktopNative.keybind.shouldPreRegister()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -102,6 +117,7 @@ addPatch({
|
||||||
[
|
[
|
||||||
"UNASSIGNED",
|
"UNASSIGNED",
|
||||||
"SWITCH_TO_VOICE_CHANNEL",
|
"SWITCH_TO_VOICE_CHANNEL",
|
||||||
|
"PUSH_TO_TALK",
|
||||||
"TOGGLE_OVERLAY",
|
"TOGGLE_OVERLAY",
|
||||||
"TOGGLE_OVERLAY_INPUT_LOCK",
|
"TOGGLE_OVERLAY_INPUT_LOCK",
|
||||||
"TOGGLE_PRIORITY_SPEAKER",
|
"TOGGLE_PRIORITY_SPEAKER",
|
||||||
|
@ -115,20 +131,21 @@ addPatch({
|
||||||
) {
|
) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// the second argument in onTrigger seems to hold some context in some specific actions
|
keybindCallbacks[id] = {
|
||||||
// as far as i can tell these are the only actions that use it: push to talk (except it doesn't seem to do anything there??)
|
// TODO: the "undefined" here is supposed to be a context. basically only used by push to talk to determine if you are in ptt mode or not
|
||||||
// and switch to voice channel which requires a channel parameter which is provided through discord's ui
|
// (it's also used by switch to channel to determine the channel but you can't really define that through xdp)
|
||||||
// except we can't really provide that with xdp so i'll just skip it for now
|
onTrigger: (keyState: boolean) => val.onTrigger(keyState, undefined),
|
||||||
keybindCallbacks[id] = (keyState: boolean) => val.onTrigger(keyState, undefined);
|
keyEvents: val.keyEvents
|
||||||
|
};
|
||||||
actions.push({ id, name: actionReadableNames[key] || key });
|
actions.push({ id, name: actionReadableNames[key] || key });
|
||||||
id++;
|
id++;
|
||||||
});
|
});
|
||||||
VesktopNative.keybind.preRegister(actions);
|
|
||||||
},
|
},
|
||||||
xdpWarning: function (keybinds) {
|
xdpWarning: function (keybinds) {
|
||||||
if (!VesktopNative.keybind.shouldPreRegister()) {
|
if (!VesktopNative.keybind.shouldPreRegister()) {
|
||||||
return keybinds;
|
return keybinds;
|
||||||
}
|
}
|
||||||
|
VesktopNative.keybind.preRegister(actions);
|
||||||
return (
|
return (
|
||||||
<ErrorCard>
|
<ErrorCard>
|
||||||
<p>
|
<p>
|
||||||
|
@ -136,9 +153,17 @@ addPatch({
|
||||||
You can configure keybinds using your desktop environment's built-in settings page.
|
You can configure keybinds using your desktop environment's built-in settings page.
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
If your desktop environment does not support the GlobalShortcuts portal you have to manually bind
|
If your desktop environment does not support the GlobalShortcuts portal (which you would know if its
|
||||||
your desired keybinds to CLI triggers.
|
settings page didn't open just now) you have to manually bind your desired keybinds to CLI triggers.
|
||||||
</p>
|
</p>
|
||||||
|
<p>List of valid keybind IDs to use with the CLI:</p>
|
||||||
|
<ul>
|
||||||
|
{actions.map(keybind => (
|
||||||
|
<li>
|
||||||
|
{keybind.id}: {keybind.name}
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
</ErrorCard>
|
</ErrorCard>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue