Handle Vencord startup error & offer to repair

This commit is contained in:
Vendicated committed 2026-11-22 16:00:45 +01:00
1 parent dd8317808a
commit 72d6f55328
5 files changed
+106 -12

No files matched your search

+9 -1
View File
@@ -12,12 +12,13 @@ import { release } from "os";
import { join } from "path";
import { app, BrowserWindow, clipboard, ClipboardItem, dialog, IpcMainInvokeEvent, session, shell } from "electron";
import { once } from "shared/utils/once";
import { IpcEvents } from "../shared/IpcEvents";
import { setBadgeCount } from "./appBadge";
import { autoStart } from "./autoStart";
import { enableHardwareAcceleration } from "./main";
import { mainWin } from "./mainWindow";
import { mainWin, showStartupError } from "./mainWindow";
import { Settings, State } from "./settings";
import { handle, handleSync } from "./utils/ipcWrappers";
import { PopoutWindows } from "./utils/popout";
@@ -38,6 +39,13 @@ const VESKTOP_RENDERER_CSS_PATH = join(__dirname, "renderer.css");
handleSync(IpcEvents.GET_VESKTOP_RENDERER_SCRIPT, () => readFileSync(VESKTOP_RENDERER_JS_PATH, "utf-8"));
handle(IpcEvents.GET_VESKTOP_RENDERER_CSS, () => readFile(VESKTOP_RENDERER_CSS_PATH, "utf-8"));
const showRendererStartupError = once((error: string) => showStartupError(error));
handle(IpcEvents.RENDERER_STARTUP_ERROR, (event, error: string) => {
if (event.sender === mainWin?.webContents && event.senderFrame === event.sender.mainFrame) {
return showRendererStartupError(error);
}
});
if (IS_DEV) {
watch(VESKTOP_RENDERER_CSS_PATH, { persistent: false }, async () => {
mainWin?.webContents.postMessage(
+20 -5
View File
@@ -13,6 +13,7 @@ import {
dialog,
Menu,
MenuItemConstructorOptions,
MessageBoxOptions,
nativeTheme,
Rectangle,
screen,
@@ -31,12 +32,13 @@ import { AppEvents } from "./events";
import { sendRendererCommand } from "./ipcCommands";
import { darwinURL } from "./main";
import { Settings, State, VencordSettings } from "./settings";
import { createSplashWindow, updateSplashMessage } from "./splash";
import { createSplashWindow, getSplashWindow, updateSplashMessage } from "./splash";
import { destroyTray, initTray } from "./tray";
import { clearData } from "./utils/clearData";
import { isDiscordUrl } from "./utils/isDiscordUrl";
import { handleExternalUrl, makeLinksOpenExternally } from "./utils/makeLinksOpenExternally";
import { relaunch } from "./utils/relaunch";
import { showWindow } from "./utils/showWindow";
import { applyDeckKeyboardFix, askToApplySteamLayout, isDeckGameMode } from "./utils/steamOS";
import { downloadVencordFiles, isValidVencordInstall } from "./utils/vencordLoader";
import { VENCORD_FILES_DIR } from "./vencordFilesDir";
@@ -496,15 +498,29 @@ function retryUrl(url: string, description: string) {
setTimeout(() => loadUrl(url), retryDelay);
}
async function showStartupError(error: unknown) {
const { response } = await dialog.showMessageBox({
export async function showStartupError(error: unknown) {
console.error("Failed to start Vesktop:", error);
const splash = getSplashWindow();
let parent = splash;
if (mainWin && !mainWin.isDestroyed()) {
splash?.hide();
parent = mainWin;
}
const options: MessageBoxOptions = {
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
});
};
if (parent) {
showWindow(parent);
}
const { response } = await (parent ? dialog.showMessageBox(parent, options) : dialog.showMessageBox(options));
if (response === MessageBoxChoice.Cancel) return app.exit(1);
@@ -533,7 +549,6 @@ export async function createWindows() {
mainWin = createMainWindow();
} catch (err) {
console.error("Failed to start Vesktop:", err);
return showStartupError(err);
}
+7 -1
View File
@@ -43,5 +43,11 @@ export function createSplashWindow(startMinimized = false) {
export function updateSplashMessage(newMessage: string) {
message = newMessage;
if (splash && !splash.isDestroyed()) splash.webContents.send("update-splash-message", message);
getSplashWindow()?.webContents.send("update-splash-message", message);
}
export function getSplashWindow() {
if (splash && !splash.isDestroyed()) {
return splash;
}
}
+69 -5
View File
@@ -11,9 +11,73 @@ import { VesktopNative } from "./VesktopNative";
contextBridge.exposeInMainWorld("VesktopNative", VesktopNative);
// While sandboxed, Electron "polyfills" these APIs as local variables.
// We have to pass them as arguments as they are not global
Function("require", "process", ipcRenderer.sendSync(IpcEvents.GET_VENCORD_PRELOAD_SCRIPT))(require, process);
function watchDiscordStartup() {
return new Promise<string | undefined>(resolve => {
function recordError(message: string) {
if (message !== "Uncaught Error: Sentry successfully disabled") {
finish(message);
}
}
webFrame.executeJavaScript(ipcRenderer.sendSync(IpcEvents.GET_VENCORD_RENDERER_SCRIPT));
webFrame.executeJavaScript(ipcRenderer.sendSync(IpcEvents.GET_VESKTOP_RENDERER_SCRIPT));
function onError(event: ErrorEvent) {
recordError(event.message);
}
function onUnhandledRejection(event: PromiseRejectionEvent) {
if (event.reason instanceof Error) {
recordError(event.reason.message);
}
}
function finish(message: string | undefined) {
window.removeEventListener("error", onError);
window.removeEventListener("unhandledrejection", onUnhandledRejection);
resolve(message);
}
function onDomReady() {
setTimeout(() => {
const appMount = document.getElementById("app-mount");
finish(appMount?.childElementCount === 0 ? "Discord failed to mount" : undefined);
}, 10_000);
}
window.addEventListener("error", onError);
window.addEventListener("unhandledrejection", onUnhandledRejection);
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", onDomReady, { once: true });
} else {
onDomReady();
}
});
}
async function loadRenderer() {
// While sandboxed, Electron "polyfills" these APIs as local variables.
// We have to pass them as arguments as they are not global
Function("require", "process", ipcRenderer.sendSync(IpcEvents.GET_VENCORD_PRELOAD_SCRIPT))(require, process);
const vencordScript = ipcRenderer.sendSync(IpcEvents.GET_VENCORD_RENDERER_SCRIPT);
const hasVencord = await webFrame.executeJavaScript(`${vencordScript}\n;window.Vencord != null`);
if (!hasVencord) {
throw new Error("Vencord did not initialize window.Vencord");
}
await webFrame.executeJavaScript(ipcRenderer.sendSync(IpcEvents.GET_VESKTOP_RENDERER_SCRIPT));
}
async function checkDiscordStartup() {
// The watcher runs in Discord's JavaScript world so it can read the original error stack.
const error = await webFrame.executeJavaScript(`(${watchDiscordStartup.toString()})()`).catch(error => {
console.error("Failed to check Discord startup:", error);
});
if (error) {
throw new Error(error);
}
}
Promise.all([checkDiscordStartup(), loadRenderer()]).catch(error => {
console.error("Failed to initialize the Vesktop renderer:", error);
return ipcRenderer.invoke(IpcEvents.RENDERER_STARTUP_ERROR, String(error));
});
+1
View File
@@ -11,6 +11,7 @@ export const enum IpcEvents {
GET_VESKTOP_RENDERER_SCRIPT = "VCD_GET_RENDERER_SCRIPT",
GET_VESKTOP_RENDERER_CSS = "VCD_GET_RENDERER_CSS",
VESKTOP_RENDERER_CSS_UPDATE = "VCD_PRELOAD_RENDERER_CSS_UPDATE",
RENDERER_STARTUP_ERROR = "VCD_RENDERER_STARTUP_ERROR",
GET_VERSION = "VCD_GET_VERSION",
SUPPORTS_WINDOWS_TRANSPARENCY = "VCD_SUPPORTS_WINDOWS_TRANSPARENCY",