From 59ddf55b99f2eb14cba7ada1fc21e0541e4ee84d Mon Sep 17 00:00:00 2001 From: Vendicated Date: Tue, 13 May 2025 22:39:56 +0200 Subject: [PATCH 1/3] updater: periodically check for updates while open --- src/Vencord.ts | 71 +++++++++++++++++++------------ src/plugins/_api/badges/index.tsx | 16 ++++++- src/utils/updater.ts | 11 +++-- 3 files changed, 65 insertions(+), 33 deletions(-) diff --git a/src/Vencord.ts b/src/Vencord.ts index 63508eb0..48ecce97 100644 --- a/src/Vencord.ts +++ b/src/Vencord.ts @@ -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) { diff --git a/src/plugins/_api/badges/index.tsx b/src/plugins/_api/badges/index.tsx index 52bede44..a30f41ce 100644 --- a/src/plugins/_api/badges/index.tsx +++ b/src/plugins/_api/badges/index.tsx @@ -46,8 +46,6 @@ const ContributorBadge: ProfileBadge = { let DonorBadges = {} as Record>>; 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; }) { diff --git a/src/utils/updater.ts b/src/utils/updater.ts index f99c6ca1..25fe6ee8 100644 --- a/src/utils/updater.ts +++ b/src/utils/updater.ts @@ -39,10 +39,15 @@ async function Unwrap(p: Promise>) { 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); } From 8473b593a7c7cea5e0b3ee5c66c50d494dd97328 Mon Sep 17 00:00:00 2001 From: Vendicated Date: Tue, 13 May 2025 22:58:54 +0200 Subject: [PATCH 2/3] bump to v1.12.1 --- package.json | 2 +- scripts/build/common.mjs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 60fa7703..b8e518ae 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "vencord", "private": "true", - "version": "1.12.0", + "version": "1.12.1", "description": "The cutest Discord client mod", "homepage": "https://github.com/Vendicated/Vencord#readme", "bugs": { diff --git a/scripts/build/common.mjs b/scripts/build/common.mjs index 9bcbc7f0..5c1732aa 100644 --- a/scripts/build/common.mjs +++ b/scripts/build/common.mjs @@ -182,7 +182,7 @@ export const globPlugins = kind => ({ const mod = `p${i}`; code += `import ${mod} from "./${dir}/${fileName.replace(/\.tsx?$/, "")}";\n`; pluginsCode += `[${mod}.name]:${mod},\n`; - metaCode += `[${mod}.name]:${JSON.stringify({ folderName, userPlugin })},\n`; // TODO: add excluded plugins to display in the UI? + metaCode += `[${mod}.name]:${JSON.stringify({ folderName, userPlugin })},\n`; i++; } } From 98b1b11dfa8728318160b309ecad6daef9589c7e Mon Sep 17 00:00:00 2001 From: Nuckyz <61953774+Nuckyz@users.noreply.github.com> Date: Tue, 13 May 2025 20:59:13 -0300 Subject: [PATCH 3/3] Fix NoServerEmojis, InvisibleChat & other patches --- src/plugins/invisibleChat.desktop/index.tsx | 2 +- src/plugins/messageLogger/index.tsx | 28 +++++++++++---------- src/plugins/noServerEmojis/index.ts | 2 +- src/plugins/roleColorEverywhere/index.tsx | 2 +- 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/plugins/invisibleChat.desktop/index.tsx b/src/plugins/invisibleChat.desktop/index.tsx index f5e8cbb5..ab124192 100644 --- a/src/plugins/invisibleChat.desktop/index.tsx +++ b/src/plugins/invisibleChat.desktop/index.tsx @@ -110,7 +110,7 @@ export default definePlugin({ patches: [ { // Indicator - find: "#{intl::MESSAGE_EDITED}", + find: ".SEND_FAILED,", replacement: { match: /let\{className:\i,message:\i[^}]*\}=(\i)/, replace: "try {$1 && $self.INV_REGEX.test($1.message.content) ? $1.content.push($self.indicator()) : null } catch {};$&" diff --git a/src/plugins/messageLogger/index.tsx b/src/plugins/messageLogger/index.tsx index ffe5286e..25ee395e 100644 --- a/src/plugins/messageLogger/index.tsx +++ b/src/plugins/messageLogger/index.tsx @@ -462,21 +462,23 @@ export default definePlugin({ ] }, + // Message content renderer + { + find: ".SEND_FAILED,", + replacement: { + // Render editHistory in the deepest div for message content + match: /(\)\("div",\{id:.+?children:\[)/, + replace: "$1 (!!arguments[0].message.editHistory?.length && $self.renderEdits(arguments[0]))," + } + }, + { - // Message content renderer find: "#{intl::MESSAGE_EDITED}", - replacement: [ - { - // Render editHistory in the deepest div for message content - match: /(\)\("div",\{id:.+?children:\[)/, - replace: "$1 (!!arguments[0].message.editHistory?.length && $self.renderEdits(arguments[0]))," - }, - { - // Make edit marker clickable - match: /"span",\{(?=className:\i\.edited,)/, - replace: "$self.EditMarker,{message:arguments[0].message," - } - ] + replacement: { + // Make edit marker clickable + match: /"span",\{(?=className:\i\.edited,)/, + replace: "$self.EditMarker,{message:arguments[0].message," + } }, { diff --git a/src/plugins/noServerEmojis/index.ts b/src/plugins/noServerEmojis/index.ts index 6a39f55c..cd950b42 100644 --- a/src/plugins/noServerEmojis/index.ts +++ b/src/plugins/noServerEmojis/index.ts @@ -30,7 +30,7 @@ export default definePlugin({ { find: "}searchWithoutFetchingLatest(", replacement: { - match: /searchWithoutFetchingLatest.{20,300}get\((\i).{10,40}?reduce\(\((\i),(\i)\)=>\{/, + match: /\.get\((\i)\)\.nameMatchesChain\(\i\)\.reduce\(\((\i),(\i)\)=>\{/, replace: "$& if ($self.shouldSkip($1, $3)) return $2;" } } diff --git a/src/plugins/roleColorEverywhere/index.tsx b/src/plugins/roleColorEverywhere/index.tsx index 71f87b13..dc60bb64 100644 --- a/src/plugins/roleColorEverywhere/index.tsx +++ b/src/plugins/roleColorEverywhere/index.tsx @@ -153,7 +153,7 @@ export default definePlugin({ }, // Messages { - find: "#{intl::MESSAGE_EDITED}", + find: ".SEND_FAILED,", replacement: { match: /(?<=isUnsupported\]:(\i)\.isUnsupported\}\),)(?=children:\[)/, replace: "style:$self.useMessageColorsStyle($1),"