feat: Crash Handler (#531)

Co-authored-by: Ven <vendicated@riseup.net>
This commit is contained in:
Nuckyz 2023-03-01 01:26:13 -03:00 committed by GitHub
parent c91b0df607
commit faa90eccd3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 182 additions and 27 deletions

View file

@ -77,3 +77,25 @@ export async function rebuild() {
return oldHashes["patcher.js"] !== newHashes["patcher.js"] ||
oldHashes["preload.js"] !== newHashes["preload.js"];
}
export async function maybePromptToUpdate(confirmMessage: string, checkForDev = false) {
if (IS_WEB) return;
if (checkForDev && IS_DEV) return;
try {
const isOutdated = await checkForUpdates();
if (isOutdated) {
const wantsUpdate = confirm(confirmMessage);
if (wantsUpdate && isNewer) return alert("Your local copy has more recent commits. Please stash or reset them.");
if (wantsUpdate) {
await update();
const needFullRestart = await rebuild();
if (needFullRestart) DiscordNative.app.relaunch();
else location.reload();
}
}
} catch (err) {
UpdateLogger.error(err);
alert("That also failed :( Try updating or re-installing with the installer!");
}
}