From 38f0330eb24c778326ed930c3e2294d011758319 Mon Sep 17 00:00:00 2001 From: Vendicated Date: Mon, 15 Jan 2024 17:56:33 +0100 Subject: [PATCH] Fix adding connections & popout on ptb/canary --- src/main/utils/makeLinksOpenExternally.ts | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/main/utils/makeLinksOpenExternally.ts b/src/main/utils/makeLinksOpenExternally.ts index 5197261..c58bad1 100644 --- a/src/main/utils/makeLinksOpenExternally.ts +++ b/src/main/utils/makeLinksOpenExternally.ts @@ -9,20 +9,22 @@ import { BrowserWindow, shell } from "electron"; import { Settings } from "../settings"; import { execSteamURL, isDeckGameMode, steamOpenURL } from "./steamOS"; +const DISCORD_HOSTNAMES = ["discord.com", "canary.discord.com", "ptb.discord.com"]; export function makeLinksOpenExternally(win: BrowserWindow) { - win.webContents.setWindowOpenHandler(({ url }) => { - switch (url) { - case "about:blank": - case "https://discord.com/popout": - return { action: "allow" }; - } - + win.webContents.setWindowOpenHandler(({ url, frameName }) => { try { - var { protocol } = new URL(url); + var { protocol, hostname, pathname } = new URL(url); } catch { return { action: "deny" }; } + if ( + url === "about:blank" || + (pathname === "/popout" && DISCORD_HOSTNAMES.includes(hostname)) || + (frameName === "authorize" && DISCORD_HOSTNAMES.includes(hostname)) + ) + return { action: "allow" }; + switch (protocol) { case "http:": case "https:":