diff --git a/src/main/index.ts b/src/main/index.ts index f583113..ee00269 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -15,6 +15,7 @@ import { createWindows, mainWin } from "./mainWindow"; import { registerMediaPermissionsHandler } from "./mediaPermissions"; import { registerScreenShareHandler } from "./screenShare"; import { Settings, State } from "./settings"; +import { setAsDefaultProtocolClient } from "./utils/setAsDefaultProtocolClient"; import { isDeckGameMode } from "./utils/steamOS"; if (!IS_DEV) { @@ -31,7 +32,7 @@ const isLinux = process.platform === "linux"; export let enableHardwareAcceleration = true; function init() { - app.setAsDefaultProtocolClient("discord"); + setAsDefaultProtocolClient("discord"); const { disableSmoothScroll, hardwareAcceleration, hardwareVideoAcceleration } = Settings.store; diff --git a/src/main/utils/setAsDefaultProtocolClient.ts b/src/main/utils/setAsDefaultProtocolClient.ts new file mode 100644 index 0000000..c4b3580 --- /dev/null +++ b/src/main/utils/setAsDefaultProtocolClient.ts @@ -0,0 +1,29 @@ +/* + * 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 { execFile } from "child_process"; +import { app } from "electron"; + +export async function setAsDefaultProtocolClient(protocol: string) { + if (process.platform !== "linux") { + return app.setAsDefaultProtocolClient(protocol); + } + + // electron setAsDefaultProtocolClient uses xdg-settings instead of xdg-mime. + // xdg-settings had a bug where it would also register the app as a handler for text/html, + // aka become your browser. This bug was fixed years ago (xdg-utils 1.2.0) but Ubuntu ships + // 7 (YES, SEVEN) years out of date xdg-utils which STILL has the bug. + // FIXME: remove this workaround when Ubuntu updates their xdg-utils or electron switches to xdg-mime. + + const { CHROME_DESKTOP } = process.env; + if (!CHROME_DESKTOP) return false; + + return new Promise(resolve => { + execFile("xdg-mime", ["default", CHROME_DESKTOP, `x-scheme-handler/${protocol}`], err => { + resolve(err == null); + }); + }); +}