Skip to content

Commit ac0f375

Browse files
committed
add venbind. currently only linux x64
1 parent d99adcc commit ac0f375

File tree

6 files changed

+82
-19
lines changed

6 files changed

+82
-19
lines changed

Diff for: package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
},
2626
"dependencies": {
2727
"arrpc": "github:OpenAsar/arrpc#c62ec6a04c8d870530aa6944257fe745f6c59a24",
28-
"electron-updater": "^6.2.1"
28+
"electron-updater": "^6.2.1",
29+
"venbind": "^0.0.2"
2930
},
3031
"optionalDependencies": {
3132
"@vencord/venmic": "^6.1.0"

Diff for: pnpm-lock.yaml

+17-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: scripts/build/build.mts

+4
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ async function copyVenmic() {
4545
copyFile(
4646
"./node_modules/@vencord/venmic/prebuilds/venmic-addon-linux-arm64/node-napi-v7.node",
4747
"./static/dist/venmic-arm64.node"
48+
),
49+
copyFile(
50+
"./node_modules/venbind/prebuilds/linux-x86_64/venbind-linux-x86_64.node",
51+
"./static/dist/venbind-linux-x86_64.node"
4852
)
4953
]).catch(() => console.warn("Failed to copy venmic. Building without venmic support"));
5054
}

Diff for: src/main/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { registerMediaPermissionsHandler } from "./mediaPermissions";
1616
import { registerScreenShareHandler } from "./screenShare";
1717
import { Settings, State } from "./settings";
1818
import { isDeckGameMode } from "./utils/steamOS";
19+
import { startVenbind } from "./venbind";
1920

2021
if (IS_DEV) {
2122
require("source-map-support").install();
@@ -88,6 +89,7 @@ function init() {
8889
app.whenReady().then(async () => {
8990
if (process.platform === "win32") app.setAppUserModelId("dev.vencord.vesktop");
9091

92+
startVenbind();
9193
registerScreenShareHandler();
9294
registerMediaPermissionsHandler();
9395

Diff for: src/main/ipc.ts

-9
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,6 @@ handle(IpcEvents.CLIPBOARD_COPY_IMAGE, async (_, buf: ArrayBuffer, src: string)
135135
});
136136
});
137137

138-
const registered_keybinds = {};
139-
140-
handle(IpcEvents.KEYBIND_REGISTER, (_, id: number, shortcut: string, options: any) => {
141-
registered_keybinds[id] = shortcut;
142-
});
143-
handle(IpcEvents.KEYBIND_UNREGISTER, (_, id: number) => {
144-
delete registered_keybinds[id];
145-
});
146-
147138
function readCss() {
148139
return readFile(VENCORD_QUICKCSS_FILE, "utf-8").catch(() => "");
149140
}

Diff for: src/main/venbind.ts

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* SPDX-License-Identifier: GPL-3.0
3+
* Vesktop, a desktop app aiming to give you a snappier Discord Experience
4+
* Copyright (c) 2023 Vendicated and Vencord contributors
5+
*/
6+
7+
import { join } from "path";
8+
import { IpcEvents } from "shared/IpcEvents";
9+
import { STATIC_DIR } from "shared/paths";
10+
import type { Venbind as VenbindType } from "venbind";
11+
12+
import { mainWin } from "./mainWindow";
13+
import { handle } from "./utils/ipcWrappers";
14+
15+
let venbind: VenbindType | null = null;
16+
export function obtainVenbind() {
17+
// TODO?: make binary outputs consistant with node's apis
18+
let os: string;
19+
switch (process.platform) {
20+
case "linux":
21+
os = "linux";
22+
break;
23+
// case "win32":
24+
// os = "windows";
25+
// case "darwin":
26+
// os = "darwin";
27+
default:
28+
return null;
29+
};
30+
let arch: string;
31+
switch (process.arch) {
32+
case "x64":
33+
arch = "x86_64";
34+
break;
35+
// case "arm64":
36+
// arch = "aarch64";
37+
// break;
38+
default:
39+
return null;
40+
};
41+
if (venbind == null) venbind = require(join(STATIC_DIR, `dist/venbind-${os}-${arch}.node`));
42+
return venbind;
43+
}
44+
45+
export function startVenbind() {
46+
const venbind = obtainVenbind();
47+
venbind?.startKeybinds(null, x => {
48+
mainWin.webContents.executeJavaScript(`Vesktop.keybindCallbacks[${x}](false)`);
49+
});
50+
}
51+
52+
handle(IpcEvents.KEYBIND_REGISTER, (_, id: number, shortcut: string, options: any) => {
53+
obtainVenbind()?.registerKeybind(shortcut, id);
54+
});
55+
handle(IpcEvents.KEYBIND_UNREGISTER, (_, id: number) => {
56+
obtainVenbind()?.unregisterKeybind(id);
57+
});

0 commit comments

Comments
 (0)