aboutsummaryrefslogtreecommitdiff
path: root/src/utils/updater.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils/updater.ts')
-rw-r--r--src/utils/updater.ts22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/utils/updater.ts b/src/utils/updater.ts
index 9fdec47..e13f5cf 100644
--- a/src/utils/updater.ts
+++ b/src/utils/updater.ts
@@ -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!");
+ }
+}