From fc16fc5404aff620a72288fc8100cf15ddce4cdc Mon Sep 17 00:00:00 2001 From: Vendicated Date: Wed, 14 May 2025 05:25:52 +0200 Subject: [PATCH] Fix not launching on GNOME Reference: https://github.com/electron/electron/issues/46538 Also improves the chromium switch code --- src/main/index.ts | 43 +++++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/src/main/index.ts b/src/main/index.ts index f1bc617..78499bb 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -28,23 +28,26 @@ console.log("Vesktop v" + app.getVersion()); // Make the Vencord files use our DATA_DIR process.env.VENCORD_USER_DATA_DIR = DATA_DIR; +const isLinux = process.platform === "linux"; + function init() { app.setAsDefaultProtocolClient("discord"); const { disableSmoothScroll, hardwareAcceleration } = Settings.store; - const enabledFeatures = app.commandLine.getSwitchValue("enable-features").split(","); - const disabledFeatures = app.commandLine.getSwitchValue("disable-features").split(","); + const enabledFeatures = new Set(app.commandLine.getSwitchValue("enable-features").split(",")); + const disabledFeatures = new Set(app.commandLine.getSwitchValue("disable-features").split(",")); if (hardwareAcceleration === false) { app.disableHardwareAcceleration(); } else { - enabledFeatures.push( - "AcceleratedVideoDecodeLinuxGL", - "AcceleratedVideoEncoder", - "AcceleratedVideoDecoder", - "AcceleratedVideoDecodeLinuxZeroCopyGL" - ); + enabledFeatures.add("AcceleratedVideoEncoder"); + enabledFeatures.add("AcceleratedVideoDecoder"); + + if (isLinux) { + enabledFeatures.add("AcceleratedVideoDecodeLinuxGL"); + enabledFeatures.add("AcceleratedVideoDecodeLinuxZeroCopyGL"); + } } if (disableSmoothScroll) { @@ -58,22 +61,34 @@ function init() { app.commandLine.appendSwitch("disable-background-timer-throttling"); app.commandLine.appendSwitch("disable-backgrounding-occluded-windows"); if (process.platform === "win32") { - disabledFeatures.push("CalculateNativeWinOcclusion"); + disabledFeatures.add("CalculateNativeWinOcclusion"); } // work around chrome 66 disabling autoplay by default app.commandLine.appendSwitch("autoplay-policy", "no-user-gesture-required"); + // WinRetrieveSuggestionsOnlyOnDemand: Work around electron 13 bug w/ async spellchecking on Windows. // HardwareMediaKeyHandling,MediaSessionService: Prevent Discord from registering as a media service. // // WidgetLayering (Vencord Added): Fix DevTools context menus https://github.com/electron/electron/issues/38790 - disabledFeatures.push("WinRetrieveSuggestionsOnlyOnDemand", "HardwareMediaKeyHandling", "MediaSessionService"); + disabledFeatures.add("WinRetrieveSuggestionsOnlyOnDemand"); + disabledFeatures.add("HardwareMediaKeyHandling"); + disabledFeatures.add("MediaSessionService"); - // Support TTS on Linux using speech-dispatcher - app.commandLine.appendSwitch("enable-speech-dispatcher"); + if (isLinux) { + // Support TTS on Linux using https://wiki.archlinux.org/title/Speech_dispatcher + app.commandLine.appendSwitch("enable-speech-dispatcher"); - app.commandLine.appendSwitch("enable-features", [...new Set(enabledFeatures)].filter(Boolean).join(",")); - app.commandLine.appendSwitch("disable-features", [...new Set(disabledFeatures)].filter(Boolean).join(",")); + // Work around Gtk-ERROR: GTK 2/3 symbols detected. Using GTK 2/3 and GTK 4 in the same process is not supported + // https://github.com/electron/electron/issues/46538 + // TODO: Remove this when upstream fixes it + app.commandLine.appendSwitch("gtk-version", "3"); + } + + disabledFeatures.forEach(feat => enabledFeatures.delete(feat)); + + app.commandLine.appendSwitch("enable-features", [...enabledFeatures].filter(Boolean).join(",")); + app.commandLine.appendSwitch("disable-features", [...disabledFeatures].filter(Boolean).join(",")); // In the Flatpak on SteamOS the theme is detected as light, but SteamOS only has a dark mode, so we just override it if (isDeckGameMode) nativeTheme.themeSource = "dark";