mirror of
https://github.com/Equicord/Equicord.git
synced 2025-06-08 14:13:01 -04:00
updater: periodically check for updates while open
This commit is contained in:
parent
8c7225d106
commit
59ddf55b99
3 changed files with 65 additions and 33 deletions
|
@ -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) {
|
||||
|
|
|
@ -46,8 +46,6 @@ const ContributorBadge: ProfileBadge = {
|
|||
let DonorBadges = {} as Record<string, Array<Record<"tooltip" | "badge", string>>>;
|
||||
|
||||
async function loadBadges(noCache = false) {
|
||||
DonorBadges = {};
|
||||
|
||||
const init = {} as RequestInit;
|
||||
if (noCache)
|
||||
init.cache = "no-cache";
|
||||
|
@ -56,6 +54,8 @@ async function loadBadges(noCache = false) {
|
|||
.then(r => r.json());
|
||||
}
|
||||
|
||||
let intervalId: any;
|
||||
|
||||
export default definePlugin({
|
||||
name: "BadgeAPI",
|
||||
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: {
|
||||
async "Refetch Badges"() {
|
||||
await loadBadges(true);
|
||||
|
@ -104,6 +109,13 @@ export default definePlugin({
|
|||
|
||||
async start() {
|
||||
await loadBadges();
|
||||
|
||||
clearInterval(intervalId);
|
||||
intervalId = setInterval(loadBadges, 1000 * 60 * 30); // 30 minutes
|
||||
},
|
||||
|
||||
async stop() {
|
||||
clearInterval(intervalId);
|
||||
},
|
||||
|
||||
getBadges(props: { userId: string; user?: User; guildId: string; }) {
|
||||
|
|
|
@ -39,10 +39,15 @@ async function Unwrap<T>(p: Promise<IpcRes<T>>) {
|
|||
|
||||
export async function checkForUpdates() {
|
||||
changes = await Unwrap(VencordNative.updater.getUpdates());
|
||||
if (changes.some(c => c.hash === gitHash)) {
|
||||
isNewer = true;
|
||||
return (isOutdated = false);
|
||||
|
||||
// we only want to check this for the git updater, not the http updater
|
||||
if (!IS_STANDALONE) {
|
||||
if (changes.some(c => c.hash === gitHash)) {
|
||||
isNewer = true;
|
||||
return (isOutdated = false);
|
||||
}
|
||||
}
|
||||
|
||||
return (isOutdated = changes.length > 0);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue