implement global shortcuts with electron api

This commit is contained in:
Vendicated
2026-04-04 23:10:11 +02:00
parent c32e16e740
commit d179b621a7
12 changed files with 454 additions and 27 deletions
+35
View File
@@ -0,0 +1,35 @@
/*
* Vesktop, a desktop app aiming to give you a snappier Discord Experience
* Copyright (c) 2026 Vendicated and Vesktop contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/
import { app, globalShortcut } from "electron";
import { IpcCommands } from "shared/IpcEvents";
import { sendRendererCommand } from "./ipcCommands";
import { Settings } from "./settings";
function unregisterKeyBinds() {
globalShortcut.unregisterAll();
}
export async function registerKeyBinds() {
await app.whenReady();
unregisterKeyBinds();
for (const { action, enabled, key } of Settings.store.keyBinds || []) {
if (!enabled || !key || action === "unassigned") continue;
console.log(
key,
"SUCCESS",
globalShortcut.register(key, () => sendRendererCommand(IpcCommands.HANDLE_KEY_BIND, action))
);
}
}
Settings.addChangeListener("keyBinds", registerKeyBinds);
app.on("will-quit", unregisterKeyBinds);