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 { StartAt } from "@utils/types";
import { get as dsGet } from "./api/DataStore"; 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 { PlainSettings, Settings } from "./api/Settings";
import { patches, PMLogger, startAllPlugins } from "./plugins"; import { patches, PMLogger, startAllPlugins } from "./plugins";
import { localStorage } from "./utils/localStorage"; 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() { async function init() {
await onceReady; await onceReady;
startAllPlugins(StartAt.WebpackReady); startAllPlugins(StartAt.WebpackReady);
@ -93,33 +133,8 @@ async function init() {
syncSettings(); syncSettings();
if (!IS_WEB && !IS_UPDATER_DISABLED) { if (!IS_WEB && !IS_UPDATER_DISABLED) {
try { runUpdateCheck();
const isOutdated = await checkForUpdates(); setInterval(runUpdateCheck, 1000 * 60 * 30); // 30 minutes
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);
}
} }
if (IS_DEV) { if (IS_DEV) {

View file

@ -46,8 +46,6 @@ const ContributorBadge: ProfileBadge = {
let DonorBadges = {} as Record<string, Array<Record<"tooltip" | "badge", string>>>; let DonorBadges = {} as Record<string, Array<Record<"tooltip" | "badge", string>>>;
async function loadBadges(noCache = false) { async function loadBadges(noCache = false) {
DonorBadges = {};
const init = {} as RequestInit; const init = {} as RequestInit;
if (noCache) if (noCache)
init.cache = "no-cache"; init.cache = "no-cache";
@ -56,6 +54,8 @@ async function loadBadges(noCache = false) {
.then(r => r.json()); .then(r => r.json());
} }
let intervalId: any;
export default definePlugin({ export default definePlugin({
name: "BadgeAPI", name: "BadgeAPI",
description: "API to add badges to users.", description: "API to add badges to users.",
@ -89,6 +89,11 @@ export default definePlugin({
} }
], ],
// for access from the console or other plugins
get DonorBadges() {
return DonorBadges;
},
toolboxActions: { toolboxActions: {
async "Refetch Badges"() { async "Refetch Badges"() {
await loadBadges(true); await loadBadges(true);
@ -104,6 +109,13 @@ export default definePlugin({
async start() { async start() {
await loadBadges(); await loadBadges();
clearInterval(intervalId);
intervalId = setInterval(loadBadges, 1000 * 60 * 30); // 30 minutes
},
async stop() {
clearInterval(intervalId);
}, },
getBadges(props: { userId: string; user?: User; guildId: string; }) { getBadges(props: { userId: string; user?: User; guildId: string; }) {

View file

@ -39,10 +39,15 @@ async function Unwrap<T>(p: Promise<IpcRes<T>>) {
export async function checkForUpdates() { export async function checkForUpdates() {
changes = await Unwrap(VencordNative.updater.getUpdates()); changes = await Unwrap(VencordNative.updater.getUpdates());
if (changes.some(c => c.hash === gitHash)) {
isNewer = true; // we only want to check this for the git updater, not the http updater
return (isOutdated = false); if (!IS_STANDALONE) {
if (changes.some(c => c.hash === gitHash)) {
isNewer = true;
return (isOutdated = false);
}
} }
return (isOutdated = changes.length > 0); return (isOutdated = changes.length > 0);
} }