Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support discord uri scheme #813

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@
"package.json",
"LICENSE"
],
"protocols": {
"name": "Discord",
"schemes": [
"discord"
]
},
"beforePack": "scripts/build/sandboxFix.js",
"linux": {
"icon": "build/icon.icns",
Expand Down Expand Up @@ -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": {
Expand Down
2 changes: 2 additions & 0 deletions src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(",");
Expand Down
18 changes: 13 additions & 5 deletions src/main/mainWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"}`);
Covkie marked this conversation as resolved.
Show resolved Hide resolved
};

let uriFiredDarwin = false;
app.on("open-url", (_, url) => {
uriFiredDarwin = true;
Covkie marked this conversation as resolved.
Show resolved Hide resolved
loadUrl(url);
});
uriFiredDarwin || loadUrl(uri);
Covkie marked this conversation as resolved.
Show resolved Hide resolved

return win;
}
Expand Down