From 59e51d3f8a20602d88a0d75471957d517979ec24 Mon Sep 17 00:00:00 2001 From: Kylie C Date: Mon, 14 Oct 2024 17:30:32 -0400 Subject: [PATCH] not insane bad response handler --- src/main/ipc.ts | 7 +------ src/main/mainWindow.ts | 10 +++++++++- src/preload/index.ts | 4 ---- src/shared/IpcEvents.ts | 4 +--- 4 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/main/ipc.ts b/src/main/ipc.ts index 0d0a772..4fa662c 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 { loadUrl, mainWin } from "./mainWindow"; +import { mainWin } from "./mainWindow"; import { Settings, State } from "./settings"; import { handle, handleSync } from "./utils/ipcWrappers"; import { PopoutWindows } from "./utils/popout"; @@ -135,11 +135,6 @@ handle(IpcEvents.CLIPBOARD_COPY_IMAGE, async (_, buf: ArrayBuffer, src: string) }); }); -handle(IpcEvents.PAGE_NOT_FOUND_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 0a203f9..b0e4f02 100644 --- a/src/main/mainWindow.ts +++ b/src/main/mainWindow.ts @@ -470,7 +470,7 @@ function createMainWindow() { const runVencordMain = once(() => require(join(VENCORD_FILES_DIR, "vencordDesktopMain.js"))); -export function loadUrl(uri: string | undefined) { +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"}`); @@ -516,6 +516,14 @@ export async function createWindows() { }); }); + mainWin.webContents.on("did-navigate", (_, url: string, responseCode: number) => { + // check url to ensure app doesn't loop + if (new URL(url).pathname !== `/app` && responseCode >= 300) { + loadUrl(undefined); + console.warn(`Caught bad page response: ${responseCode}, dumping to main app`); + } + }); + // evil hack to fix electron 32 regression that makes devtools always light theme // https://github.com/electron/electron/issues/43367 // TODO: remove once fixed diff --git a/src/preload/index.ts b/src/preload/index.ts index b43b70d..75bf9cd 100644 --- a/src/preload/index.ts +++ b/src/preload/index.ts @@ -24,10 +24,6 @@ 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.PAGE_NOT_FOUND_HANDLER); -}); - if (document.readyState === "complete") { document.documentElement.appendChild(style); } else { diff --git a/src/shared/IpcEvents.ts b/src/shared/IpcEvents.ts index 2fba633..51d2a28 100644 --- a/src/shared/IpcEvents.ts +++ b/src/shared/IpcEvents.ts @@ -50,7 +50,5 @@ export const enum IpcEvents { ARRPC_ACTIVITY = "VCD_ARRPC_ACTIVITY", - CLIPBOARD_COPY_IMAGE = "VCD_CLIPBOARD_COPY_IMAGE", - - PAGE_NOT_FOUND_HANDLER = "VCD_PAGE_NOT_FOUND_HANDLER" + CLIPBOARD_COPY_IMAGE = "VCD_CLIPBOARD_COPY_IMAGE" }