Support discord uri scheme

closes: #769
This commit is contained in:
Kylie C 2024-08-13 01:45:31 -04:00
parent af9ed58eef
commit 60d6c84542
3 changed files with 23 additions and 6 deletions

View file

@ -72,6 +72,12 @@
"package.json", "package.json",
"LICENSE" "LICENSE"
], ],
"protocols": {
"name": "Discord",
"schemes": [
"discord"
]
},
"beforePack": "scripts/build/sandboxFix.js", "beforePack": "scripts/build/sandboxFix.js",
"linux": { "linux": {
"icon": "build/icon.icns", "icon": "build/icon.icns",
@ -112,7 +118,8 @@
"GenericName": "Internet Messenger", "GenericName": "Internet Messenger",
"Type": "Application", "Type": "Application",
"Categories": "Network;InstantMessaging;Chat;", "Categories": "Network;InstantMessaging;Chat;",
"Keywords": "discord;vencord;electron;chat;" "Keywords": "discord;vencord;electron;chat;",
"MimeType": "x-scheme-handler/discord"
} }
}, },
"mac": { "mac": {

View file

@ -27,6 +27,8 @@ if (IS_DEV) {
process.env.VENCORD_USER_DATA_DIR = DATA_DIR; process.env.VENCORD_USER_DATA_DIR = DATA_DIR;
function init() { function init() {
app.setAsDefaultProtocolClient("discord");
const { disableSmoothScroll, hardwareAcceleration } = Settings.store; const { disableSmoothScroll, hardwareAcceleration } = Settings.store;
const enabledFeatures = app.commandLine.getSwitchValue("enable-features").split(","); const enabledFeatures = app.commandLine.getSwitchValue("enable-features").split(",");

View file

@ -455,12 +455,20 @@ function createMainWindow() {
win.webContents.setUserAgent(BrowserUserAgent); win.webContents.setUserAgent(BrowserUserAgent);
const subdomain = const branch = Settings.store.discordBranch;
Settings.store.discordBranch === "canary" || Settings.store.discordBranch === "ptb" const subdomain = branch === "canary" || branch === "ptb" ? `${branch}.` : "";
? `${Settings.store.discordBranch}.` 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; return win;
} }