implement shortcuts and add cli trigger argument

This commit is contained in:
Vendicated
2026-04-05 01:28:54 +02:00
parent d179b621a7
commit f3e01c2ba4
4 changed files with 55 additions and 6 deletions
+15 -1
View File
@@ -6,6 +6,7 @@
import { app } from "electron"; import { app } from "electron";
import { basename } from "path"; import { basename } from "path";
import { ShortcutAction } from "renderer/globalShortcuts/ShortcutSettings";
import { stripIndent } from "shared/utils/text"; import { stripIndent } from "shared/utils/text";
import { parseArgs, ParseArgsOptionDescriptor } from "util"; import { parseArgs, ParseArgsOptionDescriptor } from "util";
@@ -42,6 +43,19 @@ const options = {
type: "string", type: "string",
description: "Set User-Agent to a specific operating system. May trigger anti-spam or break voice chat", description: "Set User-Agent to a specific operating system. May trigger anti-spam or break voice chat",
options: ["windows", "linux", "darwin"] options: ["windows", "linux", "darwin"]
},
"run-shortcut": {
type: "string",
description:
"Run a predefined shortcut action (for custom key binds). Vesktop has to be open for this to have any effect",
options: [
"toggleMute",
"toggleDeafen",
"toggleStreamerMode",
"toggleCamera",
"toggleScreenShare",
"disconnectFromVoiceChannel"
] satisfies Array<ShortcutAction>
} }
} satisfies Record<string, Option>; } satisfies Record<string, Option>;
@@ -135,7 +149,7 @@ export function checkCommandLineForHelpOrVersion() {
app.exit(1); app.exit(1);
} }
if ("options" in def && !def.options?.includes(value as string)) { if ("options" in def && !def.options?.includes(value as any)) {
console.error(`Invalid value for --${name}: ${value}\nExpected one of: ${def.options.join(", ")}`); console.error(`Invalid value for --${name}: ${value}\nExpected one of: ${def.options.join(", ")}`);
app.exit(1); app.exit(1);
} }
+12 -1
View File
@@ -11,9 +11,13 @@ import "./userAssets";
import "./vesktopProtocol"; import "./vesktopProtocol";
import { app, BrowserWindow, nativeTheme } from "electron"; import { app, BrowserWindow, nativeTheme } from "electron";
import { IpcCommands } from "shared/IpcEvents";
// eslint-disable-next-line no-duplicate-imports
import { CommandLine } from "./cli";
import { DATA_DIR } from "./constants"; import { DATA_DIR } from "./constants";
import { createFirstLaunchTour } from "./firstLaunch"; import { createFirstLaunchTour } from "./firstLaunch";
import { sendRendererCommand } from "./ipcCommands";
import { registerKeyBinds } from "./keyBinds"; import { registerKeyBinds } from "./keyBinds";
import { createWindows, mainWin } from "./mainWindow"; import { createWindows, mainWin } from "./mainWindow";
import { registerMediaPermissionsHandler } from "./mediaPermissions"; import { registerMediaPermissionsHandler } from "./mediaPermissions";
@@ -129,7 +133,7 @@ function init() {
}); });
} }
if (!app.requestSingleInstanceLock({ IS_DEV })) { if (!app.requestSingleInstanceLock({ IS_DEV, args: CommandLine })) {
if (IS_DEV) { if (IS_DEV) {
console.log("Vesktop is already running. Quitting previous instance..."); console.log("Vesktop is already running. Quitting previous instance...");
init(); init();
@@ -158,3 +162,10 @@ app.on("open-url", (_, url) => {
app.on("window-all-closed", () => { app.on("window-all-closed", () => {
if (process.platform !== "darwin") app.quit(); if (process.platform !== "darwin") app.quit();
}); });
app.on("second-instance", (_e, _argv, _cwd, data) => {
const { args } = data as { args: typeof CommandLine; IS_DEV: boolean };
const { "run-shortcut": shortcut } = args.values;
if (shortcut) sendRendererCommand(IpcCommands.HANDLE_KEY_BIND, shortcut);
});
+2
View File
@@ -11,6 +11,8 @@ import { sendRendererCommand } from "./ipcCommands";
import { Settings } from "./settings"; import { Settings } from "./settings";
function unregisterKeyBinds() { function unregisterKeyBinds() {
if (!app.isReady()) return;
globalShortcut.unregisterAll(); globalShortcut.unregisterAll();
} }
+26 -4
View File
@@ -5,29 +5,51 @@
*/ */
import { Logger } from "@vencord/types/utils"; import { Logger } from "@vencord/types/utils";
import { findByPropsLazy } from "@vencord/types/webpack";
import { FluxDispatcher, StreamerModeStore } from "@vencord/types/webpack/common";
import { ShortcutAction } from "./ShortcutSettings"; import { ShortcutAction } from "./ShortcutSettings";
const logger = new Logger("VesktopKeyBindHandler"); const logger = new Logger("VesktopKeyBindHandler");
const { selectVoiceChannel } = findByPropsLazy("selectVoiceChannel");
export function handleKeyBind(keyBind: ShortcutAction) { export function handleKeyBind(keyBind: ShortcutAction) {
logger.debug(`Handling key bind action: ${keyBind}`); logger.debug(`Handling key bind action: ${keyBind}`);
switch (keyBind) { switch (keyBind) {
case "toggleMute": case "toggleMute":
FluxDispatcher.dispatch({
type: "AUDIO_TOGGLE_SELF_MUTE",
context: "default",
syncRemote: true,
playSoundEffect: true
});
break; break;
case "toggleDeafen": case "toggleDeafen":
FluxDispatcher.dispatch({
type: "AUDIO_TOGGLE_SELF_DEAF",
context: "default",
syncRemote: true
});
break; break;
case "toggleStreamerMode": case "toggleStreamerMode":
FluxDispatcher.dispatch({
type: "STREAMER_MODE_UPDATE",
key: "enabled",
value: !StreamerModeStore.enabled
});
break; break;
case "toggleCamera":
break;
case "toggleScreenShare":
break;
case "disconnectFromVoiceChannel": case "disconnectFromVoiceChannel":
selectVoiceChannel(null);
break; break;
case "unassigned": case "unassigned":
break; break;
default: default:
logger.warn(`Unknown key bind action: ${keyBind}`); logger.warn(`Unknown key bind action: ${keyBind}`);
} }