diff --git a/src/plugins/keybinds/components/SettingsView.tsx b/src/plugins/keybinds/components/SettingsView.tsx new file mode 100644 index 000000000..3bbe42fc9 --- /dev/null +++ b/src/plugins/keybinds/components/SettingsView.tsx @@ -0,0 +1,80 @@ +/* + * Vencord, a Discord client mod + * Copyright (c) 2025 Vendicated and contributors + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +import "./styles.css"; + +import { Text, TextInput, useState } from "@webpack/common"; + +import { keybinds } from "./keybinds"; +import { CheckboxRow, cl } from "./utils"; + +function keybindStr(key, ctrl, shift, alt) { + return (ctrl ? "Ctrl+" : "") + (shift ? "Shift+" : "") + (alt ? "Alt+" : "") + key; +} + + +function KeybindDetector({ keybindSettings: k }) { + + const [listening, setListening] = useState(false); + + if (!listening) + return ( +
setListening(true)}> + +
+ ); + + return ( +
+ { + e.preventDefault(); + e.stopPropagation(); + if (e.key === "Escape") { + setListening(false); + return; + } + if (e.key === "Control" || e.key === "Shift" || e.key === "Alt") { + return; + } + k.key = e.key.toUpperCase(); + k.ctrl = e.ctrlKey; + k.shift = e.shiftKey; + k.alt = e.altKey; + setListening(false); + }} /> +
+ ); + +} + +function KeybindSettings({ keybind, settings }) { + const keybindData = keybinds[keybind]; + const keybindSettings = settings.store[keybind]; + + return ( +
+ keybindSettings.enabled = !keybindSettings.enabled}> +
+
+ {keybindData.name} + {keybindData.desc} +
+ +
+
+
+ ); +} + +export function SettingsView({ settings }) { + return ( +
+ {Object.keys(keybinds).map(keybind => { + return ; + })} +
+ ); +} diff --git a/src/plugins/keybinds/components/keybinds.tsx b/src/plugins/keybinds/components/keybinds.tsx new file mode 100644 index 000000000..59bca7951 --- /dev/null +++ b/src/plugins/keybinds/components/keybinds.tsx @@ -0,0 +1,58 @@ +/* + * Vencord, a Discord client mod + * Copyright (c) 2025 Vendicated and contributors + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +import { relaunch } from "@utils/native"; + +export const keybinds: { [key: string]: any; } = { + debuggerPause: { + name: "Debugger Pause", + desc: "Pauses the client in using the debugger", + default: { + enabled: false, + key: "F8", + ctrl: false, + alt: false, + shift: false, + }, + action: () => { + // Hi! You've just paused the client. Pressing F8 in DevTools or in the main window will unpause it again. + // It's up to you on what to do, friend. Happy travels! + debugger; + }, + }, + inboxJump: { + name: "Inbox Jump", + desc: "Adds a keybind for the jump button in the inbox", + default: { + enabled: false, + key: ";", + ctrl: true, + alt: false, + shift: false + }, + action: () => { + const btn = document.querySelector( + "div[class^=jumpButton]", + ); + if (btn) btn?.click(); + console.log("Executed"); + } + }, + restart: { + name: "Restart", + desc: "Restarts your discord client", + default: { + enabled: false, + key: "R", + ctrl: true, + shift: true, + alt: false, + }, + action: () => { + relaunch(); + } + } +}; diff --git a/src/plugins/keybinds/components/styles.css b/src/plugins/keybinds/components/styles.css new file mode 100644 index 000000000..ee6ee2410 --- /dev/null +++ b/src/plugins/keybinds/components/styles.css @@ -0,0 +1,12 @@ +.vc-keybinds-settings-row { + padding: 3px; +} + +.vc-keybinds-settings-row-content { + display: flex; + flex-direction: row; + align-items: center; + justify-content: space-between; + width: 100%; + height: 100%; +} diff --git a/src/plugins/keybinds/components/utils.ts b/src/plugins/keybinds/components/utils.ts new file mode 100644 index 000000000..4e6754ed8 --- /dev/null +++ b/src/plugins/keybinds/components/utils.ts @@ -0,0 +1,13 @@ +/* + * Vencord, a Discord client mod + * Copyright (c) 2025 Vendicated and contributors + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +import { classNameFactory } from "@api/Styles"; +import { findComponentByCodeLazy } from "@webpack"; + +export const cl = classNameFactory("vc-keybinds-"); +export const CheckboxRow = findComponentByCodeLazy(".labelReversed"); + +