Fix Crash Loops and prevent metrics (#580)

This commit is contained in:
Nuckyz 2023-03-06 18:54:01 -03:00 committed by GitHub
parent 36c27f1111
commit 7322c3af04
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 1 deletions

View file

@ -41,6 +41,8 @@ const settings = definePluginSettings({
} }
}); });
let crashCount: number = 0;
export default definePlugin({ export default definePlugin({
name: "CrashHandler", name: "CrashHandler",
description: "Utility plugin for handling and possibly recovering from Crashes without a restart", description: "Utility plugin for handling and possibly recovering from Crashes without a restart",
@ -69,8 +71,22 @@ export default definePlugin({
], ],
handleCrash(_this: ReactElement & { forceUpdate: () => void; }) { handleCrash(_this: ReactElement & { forceUpdate: () => void; }) {
if (++crashCount > 5) {
try { try {
maybePromptToUpdate("Uh oh, Discord has just crashed... but good news, there is a Vencord update available that might fix this issue! Would you like to update now?", true); showNotification({
color: "#eed202",
title: "Discord has crashed!",
body: "Awn :( Discord has crashed more than five times, not attempting to recover.",
});
} catch { }
return false;
}
setTimeout(() => crashCount--, 60_000);
try {
if (crashCount === 1) maybePromptToUpdate("Uh oh, Discord has just crashed... but good news, there is a Vencord update available that might fix this issue! Would you like to update now?", true);
if (settings.store.attemptToPreventCrashes) { if (settings.store.attemptToPreventCrashes) {
this.handlePreventCrash(_this); this.handlePreventCrash(_this);
@ -80,6 +96,7 @@ export default definePlugin({
return false; return false;
} catch (err) { } catch (err) {
CrashHandlerLogger.error("Failed to handle crash", err); CrashHandlerLogger.error("Failed to handle crash", err);
return false;
} }
}, },

View file

@ -38,6 +38,19 @@ export default definePlugin({
match: /window\.DiscordSentry=function.+\}\(\)/, match: /window\.DiscordSentry=function.+\}\(\)/,
replace: "", replace: "",
} }
},
{
find: ".METRICS,",
replacement: [
{
match: /this\._intervalId.+?12e4\)/,
replace: ""
},
{
match: /(?<=increment=function\(\i\){)/,
replace: "return;"
}
]
} }
] ]
}); });