updater: periodically check for updates while open

This commit is contained in:
Vendicated 2025-05-13 22:39:56 +02:00
parent 8c7225d106
commit 59ddf55b99
No known key found for this signature in database
GPG key ID: D66986BAF75ECF18
3 changed files with 65 additions and 33 deletions

View file

@ -33,7 +33,7 @@ import { openUpdaterModal } from "@components/VencordSettings/UpdaterTab";
import { StartAt } from "@utils/types";
import { get as dsGet } from "./api/DataStore";
import { showNotification } from "./api/Notifications";
import { NotificationData, showNotification } from "./api/Notifications";
import { PlainSettings, Settings } from "./api/Settings";
import { patches, PMLogger, startAllPlugins } from "./plugins";
import { localStorage } from "./utils/localStorage";
@ -86,6 +86,46 @@ async function syncSettings() {
}
}
let notifiedForUpdatesThisSession = false;
async function runUpdateCheck() {
const notify = (data: NotificationData) => {
if (notifiedForUpdatesThisSession) return;
notifiedForUpdatesThisSession = true;
setTimeout(() => showNotification({
permanent: true,
noPersist: true,
...data
}), 10_000);
};
try {
const isOutdated = await checkForUpdates();
if (!isOutdated) return;
if (Settings.autoUpdate) {
await update();
if (Settings.autoUpdateNotification) {
notify({
title: "Vencord has been updated!",
body: "Click here to restart",
onClick: relaunch
});
}
return;
}
notify({
title: "A Vencord update is available!",
body: "Click here to view the update",
onClick: openUpdaterModal!
});
} catch (err) {
UpdateLogger.error("Failed to check for updates", err);
}
}
async function init() {
await onceReady;
startAllPlugins(StartAt.WebpackReady);
@ -93,33 +133,8 @@ async function init() {
syncSettings();
if (!IS_WEB && !IS_UPDATER_DISABLED) {
try {
const isOutdated = await checkForUpdates();
if (!isOutdated) return;
if (Settings.autoUpdate) {
await update();
if (Settings.autoUpdateNotification)
setTimeout(() => showNotification({
title: "Vencord has been updated!",
body: "Click here to restart",
permanent: true,
noPersist: true,
onClick: relaunch
}), 10_000);
return;
}
setTimeout(() => showNotification({
title: "A Vencord update is available!",
body: "Click here to view the update",
permanent: true,
noPersist: true,
onClick: openUpdaterModal!
}), 10_000);
} catch (err) {
UpdateLogger.error("Failed to check for updates", err);
}
runUpdateCheck();
setInterval(runUpdateCheck, 1000 * 60 * 30); // 30 minutes
}
if (IS_DEV) {