From f98309c7b744ab0a6b129824eec9cc2f9f2d48e9 Mon Sep 17 00:00:00 2001 From: Vendicated Date: Tue, 10 Jun 2025 17:16:26 +0200 Subject: [PATCH] fix random logouts (Discord shitcode moment) --- src/main/mainWindow.ts | 10 ++++++ src/preload/VesktopNative.ts | 12 ++++++- src/renderer/patches/allowDevToolsKeybind.ts | 19 ----------- src/renderer/patches/devtoolsFixes.ts | 36 ++++++++++++++++++++ src/shared/IpcEvents.ts | 5 ++- 5 files changed, 61 insertions(+), 21 deletions(-) delete mode 100644 src/renderer/patches/allowDevToolsKeybind.ts create mode 100644 src/renderer/patches/devtoolsFixes.ts diff --git a/src/main/mainWindow.ts b/src/main/mainWindow.ts index 14f7561..762d39b 100644 --- a/src/main/mainWindow.ts +++ b/src/main/mainWindow.ts @@ -388,6 +388,15 @@ function initSpellCheck(win: BrowserWindow) { initSpellCheckLanguages(win, Settings.store.spellCheckLanguages); } +function initDevtoolsListeners(win: BrowserWindow) { + win.webContents.on("devtools-opened", () => { + win.webContents.send(IpcEvents.DEVTOOLS_OPENED); + }); + win.webContents.on("devtools-closed", () => { + win.webContents.send(IpcEvents.DEVTOOLS_CLOSED); + }); +} + function initStaticTitle(win: BrowserWindow) { const listener = (e: { preventDefault: Function }) => e.preventDefault(); @@ -473,6 +482,7 @@ function createMainWindow() { makeLinksOpenExternally(win); initSettingsListeners(win); initSpellCheck(win); + initDevtoolsListeners(win); initStaticTitle(win); win.webContents.setUserAgent(BrowserUserAgent); diff --git a/src/preload/VesktopNative.ts b/src/preload/VesktopNative.ts index 8aee1e7..1525965 100644 --- a/src/preload/VesktopNative.ts +++ b/src/preload/VesktopNative.ts @@ -20,6 +20,12 @@ ipcRenderer.on(IpcEvents.SPELLCHECK_RESULT, (_, w: string, s: string[]) => { spellCheckCallbacks.forEach(cb => cb(w, s)); }); +let onDevtoolsOpen = () => {}; +let onDevtoolsClose = () => {}; + +ipcRenderer.on(IpcEvents.DEVTOOLS_OPENED, () => onDevtoolsOpen()); +ipcRenderer.on(IpcEvents.DEVTOOLS_CLOSED, () => onDevtoolsClose()); + export const VesktopNative = { app: { relaunch: () => invoke(IpcEvents.RELAUNCH), @@ -57,7 +63,11 @@ export const VesktopNative = { focus: () => invoke(IpcEvents.FOCUS), close: (key?: string) => invoke(IpcEvents.CLOSE, key), minimize: (key?: string) => invoke(IpcEvents.MINIMIZE, key), - maximize: (key?: string) => invoke(IpcEvents.MAXIMIZE, key) + maximize: (key?: string) => invoke(IpcEvents.MAXIMIZE, key), + setDevtoolsCallbacks: (onOpen: () => void, onClose: () => void) => { + onDevtoolsOpen = onOpen; + onDevtoolsClose = onClose; + } }, capturer: { getLargeThumbnail: (id: string) => invoke(IpcEvents.CAPTURER_GET_LARGE_THUMBNAIL, id) diff --git a/src/renderer/patches/allowDevToolsKeybind.ts b/src/renderer/patches/allowDevToolsKeybind.ts deleted file mode 100644 index 59698e2..0000000 --- a/src/renderer/patches/allowDevToolsKeybind.ts +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Vesktop, a desktop app aiming to give you a snappier Discord Experience - * Copyright (c) 2025 Vendicated and Vesktop contributors - * SPDX-License-Identifier: GPL-3.0-or-later - */ - -import { addPatch } from "./shared"; - -addPatch({ - patches: [ - { - find: '"mod+alt+i"', - replacement: { - match: /"discord\.com"===location\.host/, - replace: "false" - } - } - ] -}); diff --git a/src/renderer/patches/devtoolsFixes.ts b/src/renderer/patches/devtoolsFixes.ts new file mode 100644 index 0000000..59fb853 --- /dev/null +++ b/src/renderer/patches/devtoolsFixes.ts @@ -0,0 +1,36 @@ +/* + * Vesktop, a desktop app aiming to give you a snappier Discord Experience + * Copyright (c) 2025 Vendicated and Vesktop contributors + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +import { addPatch } from "./shared"; + +addPatch({ + patches: [ + // Discord Web blocks the devtools keybin on mac specifically, disable that + { + find: '"mod+alt+i"', + replacement: { + match: /"discord\.com"===location\.host/, + replace: "false" + } + }, + { + find: ".setDevtoolsCallbacks(", + group: true, + replacement: [ + { + // eslint-disable-next-line no-useless-escape + match: /if\(null!=(\i)\)(?=.{0,50}\1\.window\.setDevtoolsCallbacks)/, + replace: "if(true)" + }, + { + // eslint-disable-next-line no-useless-escape + match: /\b\i\.window\b/g, + replace: "VesktopNative.win" + } + ] + } + ] +}); diff --git a/src/shared/IpcEvents.ts b/src/shared/IpcEvents.ts index faae369..1097989 100644 --- a/src/shared/IpcEvents.ts +++ b/src/shared/IpcEvents.ts @@ -56,7 +56,10 @@ export const enum IpcEvents { DEBUG_LAUNCH_GPU = "VCD_DEBUG_LAUNCH_GPU", DEBUG_LAUNCH_WEBRTC_INTERNALS = "VCD_DEBUG_LAUNCH_WEBRTC", - IPC_COMMAND = "VCD_IPC_COMMAND" + IPC_COMMAND = "VCD_IPC_COMMAND", + + DEVTOOLS_OPENED = "VCD_DEVTOOLS_OPENED", + DEVTOOLS_CLOSED = "VCD_DEVTOOLS_CLOSED" } export const enum IpcCommands {