From f527df76b86aaab62faffaae90a0c6cc95b370f3 Mon Sep 17 00:00:00 2001 From: thororen1234 <78185467+thororen1234@users.noreply.github.com> Date: Sun, 16 Mar 2025 01:27:38 -0400 Subject: [PATCH] If Equicord Fails To Initialize Reload This works for me but needs more testing --- src/Vencord.ts | 59 ++++++++++++++++++++++++++++++++++++------ src/webpack/webpack.ts | 2 +- 2 files changed, 52 insertions(+), 9 deletions(-) diff --git a/src/Vencord.ts b/src/Vencord.ts index 0e64212d..a575cc59 100644 --- a/src/Vencord.ts +++ b/src/Vencord.ts @@ -30,6 +30,7 @@ import "./utils/quickCss"; import "./webpack/patchWebpack"; import { openUpdaterModal } from "@components/VencordSettings/UpdaterTab"; +import { Logger } from "@utils/Logger"; import { StartAt } from "@utils/types"; import { get as dsGet } from "./api/DataStore"; @@ -48,6 +49,37 @@ if (IS_REPORTER) { Settings.plugins.CharacterCounter.enabled = false; } +const logger = new Logger("Debug", "#a6d189"); + +let isFrozen = true; +const checkInterval = 5000; +const freezeChecker = setInterval(() => { + if (isFrozen) { + location.reload(); + } + isFrozen = true; +}, checkInterval); + +function safeInit() { + try { + startAllPlugins(StartAt.Init); + init(); + + const originalLoggerInfo = logger.info.bind(logger); + logger.info = function (message) { + originalLoggerInfo(message); + if (message.includes("Completed Equicord initialization.")) { + isFrozen = false; + clearInterval(freezeChecker); + } + }; + } catch (error) { + logger.error("Failed to initialize Equicord, reloading in 5 seconds...", error); + clearInterval(freezeChecker); + setTimeout(() => location.reload(), 5000); + } +} + async function syncSettings() { // pre-check for local shared settings if ( @@ -94,6 +126,8 @@ async function init() { syncSettings(); + logger.info("Completed Equicord initialization."); + if (!IS_WEB && !IS_UPDATER_DISABLED) { try { const isOutdated = await checkForUpdates(); @@ -139,16 +173,25 @@ async function init() { } } -startAllPlugins(StartAt.Init); -init(); +safeInit(); document.addEventListener("DOMContentLoaded", () => { - startAllPlugins(StartAt.DOMContentLoaded); + try { + startAllPlugins(StartAt.DOMContentLoaded); - if (IS_DISCORD_DESKTOP && Settings.winNativeTitleBar && navigator.platform.toLowerCase().startsWith("win")) { - document.head.append(Object.assign(document.createElement("style"), { - id: "vencord-native-titlebar-style", - textContent: "[class*=titleBar]{display: none!important}" - })); + if (IS_DISCORD_DESKTOP && Settings.winNativeTitleBar && navigator.platform.toLowerCase().startsWith("win")) { + document.head.append(Object.assign(document.createElement("style"), { + id: "vencord-native-titlebar-style", + textContent: "[class*=titleBar]{display: none!important}" + })); + } + + isFrozen = false; + clearInterval(freezeChecker); + logger.info("DOMContentLoaded event handled successfully."); + } catch (error) { + logger.error("Error during DOMContentLoaded event, reloading in 5 seconds...", error); + clearInterval(freezeChecker); + setTimeout(() => location.reload(), 5000); } }, { once: true }); diff --git a/src/webpack/webpack.ts b/src/webpack/webpack.ts index 26d9c0d7..7796827b 100644 --- a/src/webpack/webpack.ts +++ b/src/webpack/webpack.ts @@ -26,7 +26,7 @@ import { traceFunction } from "../debug/Tracer"; import { Flux } from "./common"; import { AnyModuleFactory, AnyWebpackRequire, ModuleExports, WebpackRequire } from "./wreq"; -const logger = new Logger("Webpack"); +export const logger = new Logger("Webpack"); export let _resolveReady: () => void; /**