From f0919833e6ec278c9f5ad342b447f87c804642dd Mon Sep 17 00:00:00 2001 From: Tuxinal <24763016+tuxinal@users.noreply.github.com> Date: Sun, 18 Aug 2024 19:27:25 +0330 Subject: [PATCH] add venbind. currently only linux x64 on x11 --- package.json | 3 ++- pnpm-lock.yaml | 26 ++++++++++++------- scripts/build/build.mts | 4 +++ src/main/index.ts | 2 ++ src/main/ipc.ts | 9 ------- src/main/venbind.ts | 57 +++++++++++++++++++++++++++++++++++++++++ 6 files changed, 82 insertions(+), 19 deletions(-) create mode 100644 src/main/venbind.ts diff --git a/package.json b/package.json index ca5cf495..d8d3fedd 100644 --- a/package.json +++ b/package.json @@ -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" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e67ad18f..64b614cb 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -19,6 +19,9 @@ importers: electron-updater: specifier: ^6.2.1 version: 6.2.1 + venbind: + specifier: ^0.0.2 + version: 0.0.2 optionalDependencies: '@vencord/venmic': specifier: ^6.1.0 @@ -2784,6 +2787,9 @@ packages: util-deprecate@1.0.2: resolution: {integrity: sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==} + venbind@0.0.2: + resolution: {integrity: sha512-TlkghnnV43lmINTMOuZWvgRIIZJ3I5oNykXbGZPC22GE7gdoen9uPBWWEKLtN7BG4wjtT/dIAv2Xz9gHz9P4Gw==} + verror@1.10.1: resolution: {integrity: sha512-veufcmxri4e3XSrT0xwfUR7kguIkaxBeosDg00yDWhk49wdwkSUrvvsm7nc75e1PUyvIeZj6nS8VQRYz2/S4Xg==} engines: {node: '>=0.6.0'} @@ -3441,7 +3447,7 @@ snapshots: app-builder-bin@5.0.0-alpha.6: {} - app-builder-lib@24.13.3(dmg-builder@25.0.1(electron-builder-squirrel-windows@24.13.3(dmg-builder@25.0.1)))(electron-builder-squirrel-windows@24.13.3(dmg-builder@25.0.1)): + app-builder-lib@24.13.3(dmg-builder@25.0.1(electron-builder-squirrel-windows@24.13.3))(electron-builder-squirrel-windows@24.13.3(dmg-builder@25.0.1)): dependencies: '@develar/schema-utils': 2.6.5 '@electron/notarize': 2.2.1 @@ -3455,7 +3461,7 @@ snapshots: builder-util-runtime: 9.2.4 chromium-pickle-js: 0.2.0 debug: 4.3.5 - dmg-builder: 25.0.1(electron-builder-squirrel-windows@24.13.3(dmg-builder@25.0.1)) + dmg-builder: 25.0.1(electron-builder-squirrel-windows@24.13.3) ejs: 3.1.10 electron-builder-squirrel-windows: 24.13.3(dmg-builder@25.0.1) electron-publish: 24.13.1 @@ -3475,7 +3481,7 @@ snapshots: transitivePeerDependencies: - supports-color - app-builder-lib@25.0.1(dmg-builder@25.0.1(electron-builder-squirrel-windows@24.13.3(dmg-builder@25.0.1)))(electron-builder-squirrel-windows@24.13.3(dmg-builder@25.0.1)): + app-builder-lib@25.0.1(dmg-builder@25.0.1(electron-builder-squirrel-windows@24.13.3))(electron-builder-squirrel-windows@24.13.3(dmg-builder@25.0.1)): dependencies: '@develar/schema-utils': 2.6.5 '@electron/notarize': 2.3.2 @@ -3490,7 +3496,7 @@ snapshots: builder-util-runtime: 9.2.5 chromium-pickle-js: 0.2.0 debug: 4.3.5 - dmg-builder: 25.0.1(electron-builder-squirrel-windows@24.13.3(dmg-builder@25.0.1)) + dmg-builder: 25.0.1(electron-builder-squirrel-windows@24.13.3) ejs: 3.1.10 electron-builder-squirrel-windows: 24.13.3(dmg-builder@25.0.1) electron-publish: 25.0.1 @@ -4051,9 +4057,9 @@ snapshots: '@types/react': 17.0.2 moment: 2.30.1 - dmg-builder@25.0.1(electron-builder-squirrel-windows@24.13.3(dmg-builder@25.0.1)): + dmg-builder@25.0.1(electron-builder-squirrel-windows@24.13.3): dependencies: - app-builder-lib: 25.0.1(dmg-builder@25.0.1(electron-builder-squirrel-windows@24.13.3(dmg-builder@25.0.1)))(electron-builder-squirrel-windows@24.13.3(dmg-builder@25.0.1)) + app-builder-lib: 25.0.1(dmg-builder@25.0.1(electron-builder-squirrel-windows@24.13.3))(electron-builder-squirrel-windows@24.13.3(dmg-builder@25.0.1)) builder-util: 25.0.1 builder-util-runtime: 9.2.5 fs-extra: 10.1.0 @@ -4104,7 +4110,7 @@ snapshots: electron-builder-squirrel-windows@24.13.3(dmg-builder@25.0.1): dependencies: - app-builder-lib: 24.13.3(dmg-builder@25.0.1(electron-builder-squirrel-windows@24.13.3(dmg-builder@25.0.1)))(electron-builder-squirrel-windows@24.13.3(dmg-builder@25.0.1)) + app-builder-lib: 24.13.3(dmg-builder@25.0.1(electron-builder-squirrel-windows@24.13.3))(electron-builder-squirrel-windows@24.13.3(dmg-builder@25.0.1)) archiver: 5.3.2 builder-util: 24.13.1 fs-extra: 10.1.0 @@ -4114,11 +4120,11 @@ snapshots: electron-builder@25.0.1(electron-builder-squirrel-windows@24.13.3(dmg-builder@25.0.1)): dependencies: - app-builder-lib: 25.0.1(dmg-builder@25.0.1(electron-builder-squirrel-windows@24.13.3(dmg-builder@25.0.1)))(electron-builder-squirrel-windows@24.13.3(dmg-builder@25.0.1)) + app-builder-lib: 25.0.1(dmg-builder@25.0.1(electron-builder-squirrel-windows@24.13.3))(electron-builder-squirrel-windows@24.13.3(dmg-builder@25.0.1)) builder-util: 25.0.1 builder-util-runtime: 9.2.5 chalk: 4.1.2 - dmg-builder: 25.0.1(electron-builder-squirrel-windows@24.13.3(dmg-builder@25.0.1)) + dmg-builder: 25.0.1(electron-builder-squirrel-windows@24.13.3) fs-extra: 10.1.0 is-ci: 3.0.1 lazy-val: 1.0.5 @@ -5983,6 +5989,8 @@ snapshots: util-deprecate@1.0.2: {} + venbind@0.0.2: {} + verror@1.10.1: dependencies: assert-plus: 1.0.0 diff --git a/scripts/build/build.mts b/scripts/build/build.mts index 243381ba..fa832e35 100644 --- a/scripts/build/build.mts +++ b/scripts/build/build.mts @@ -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")); } diff --git a/src/main/index.ts b/src/main/index.ts index 175eff57..1fe2aeea 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -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(); @@ -88,6 +89,7 @@ function init() { app.whenReady().then(async () => { if (process.platform === "win32") app.setAppUserModelId("dev.vencord.vesktop"); + startVenbind(); registerScreenShareHandler(); registerMediaPermissionsHandler(); diff --git a/src/main/ipc.ts b/src/main/ipc.ts index 6e040857..4fa662c3 100644 --- a/src/main/ipc.ts +++ b/src/main/ipc.ts @@ -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(() => ""); } diff --git a/src/main/venbind.ts b/src/main/venbind.ts new file mode 100644 index 00000000..617b27e5 --- /dev/null +++ b/src/main/venbind.ts @@ -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); +});