diff --git a/src/main/ipc.ts b/src/main/ipc.ts index 4fa662c..a438206 100644 --- a/src/main/ipc.ts +++ b/src/main/ipc.ts @@ -18,7 +18,7 @@ import { IpcEvents } from "../shared/IpcEvents"; import { setBadgeCount } from "./appBadge"; import { autoStart } from "./autoStart"; import { VENCORD_FILES_DIR, VENCORD_QUICKCSS_FILE, VENCORD_THEMES_DIR } from "./constants"; -import { mainWin } from "./mainWindow"; +import { loadUrl, mainWin } from "./mainWindow"; import { Settings, State } from "./settings"; import { handle, handleSync } from "./utils/ipcWrappers"; import { PopoutWindows } from "./utils/popout"; @@ -135,6 +135,11 @@ handle(IpcEvents.CLIPBOARD_COPY_IMAGE, async (_, buf: ArrayBuffer, src: string) }); }); +handle(IpcEvents.FOUROHFOUR_PAGE_HANDLER, _ => { + loadUrl(undefined); + console.warn("caught incomplete uri scheme. dumping to main app"); +}); + function readCss() { return readFile(VENCORD_QUICKCSS_FILE, "utf-8").catch(() => ""); } diff --git a/src/main/mainWindow.ts b/src/main/mainWindow.ts index 59ea2c7..626582f 100644 --- a/src/main/mainWindow.ts +++ b/src/main/mainWindow.ts @@ -455,25 +455,26 @@ function createMainWindow() { win.webContents.setUserAgent(BrowserUserAgent); - const branch = Settings.store.discordBranch; - const subdomain = branch === "canary" || branch === "ptb" ? `${branch}.` : ""; - const uri = process.argv.find(arg => arg.startsWith("discord://")); - - const loadUrl = (url: string | undefined) => { - win.loadURL(`https://${subdomain}discord.com/${url?.replace(RegExp("^discord://[^/]*/?"), "") || "app"}`); - }; - let uriFiredDarwin = false; app.on("open-url", (_, url) => { uriFiredDarwin ? restoreVesktop() : loadUrl(url); uriFiredDarwin = true; }); + + const uri = process.argv.find(arg => arg.startsWith("discord://")); uriFiredDarwin || loadUrl(uri); + 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?.replace(RegExp("^discord://[^/]*/?"), "") || "app"}`); +} + export function restoreVesktop() { if (mainWin) { if (mainWin.isMinimized()) mainWin.restore(); diff --git a/src/preload/index.ts b/src/preload/index.ts index 75bf9cd..5aa63ad 100644 --- a/src/preload/index.ts +++ b/src/preload/index.ts @@ -24,6 +24,10 @@ const style = document.createElement("style"); style.id = "vcd-css-core"; style.textContent = readFileSync(rendererCss, "utf-8"); +document.addEventListener("DOMContentLoaded", () => { + if (document.title === "Page Not Found | Discord") ipcRenderer.invoke(IpcEvents.FOUROHFOUR_PAGE_HANDLER); +}); + if (document.readyState === "complete") { document.documentElement.appendChild(style); } else { diff --git a/src/shared/IpcEvents.ts b/src/shared/IpcEvents.ts index 51d2a28..0843a47 100644 --- a/src/shared/IpcEvents.ts +++ b/src/shared/IpcEvents.ts @@ -50,5 +50,7 @@ export const enum IpcEvents { ARRPC_ACTIVITY = "VCD_ARRPC_ACTIVITY", - CLIPBOARD_COPY_IMAGE = "VCD_CLIPBOARD_COPY_IMAGE" + CLIPBOARD_COPY_IMAGE = "VCD_CLIPBOARD_COPY_IMAGE", + + FOUROHFOUR_PAGE_HANDLER = "VCD_404_PAGE_HANDLER" }