Support discord:// uri scheme (#813)

Co-authored-by: v <vendicated@riseup.net>
This commit is contained in:
Cookie
2025-02-05 21:45:20 -05:00
committed by GitHub
parent 6ba562c663
commit 7560727372
3 changed files with 33 additions and 7 deletions

View File

@@ -29,6 +29,8 @@ console.log("Vesktop v" + app.getVersion());
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(",");
@@ -119,6 +121,12 @@ async function bootstrap() {
}
}
// MacOS only event
export let darwinURL: string | undefined;
app.on("open-url", (_, url) => {
darwinURL = url;
});
app.on("window-all-closed", () => {
if (process.platform !== "darwin") app.quit();
});

View File

@@ -36,6 +36,7 @@ import {
MIN_WIDTH,
VENCORD_FILES_DIR
} from "./constants";
import { darwinURL } from "./index";
import { sendRendererCommand } from "./ipcCommands";
import { Settings, State, VencordSettings } from "./settings";
import { createSplashWindow } from "./splash";
@@ -454,18 +455,20 @@ function createMainWindow() {
win.webContents.setUserAgent(BrowserUserAgent);
const subdomain =
Settings.store.discordBranch === "canary" || Settings.store.discordBranch === "ptb"
? `${Settings.store.discordBranch}.`
: "";
win.loadURL(`https://${subdomain}discord.com/app`);
// if the open-url event is fired (in index.ts) while starting up, darwinURL will be set. If not fall back to checking the process args (which Windows and Linux use for URI calling.)
loadUrl(darwinURL || process.argv.find(arg => arg.startsWith("discord://")));
return win;
}
const runVencordMain = once(() => require(join(VENCORD_FILES_DIR, "vencordDesktopMain.js")));
export function loadUrl(uri: string | undefined) {
const branch = Settings.store.discordBranch;
const subdomain = branch === "canary" || branch === "ptb" ? `${branch}.` : "";
mainWin.loadURL(`https://${subdomain}discord.com/${uri ? new URL(uri).pathname.slice(1) || "app" : "app"}`);
}
export async function createWindows() {
const startMinimized = process.argv.includes("--start-minimized");
const splash = createSplashWindow(startMinimized);
@@ -498,5 +501,13 @@ export async function createWindows() {
});
});
mainWin.webContents.on("did-navigate", (_, url: string, responseCode: number) => {
// check url to ensure app doesn't loop
if (responseCode >= 300 && new URL(url).pathname !== `/app`) {
loadUrl(undefined);
console.warn(`'did-navigate': Caught bad page response: ${responseCode}, redirecting to main app`);
}
});
initArRPC();
}