Skip to content

Commit

Permalink
add venbind. currently only linux x64
Browse files Browse the repository at this point in the history
  • Loading branch information
tuxinal committed Aug 18, 2024
1 parent d99adcc commit ac0f375
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 19 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
},
"dependencies": {
"arrpc": "github:OpenAsar/arrpc#c62ec6a04c8d870530aa6944257fe745f6c59a24",
"electron-updater": "^6.2.1"
"electron-updater": "^6.2.1",
"venbind": "^0.0.2"
},
"optionalDependencies": {
"@vencord/venmic": "^6.1.0"
Expand Down
26 changes: 17 additions & 9 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions scripts/build/build.mts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ async function copyVenmic() {
copyFile(
"./node_modules/@vencord/venmic/prebuilds/venmic-addon-linux-arm64/node-napi-v7.node",
"./static/dist/venmic-arm64.node"
),
copyFile(
"./node_modules/venbind/prebuilds/linux-x86_64/venbind-linux-x86_64.node",
"./static/dist/venbind-linux-x86_64.node"
)
]).catch(() => console.warn("Failed to copy venmic. Building without venmic support"));
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { registerMediaPermissionsHandler } from "./mediaPermissions";
import { registerScreenShareHandler } from "./screenShare";
import { Settings, State } from "./settings";
import { isDeckGameMode } from "./utils/steamOS";
import { startVenbind } from "./venbind";

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

startVenbind();
registerScreenShareHandler();
registerMediaPermissionsHandler();

Expand Down
9 changes: 0 additions & 9 deletions src/main/ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,6 @@ handle(IpcEvents.CLIPBOARD_COPY_IMAGE, async (_, buf: ArrayBuffer, src: string)
});
});

const registered_keybinds = {};

handle(IpcEvents.KEYBIND_REGISTER, (_, id: number, shortcut: string, options: any) => {
registered_keybinds[id] = shortcut;
});
handle(IpcEvents.KEYBIND_UNREGISTER, (_, id: number) => {
delete registered_keybinds[id];
});

function readCss() {
return readFile(VENCORD_QUICKCSS_FILE, "utf-8").catch(() => "");
}
Expand Down
57 changes: 57 additions & 0 deletions src/main/venbind.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* SPDX-License-Identifier: GPL-3.0
* Vesktop, a desktop app aiming to give you a snappier Discord Experience
* Copyright (c) 2023 Vendicated and Vencord contributors
*/

import { join } from "path";
import { IpcEvents } from "shared/IpcEvents";
import { STATIC_DIR } from "shared/paths";
import type { Venbind as VenbindType } from "venbind";

import { mainWin } from "./mainWindow";
import { handle } from "./utils/ipcWrappers";

let venbind: VenbindType | null = null;
export function obtainVenbind() {
// TODO?: make binary outputs consistant with node's apis
let os: string;
switch (process.platform) {
case "linux":
os = "linux";
break;
// case "win32":
// os = "windows";
// case "darwin":
// os = "darwin";
default:
return null;
};
let arch: string;
switch (process.arch) {
case "x64":
arch = "x86_64";
break;
// case "arm64":
// arch = "aarch64";
// break;
default:
return null;
};
if (venbind == null) venbind = require(join(STATIC_DIR, `dist/venbind-${os}-${arch}.node`));
return venbind;
}

export function startVenbind() {
const venbind = obtainVenbind();
venbind?.startKeybinds(null, x => {
mainWin.webContents.executeJavaScript(`Vesktop.keybindCallbacks[${x}](false)`);
});
}

handle(IpcEvents.KEYBIND_REGISTER, (_, id: number, shortcut: string, options: any) => {
obtainVenbind()?.registerKeybind(shortcut, id);
});
handle(IpcEvents.KEYBIND_UNREGISTER, (_, id: number) => {
obtainVenbind()?.unregisterKeybind(id);
});

0 comments on commit ac0f375

Please sign in to comment.