mirror of
https://github.com/Vencord/Vesktop.git
synced 2026-11-20 00:51:15 -08:00
Add global shortcuts/keybinds (#1238)
Co-authored-by: Kylie C <[email protected]> Assisted-by: Claude Opus 5.5
This commit is contained in:
1 parent
857db4313f
commit
e45a1027ef
29 files changed
+2025
-25
No files matched your search
+53
-12
@@ -6,7 +6,7 @@
|
||||
|
||||
import { copyFile, rm } from "fs/promises";
|
||||
|
||||
import { BuildContext, BuildOptions, context } from "esbuild";
|
||||
import { BuildContext, BuildOptions, context, Plugin } from "esbuild";
|
||||
|
||||
import { includeDirPlugin } from "./includeDirPlugin.mts";
|
||||
import vencordDep from "./vencordDep.mjs";
|
||||
@@ -34,6 +34,29 @@ const NodeCommonOpts: BuildOptions = {
|
||||
}
|
||||
};
|
||||
|
||||
// uiohook-napi finds its binary with node-gyp-build, so point that at the copy in static/dist (see copyUiohook)
|
||||
const uiohookBinaryPlugin: Plugin = {
|
||||
name: "uiohook-binary",
|
||||
setup(build) {
|
||||
build.onResolve({ filter: /^node-gyp-build$/ }, args => {
|
||||
if (args.importer.includes("uiohook-napi")) return { path: "uiohook-binary", namespace: "uiohook-binary" };
|
||||
});
|
||||
build.onLoad({ filter: /.*/, namespace: "uiohook-binary" }, () => ({
|
||||
contents: `
|
||||
const { join } = require("path");
|
||||
module.exports = () => require(join(__dirname, "../../static/dist/uiohook-napi-" + process.arch + ".node"));
|
||||
`,
|
||||
loader: "js"
|
||||
}));
|
||||
}
|
||||
};
|
||||
|
||||
// Overwriting in place crashes a running instance, as the addon is mapped into memory, so replace the file instead
|
||||
async function copyNativeModule(src: string, dest: string) {
|
||||
await rm(dest, { force: true });
|
||||
await copyFile(src, dest);
|
||||
}
|
||||
|
||||
const contexts = [] as BuildContext[];
|
||||
async function createContext(options: BuildOptions) {
|
||||
contexts.push(await context(options));
|
||||
@@ -43,27 +66,40 @@ async function copyVenmic() {
|
||||
if (process.platform !== "linux") return;
|
||||
|
||||
return Promise.all([
|
||||
copyFile(
|
||||
copyNativeModule(
|
||||
"./node_modules/@vencord/venmic/prebuilds/venmic-addon-linux-x64/node-napi-v7.node",
|
||||
"./static/dist/venmic-x64.node"
|
||||
),
|
||||
copyFile(
|
||||
copyNativeModule(
|
||||
"./node_modules/@vencord/venmic/prebuilds/venmic-addon-linux-arm64/node-napi-v7.node",
|
||||
"./static/dist/venmic-arm64.node"
|
||||
)
|
||||
]).catch(() => console.warn("Failed to copy venmic. Building without venmic support"));
|
||||
}
|
||||
|
||||
async function copyUiohook() {
|
||||
const prebuilds = "./node_modules/uiohook-napi/prebuilds";
|
||||
|
||||
return Promise.all(
|
||||
["x64", "arm64"].map(arch =>
|
||||
copyNativeModule(
|
||||
`${prebuilds}/${process.platform}-${arch}/uiohook-napi.node`,
|
||||
`./static/dist/uiohook-napi-${arch}.node`
|
||||
)
|
||||
)
|
||||
).catch(() => console.warn("Failed to copy uiohook. Building without global keybind support"));
|
||||
}
|
||||
|
||||
async function copyGameDetection() {
|
||||
const prebuilds = "./node_modules/@vencord/game-detection/prebuilds";
|
||||
|
||||
return Promise.all(
|
||||
["x64", "arm64"].map(async arch => {
|
||||
const dest = `./static/dist/game-detection-${arch}.node`;
|
||||
// Overwriting in place crashes a running instance, as the addon is mapped into memory
|
||||
await rm(dest, { force: true });
|
||||
await copyFile(`${prebuilds}/${process.platform}-${arch}/rpc_native.node`, dest);
|
||||
})
|
||||
["x64", "arm64"].map(arch =>
|
||||
copyNativeModule(
|
||||
`${prebuilds}/${process.platform}-${arch}/rpc_native.node`,
|
||||
`./static/dist/game-detection-${arch}.node`
|
||||
)
|
||||
)
|
||||
).catch(() => console.warn("Failed to copy game detection. Building without game detection support"));
|
||||
}
|
||||
|
||||
@@ -71,7 +107,7 @@ async function copyLibVesktop() {
|
||||
if (process.platform !== "linux") return;
|
||||
|
||||
try {
|
||||
await copyFile(
|
||||
await copyNativeModule(
|
||||
"./packages/libvesktop/build/Release/vesktop.node",
|
||||
`./static/dist/libvesktop-${process.arch}.node`
|
||||
);
|
||||
@@ -81,8 +117,11 @@ async function copyLibVesktop() {
|
||||
"Using prebuilt libvesktop binaries. Run `pnpm buildLibVesktop` and build again to build from source - see README.md for more details"
|
||||
);
|
||||
return Promise.all([
|
||||
copyFile("./packages/libvesktop/prebuilds/vesktop-x64.node", "./static/dist/libvesktop-x64.node"),
|
||||
copyFile("./packages/libvesktop/prebuilds/vesktop-arm64.node", "./static/dist/libvesktop-arm64.node")
|
||||
copyNativeModule("./packages/libvesktop/prebuilds/vesktop-x64.node", "./static/dist/libvesktop-x64.node"),
|
||||
copyNativeModule(
|
||||
"./packages/libvesktop/prebuilds/vesktop-arm64.node",
|
||||
"./static/dist/libvesktop-arm64.node"
|
||||
)
|
||||
]).catch(() => console.warn("Failed to copy libvesktop. Building without libvesktop support"));
|
||||
}
|
||||
}
|
||||
@@ -91,9 +130,11 @@ await Promise.all([
|
||||
copyVenmic(),
|
||||
copyLibVesktop(),
|
||||
copyGameDetection(),
|
||||
copyUiohook(),
|
||||
createContext({
|
||||
...NodeCommonOpts,
|
||||
entryPoints: ["src/main/index.ts"],
|
||||
plugins: [uiohookBinaryPlugin],
|
||||
outfile: "dist/js/main.js",
|
||||
footer: { js: "//# sourceURL=VesktopMain" }
|
||||
}),
|
||||
|
||||
Reference in new issue
Block a user