From 60d6c84542fadb6055b1d2d50a5eaf9ffa15cbbc Mon Sep 17 00:00:00 2001 From: Kylie C Date: Tue, 13 Aug 2024 01:45:31 -0400 Subject: [PATCH] Support discord uri scheme closes: #769 --- package.json | 9 ++++++++- src/main/index.ts | 2 ++ src/main/mainWindow.ts | 18 +++++++++++++----- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index ca5cf49..b850985 100644 --- a/package.json +++ b/package.json @@ -72,6 +72,12 @@ "package.json", "LICENSE" ], + "protocols": { + "name": "Discord", + "schemes": [ + "discord" + ] + }, "beforePack": "scripts/build/sandboxFix.js", "linux": { "icon": "build/icon.icns", @@ -112,7 +118,8 @@ "GenericName": "Internet Messenger", "Type": "Application", "Categories": "Network;InstantMessaging;Chat;", - "Keywords": "discord;vencord;electron;chat;" + "Keywords": "discord;vencord;electron;chat;", + "MimeType": "x-scheme-handler/discord" } }, "mac": { diff --git a/src/main/index.ts b/src/main/index.ts index 2e0d6f7..4df2ad7 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -27,6 +27,8 @@ if (IS_DEV) { process.env.VENCORD_USER_DATA_DIR = DATA_DIR; function init() { + app.setAsDefaultProtocolClient("discord"); + const { disableSmoothScroll, hardwareAcceleration } = Settings.store; const enabledFeatures = app.commandLine.getSwitchValue("enable-features").split(","); diff --git a/src/main/mainWindow.ts b/src/main/mainWindow.ts index d860b37..bf462e5 100644 --- a/src/main/mainWindow.ts +++ b/src/main/mainWindow.ts @@ -455,12 +455,20 @@ function createMainWindow() { win.webContents.setUserAgent(BrowserUserAgent); - const subdomain = - Settings.store.discordBranch === "canary" || Settings.store.discordBranch === "ptb" - ? `${Settings.store.discordBranch}.` - : ""; + const branch = Settings.store.discordBranch; + const subdomain = branch === "canary" || branch === "ptb" ? `${branch}.` : ""; + const uri = process.argv.find(arg => arg.startsWith("discord://")); - win.loadURL(`https://${subdomain}discord.com/app`); + const loadUrl = (url: string | undefined) => { + win.loadURL(`https://${subdomain}discord.com${url?.substring("discord://".length) || "/app"}`); + }; + + let uriFiredDarwin = false; + app.on("open-url", (_, url) => { + uriFiredDarwin = true; + loadUrl(url); + }); + uriFiredDarwin || loadUrl(uri); return win; }