Fix false positive in Vencord startup error recovery

This commit is contained in:
Vendicated committed 2026-11-22 23:17:44 +01:00
1 parent 12eeea3268
commit d5669a024c
2 files changed
+61 -25

No files matched your search

+19 -8
View File
@@ -27,7 +27,7 @@ import type { SettingsStore } from "shared/utils/SettingsStore";
import { createAboutWindow } from "./about";
import { CommandLine } from "./cli";
import { BrowserUserAgent, DEFAULT_HEIGHT, DEFAULT_WIDTH, MessageBoxChoice, MIN_HEIGHT, MIN_WIDTH } from "./constants";
import { BrowserUserAgent, DEFAULT_HEIGHT, DEFAULT_WIDTH, MIN_HEIGHT, MIN_WIDTH } from "./constants";
import { AppEvents } from "./events";
import { sendRendererCommand } from "./ipcCommands";
import { darwinURL } from "./main";
@@ -498,12 +498,19 @@ function retryUrl(url: string, description: string) {
setTimeout(() => loadUrl(url), retryDelay);
}
const enum StartupErrorChoice {
Repair,
Quit,
Dismiss
}
export async function showStartupError(error: unknown) {
console.error("Failed to start Vesktop:", error);
const splash = getSplashWindow();
const hasMainWindow = mainWin && !mainWin.isDestroyed();
let parent = splash;
if (mainWin && !mainWin.isDestroyed()) {
if (hasMainWindow) {
splash?.hide();
parent = mainWin;
}
@@ -512,9 +519,9 @@ export async function showStartupError(error: unknown) {
type: "error",
message: "Vesktop failed to start",
detail: `${error}\n\nRepair will re-download Vencord and restart Vesktop.`,
buttons: ["Repair", "Quit"],
defaultId: MessageBoxChoice.Default,
cancelId: MessageBoxChoice.Cancel
buttons: hasMainWindow ? ["Repair", "Quit", "Dismiss"] : ["Repair", "Quit"],
defaultId: StartupErrorChoice.Repair,
cancelId: hasMainWindow ? StartupErrorChoice.Dismiss : StartupErrorChoice.Quit
};
if (parent) {
@@ -522,10 +529,14 @@ export async function showStartupError(error: unknown) {
}
const { response } = await (parent ? dialog.showMessageBox(parent, options) : dialog.showMessageBox(options));
if (response === MessageBoxChoice.Cancel) return app.exit(1);
if (response === StartupErrorChoice.Quit) {
return app.exit(1);
}
updateSplashMessage("Repairing Vencord...");
downloadVencordFiles().then(relaunch, showStartupError);
if (response === StartupErrorChoice.Repair) {
updateSplashMessage("Repairing Vencord...");
downloadVencordFiles().then(relaunch, showStartupError);
}
}
export async function createWindows() {
+42 -17
View File
@@ -13,32 +13,57 @@ contextBridge.exposeInMainWorld("VesktopNative", VesktopNative);
function watchDiscordStartup() {
return new Promise<string | undefined>(resolve => {
function recordError(message: string) {
if (message !== "Uncaught Error: Sentry successfully disabled") {
finish(message);
}
}
function onError(event: ErrorEvent) {
recordError(event.message);
}
function onUnhandledRejection(event: PromiseRejectionEvent) {
if (event.reason instanceof Error) {
recordError(event.reason.message);
}
}
let startupError: string | undefined;
let startupTimeout: number | undefined;
function finish(message: string | undefined) {
window.clearTimeout(startupTimeout);
document.removeEventListener("DOMContentLoaded", onDomReady);
window.removeEventListener("error", onError);
window.removeEventListener("unhandledrejection", onUnhandledRejection);
resolve(message);
}
function recordError(message: string, filename: string, error: unknown) {
const detail = error instanceof Error ? error.message : message.replace(/^Uncaught Error: /, "");
if (
detail === "Sentry successfully disabled" ||
detail === "ResizeObserver loop completed with undelivered notifications." ||
detail === "ResizeObserver loop limit exceeded"
) {
return;
}
const stack = error instanceof Error ? error.stack : undefined;
if (!filename && !stack) {
return;
}
const origin = stack?.split("\n").find(line => line.trimStart().startsWith("at ")) ?? filename;
const fromMod = /file:\/\/\/(?:Vencord(?:Desktop)?Renderer\b|WebpackModule\d+\b)|\bVesktopRenderer\b/.test(
origin
);
if (fromMod) {
finish(message);
} else {
startupError ??= message;
}
}
function onError(event: ErrorEvent) {
recordError(event.message, event.filename, event.error);
}
function onUnhandledRejection(event: PromiseRejectionEvent) {
if (event.reason instanceof Error) {
recordError(event.reason.message, "", event.reason);
}
}
function onDomReady() {
setTimeout(() => {
startupTimeout = window.setTimeout(() => {
const appMount = document.getElementById("app-mount");
finish(appMount?.childElementCount === 0 ? "Discord failed to mount" : undefined);
finish(appMount?.childElementCount === 0 ? (startupError ?? "Discord failed to mount") : undefined);
}, 10_000);
}