not insane bad response handler

This commit is contained in:
Kylie C 2024-10-14 17:30:32 -04:00
parent 8b3254a344
commit 59e51d3f8a
4 changed files with 11 additions and 14 deletions

View file

@ -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(() => "");
}

View file

@ -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

View file

@ -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 {

View file

@ -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"
}