diff --git a/plugins/better-timestamps/src/index.ts b/plugins/better-timestamps/src/index.ts index eeddc82..53f601b 100644 --- a/plugins/better-timestamps/src/index.ts +++ b/plugins/better-timestamps/src/index.ts @@ -1,7 +1,6 @@ import { logger } from "@vendetta"; -import { id, storage } from "@vendetta/plugin"; +import { storage } from "@vendetta/plugin"; import { applyPatches } from "@shared/lib/patcher"; -import { guardPlugin } from "@shared/lib/guard"; import patchRowManager from "./patches/rowManager"; import patchTimestamp from "./patches/timestamp"; import Settings from "./ui/Settings"; @@ -14,10 +13,10 @@ export default { storage.customFormat ??= "dddd, MMMM Do YYYY, h:mm:ss a"; storage.separateMessages ??= false; - unpatchAll = guardPlugin(id, () => applyPatches("BetterTimestamps", logger, { + unpatchAll = applyPatches("BetterTimestamps", logger, { "message & day timestamps": patchRowManager, "message timestamp component": patchTimestamp - })); + }); }, onUnload: () => unpatchAll(), settings: Settings diff --git a/plugins/copy-role-color/src/index.ts b/plugins/copy-role-color/src/index.ts index 365a378..1ea1a72 100644 --- a/plugins/copy-role-color/src/index.ts +++ b/plugins/copy-role-color/src/index.ts @@ -1,5 +1,4 @@ import { logger } from "@vendetta"; -import { id } from "@vendetta/plugin"; import { findByName, findByStoreName } from "@vendetta/metro"; import { after } from "@vendetta/patcher"; import { findInReactTree } from "@vendetta/utils"; @@ -7,7 +6,6 @@ import { clipboard } from "@vendetta/metro/common"; import { getAssetIDByName } from "@vendetta/ui/assets"; import { showToast } from "@vendetta/ui/toasts"; import { applyPatches } from "@shared/lib/patcher"; -import { guardPlugin } from "@shared/lib/guard"; import { registerTypeDetector, registerIntercept, patchCreateElement } from "@shared/lib/createElementIntercept"; // A gradient role's real colors live at role.colorStrings ({primaryColor, secondaryColor, @@ -121,10 +119,10 @@ let unpatchAll: () => void = () => {}; export default { onLoad: () => { - unpatchAll = guardPlugin(id, () => applyPatches("CopyRoleColor", logger, { + unpatchAll = applyPatches("CopyRoleColor", logger, { "role pill long-press": patchRolePill, "profile role item long-press": patchProfileRoleItem - })); + }); }, onUnload: () => unpatchAll() }; diff --git a/plugins/custom-user-tags/src/index.ts b/plugins/custom-user-tags/src/index.ts index 25a13aa..ddbd7c6 100644 --- a/plugins/custom-user-tags/src/index.ts +++ b/plugins/custom-user-tags/src/index.ts @@ -1,7 +1,6 @@ import { logger } from "@vendetta"; -import { id, storage } from "@vendetta/plugin"; +import { storage } from "@vendetta/plugin"; import { applyPatches } from "@shared/lib/patcher"; -import { guardPlugin } from "@shared/lib/guard"; import patchChat from "./patches/chat"; import patchName from "./patches/name"; import patchDetails from "./patches/details"; @@ -15,13 +14,13 @@ export default { onLoad: () => { storage.tags ??= {}; - unpatchAll = guardPlugin(id, () => applyPatches("Custom User Tags", logger, { + unpatchAll = applyPatches("Custom User Tags", logger, { tag: patchTag, chat: patchChat, name: patchName, details: patchDetails, profile: patchProfile - })); + }); }, onUnload: () => unpatchAll(), settings: Settings diff --git a/plugins/fake-profile-themes-and-effects/src/index.ts b/plugins/fake-profile-themes-and-effects/src/index.ts index fe6db5e..4e6498f 100644 --- a/plugins/fake-profile-themes-and-effects/src/index.ts +++ b/plugins/fake-profile-themes-and-effects/src/index.ts @@ -1,7 +1,6 @@ import { logger } from "@vendetta"; -import { id, storage } from "@vendetta/plugin"; +import { storage } from "@vendetta/plugin"; import { applyPatches } from "@shared/lib/patcher"; -import { guardPlugin } from "@shared/lib/guard"; import { FluxDispatcher } from "@fpte/lib/flux"; import { UserProfileStore, UserStore } from "@fpte/lib/stores"; import { @@ -37,7 +36,7 @@ export default { // self-contained fallback picker instead. storage.forceFallbackEffectPicker ??= true; - unpatchAll = guardPlugin(id, () => applyPatches("FakeProfileThemesAndEffects", logger, { + unpatchAll = applyPatches("FakeProfileThemesAndEffects", logger, { "purchase check": patchGetPurchase, "user profile data": patchGetUserProfile, "profile effect sections": () => { @@ -47,7 +46,7 @@ export default { "profile theme": patchUseProfileTheme, "profile edit form": patchUserProfileEditForm, "nitro upsell card": patchNitroUpsellCard - })); + }); updateProfileThemeAndEffect(); }, onUnload() { diff --git a/plugins/key-inspector/src/index.tsx b/plugins/key-inspector/src/index.tsx index 7967148..a18fc20 100644 --- a/plugins/key-inspector/src/index.tsx +++ b/plugins/key-inspector/src/index.tsx @@ -1,10 +1,5 @@ -import { id } from "@vendetta/plugin"; -import { checkForUpdate } from "@shared/lib/reload"; import Settings from "./ui/Settings"; export default { - onLoad: () => { - checkForUpdate(id).catch(() => {}); - }, settings: Settings }; diff --git a/plugins/message-logger/src/index.ts b/plugins/message-logger/src/index.ts index 45364c2..7fd70aa 100644 --- a/plugins/message-logger/src/index.ts +++ b/plugins/message-logger/src/index.ts @@ -1,13 +1,12 @@ import { logger } from "@vendetta"; -import { id, storage } from "@vendetta/plugin"; -import { guardPlugin } from "@shared/lib/guard"; +import { storage } from "@vendetta/plugin"; import Settings from "./ui/Settings"; import { patchFluxIntercept, rehydrateFromLog, revertFakedMessages } from "./patches/fluxIntercept"; import { patchRowStyling } from "./patches/rowStyling"; import { initCloudSync } from "./lib/cloudSync"; const TAG = "[MessageLogger]"; -let unpatchAll: () => void = () => {}; +const cleanups: (() => void)[] = []; function initStorage() { storage.options ??= {}; @@ -33,20 +32,13 @@ export default { initStorage(); console.log(TAG, "onLoad"); - unpatchAll = guardPlugin(id, () => { - const cleanups: (() => void)[] = []; - let patched = 0; - if (patchFluxIntercept(cleanups)) patched++; - if (patchRowStyling(cleanups)) patched++; - cleanups.push(initCloudSync()); - rehydrateFromLog(); + let patched = 0; + if (patchFluxIntercept(cleanups)) patched++; + if (patchRowStyling(cleanups)) patched++; + cleanups.push(initCloudSync()); + rehydrateFromLog(); - console.log(TAG, `onLoad done - ${patched}/2 patches applied`); - return () => { - for (const fn of cleanups) fn(); - cleanups.length = 0; - }; - }); + console.log(TAG, `onLoad done - ${patched}/2 patches applied`); }, onUnload() { console.log(TAG, "onUnload"); @@ -55,7 +47,8 @@ export default { } catch (e: any) { logger.error("[MessageLogger] Failed to revert faked messages:", e?.message ?? e); } - unpatchAll(); + for (const fn of cleanups) fn(); + cleanups.length = 0; }, settings: Settings, }; diff --git a/plugins/message-snippets/src/index.ts b/plugins/message-snippets/src/index.ts index a543666..ea9caa6 100644 --- a/plugins/message-snippets/src/index.ts +++ b/plugins/message-snippets/src/index.ts @@ -1,17 +1,12 @@ -import { id } from "@vendetta/plugin"; -import { guardPlugin } from "@shared/lib/guard"; import loadCommands from "./commands"; import Settings from "./ui/Settings"; -let unpatchAll: () => void = () => {}; +let unregisterFns: (() => void)[] = []; export default { onLoad: () => { - unpatchAll = guardPlugin(id, () => { - const unregisterFns = loadCommands(); - return () => unregisterFns.forEach((fn) => fn()); - }); + unregisterFns = loadCommands(); }, - onUnload: () => unpatchAll(), + onUnload: () => unregisterFns.forEach((fn) => fn()), settings: Settings }; diff --git a/plugins/more-alts/src/index.ts b/plugins/more-alts/src/index.ts index 740b8d3..0c5f9e7 100644 --- a/plugins/more-alts/src/index.ts +++ b/plugins/more-alts/src/index.ts @@ -1,7 +1,5 @@ import { logger } from "@vendetta"; -import { id } from "@vendetta/plugin"; import { getAssetIDByName } from "@vendetta/ui/assets"; -import { guardPlugin } from "@shared/lib/guard"; import Settings from "./ui/Settings"; import patchMoreAltsSection, { SectionRow } from "./patches/sidebarPin"; import patchContextMenu from "./patches/contextMenu"; @@ -9,7 +7,10 @@ import patchNativeSwitcher from "./lib/nativeSwitcher"; import loadCommands from "./commands"; import { ensureStorage, getSettings } from "./lib/accounts"; -let teardown: () => void = () => {}; +let unpatchSidebar: (() => void) | undefined; +let unpatchContextMenu: (() => void) | undefined; +let unpatchNativeSwitcher: (() => void) | undefined; +let unregisterCommands: (() => void)[] = []; function buildRows(): SectionRow[] { if (!getSettings().addToSidebar) return []; @@ -29,47 +30,36 @@ export default { onLoad() { ensureStorage(); - teardown = guardPlugin(id, () => { - let unpatchSidebar: (() => void) | undefined; - let unpatchContextMenu: (() => void) | undefined; - let unpatchNativeSwitcher: (() => void) | undefined; - let unregisterCommands: (() => void)[] = []; + try { + unpatchSidebar = patchMoreAltsSection(buildRows); + } catch (e: any) { + logger.error("[MoreAlts] Failed to patch sidebar:", e?.message ?? e); + } - try { - unpatchSidebar = patchMoreAltsSection(buildRows); - } catch (e: any) { - logger.error("[MoreAlts] Failed to patch sidebar:", e?.message ?? e); - } + try { + unpatchContextMenu = patchContextMenu(); + } catch (e: any) { + logger.error("[MoreAlts] Failed to patch context menu:", e?.message ?? e); + } - try { - unpatchContextMenu = patchContextMenu(); - } catch (e: any) { - logger.error("[MoreAlts] Failed to patch context menu:", e?.message ?? e); - } + try { + unpatchNativeSwitcher = patchNativeSwitcher(); + } catch (e: any) { + logger.error("[MoreAlts] Failed to patch native switcher:", e?.message ?? e); + } - try { - unpatchNativeSwitcher = patchNativeSwitcher(); - } catch (e: any) { - logger.error("[MoreAlts] Failed to patch native switcher:", e?.message ?? e); - } - - try { - unregisterCommands = loadCommands(); - } catch (e: any) { - logger.error("[MoreAlts] Failed to register commands:", e?.message ?? e); - } - - return () => { - unpatchSidebar?.(); - unpatchContextMenu?.(); - unpatchNativeSwitcher?.(); - unregisterCommands.forEach((u) => u()); - unregisterCommands = []; - }; - }); + try { + unregisterCommands = loadCommands(); + } catch (e: any) { + logger.error("[MoreAlts] Failed to register commands:", e?.message ?? e); + } }, onUnload() { - teardown(); + unpatchSidebar?.(); + unpatchContextMenu?.(); + unpatchNativeSwitcher?.(); + unregisterCommands.forEach((u) => u()); + unregisterCommands = []; } }; diff --git a/plugins/pronoun-db/src/index.tsx b/plugins/pronoun-db/src/index.tsx index e17a345..14fae36 100644 --- a/plugins/pronoun-db/src/index.tsx +++ b/plugins/pronoun-db/src/index.tsx @@ -1,9 +1,7 @@ import { logger } from "@vendetta"; -import { id } from "@vendetta/plugin"; import { after } from "@vendetta/patcher"; import { findInReactTree } from "@vendetta/utils"; import { rawFindByTypeName } from "@shared/lib/rawFind"; -import { guardPlugin } from "@shared/lib/guard"; import PronounSection from "./ui/PronounSection"; import Settings from "./ui/Settings"; @@ -68,25 +66,20 @@ function attempt() { } } -let teardown: () => void = () => {}; - export default { onLoad: () => { - teardown = guardPlugin(id, () => { - attempt(); - if (!patched) { - let ticks = 0; - retryHandle = setInterval(() => { - attempt(); - if (++ticks >= 30) stopRetrying(); // ~9s at 300ms, then give up - }, 300); - } - return () => { - stopRetrying(); - unpatch(); - }; - }); + attempt(); + if (!patched) { + let ticks = 0; + retryHandle = setInterval(() => { + attempt(); + if (++ticks >= 30) stopRetrying(); // ~9s at 300ms, then give up + }, 300); + } + }, + onUnload: () => { + stopRetrying(); + unpatch(); }, - onUnload: () => teardown(), settings: Settings }; diff --git a/plugins/quest-orbs/src/index.ts b/plugins/quest-orbs/src/index.ts index 0442403..f895e60 100644 --- a/plugins/quest-orbs/src/index.ts +++ b/plugins/quest-orbs/src/index.ts @@ -1,25 +1,14 @@ import { logger } from "@vendetta"; -import { id } from "@vendetta/plugin"; -import { findByStoreName } from "@vendetta/metro"; -import { checkPluginStatus } from "@shared/lib/backend"; -import { checkForUpdate } from "@shared/lib/reload"; import Settings from "./ui/Settings"; import { completeAllVideoQuests } from "./lib/questCompleter"; -const UserStore = findByStoreName("UserStore"); - export default { onLoad: () => { - checkForUpdate(id).catch(() => {}); - // Fire-and-forget: never blocks Discord's own boot, and a failure here (e.g. QuestStore // not populated yet this session) is logged, not thrown - onLoad must not crash the app. - checkPluginStatus(UserStore?.getCurrentUser?.()?.id, id).then((status) => { - if (status.blocked) return; - completeAllVideoQuests().catch((e) => { - logger.error(`[QuestOrbs] Auto-run on load failed: ${e}`); - }); + completeAllVideoQuests().catch((e) => { + logger.error(`[QuestOrbs] Auto-run on load failed: ${e}`); }); }, onUnload: () => {}, diff --git a/plugins/radial-status/src/index.ts b/plugins/radial-status/src/index.ts index 274946b..715e779 100644 --- a/plugins/radial-status/src/index.ts +++ b/plugins/radial-status/src/index.ts @@ -1,7 +1,6 @@ import { logger } from "@vendetta"; -import { id, storage } from "@vendetta/plugin"; +import { storage } from "@vendetta/plugin"; import { applyPatches } from "@shared/lib/patcher"; -import { guardPlugin } from "@shared/lib/guard"; import patchRing from "./patches/ringPatch"; import Settings from "./ui/Settings"; @@ -22,9 +21,9 @@ export default { }; storage.ringThickness ??= 2; - unpatchAll = guardPlugin(id, () => applyPatches("Radial Status", logger, { + unpatchAll = applyPatches("Radial Status", logger, { ring: patchRing - })); + }); }, onUnload: () => unpatchAll(), settings: Settings diff --git a/plugins/reminders/src/index.ts b/plugins/reminders/src/index.ts index 79dae7a..273465f 100644 --- a/plugins/reminders/src/index.ts +++ b/plugins/reminders/src/index.ts @@ -1,22 +1,17 @@ -import { id } from "@vendetta/plugin"; -import { guardPlugin } from "@shared/lib/guard"; import loadCommands from "./commands"; import { startScheduler, stopScheduler } from "./lib/reminders"; import Settings from "./ui/Settings"; -let unpatchAll: () => void = () => {}; +let unregisterFns: (() => void)[] = []; export default { onLoad: () => { - unpatchAll = guardPlugin(id, () => { - const unregisterFns = loadCommands(); - startScheduler(); - return () => { - unregisterFns.forEach((fn) => fn()); - stopScheduler(); - }; - }); + unregisterFns = loadCommands(); + startScheduler(); + }, + onUnload: () => { + unregisterFns.forEach((fn) => fn()); + stopScheduler(); }, - onUnload: () => unpatchAll(), settings: Settings }; diff --git a/plugins/reverse-image-search/src/index.ts b/plugins/reverse-image-search/src/index.ts index a4b9d50..fb7f2e3 100644 --- a/plugins/reverse-image-search/src/index.ts +++ b/plugins/reverse-image-search/src/index.ts @@ -1,15 +1,10 @@ -import { id } from "@vendetta/plugin"; -import { guardPlugin } from "@shared/lib/guard"; import loadCommands from "./commands"; -let unpatchAll: () => void = () => {}; +let unregisterFns: (() => void)[] = []; export default { onLoad: () => { - unpatchAll = guardPlugin(id, () => { - const unregisterFns = loadCommands(); - return () => unregisterFns.forEach((fn) => fn()); - }); + unregisterFns = loadCommands(); }, - onUnload: () => unpatchAll() + onUnload: () => unregisterFns.forEach((fn) => fn()) }; diff --git a/plugins/role-color-everywhere/src/index.ts b/plugins/role-color-everywhere/src/index.ts index 6f6dffd..51e64e5 100644 --- a/plugins/role-color-everywhere/src/index.ts +++ b/plugins/role-color-everywhere/src/index.ts @@ -1,7 +1,6 @@ import { logger } from "@vendetta"; -import { id, storage } from "@vendetta/plugin"; +import { storage } from "@vendetta/plugin"; import { applyPatches } from "@shared/lib/patcher"; -import { guardPlugin } from "@shared/lib/guard"; import patchRows from "./patches/rows"; import patchMemberList from "./patches/memberList"; import patchTypingWrapper from "./patches/typingWrapper"; @@ -18,12 +17,12 @@ export default { storage.hideTyping ??= false; storage.chatInterpolation ??= 0; - unpatchAll = guardPlugin(id, () => applyPatches("RoleColorEverywhere", logger, { + unpatchAll = applyPatches("RoleColorEverywhere", logger, { "mentions & chat text": patchRows, "member list role headers": patchMemberList, "typing indicator": patchTypingWrapper, "voice channel names": patchVoiceUserConnected - })); + }); }, onUnload: () => unpatchAll(), settings: Settings diff --git a/plugins/rose-plugs/src/index.ts b/plugins/rose-plugs/src/index.ts index 1e0967b..2a6bf81 100644 --- a/plugins/rose-plugs/src/index.ts +++ b/plugins/rose-plugs/src/index.ts @@ -1,13 +1,11 @@ import { logger } from "@vendetta"; -import { id } from "@vendetta/plugin"; import { getAssetIDByName } from "@vendetta/ui/assets"; -import { guardPlugin } from "@shared/lib/guard"; import Settings from "./ui/Settings"; import PluginsBrowser from "./ui/PluginsBrowser"; import patchRosiesPlugsSection, { SectionRow } from "./patches/settings"; import { discoverRosiesPlugins } from "./patches/discoverPlugins"; -let teardown: () => void = () => {}; +let unpatch: (() => void) | undefined; function buildRows(): SectionRow[] { const rows: SectionRow[] = [ @@ -40,18 +38,15 @@ function buildRows(): SectionRow[] { export default { onLoad: () => { - teardown = guardPlugin(id, () => { - let unpatch: (() => void) | undefined; - try { - unpatch = patchRosiesPlugsSection(buildRows); - } catch (e: any) { - logger.error("[RosePlugs] Failed to patch settings:", e?.message ?? e); - } - return () => unpatch?.(); - }); + try { + unpatch = patchRosiesPlugsSection(buildRows); + } catch (e: any) { + logger.error("[RosePlugs] Failed to patch settings:", e?.message ?? e); + } }, onUnload: () => { - teardown(); + unpatch?.(); + unpatch = undefined; }, settings: Settings, }; diff --git a/plugins/rose-utils/src/index.ts b/plugins/rose-utils/src/index.ts index 6b6a08e..9219c08 100644 --- a/plugins/rose-utils/src/index.ts +++ b/plugins/rose-utils/src/index.ts @@ -1,37 +1,28 @@ import { logger } from "@vendetta"; -import { id } from "@vendetta/plugin"; -import { guardPlugin } from "@shared/lib/guard"; import modules from "./modules"; import { vstorage } from "./lib/Module"; import Settings from "./ui/Settings"; -let teardown: () => void = () => {}; - export default { onLoad() { vstorage.modules ??= {}; - teardown = guardPlugin(id, () => { - for (const module of modules) { - try { - if (module.storage.enabled) module.start(); - } catch (e) { - logger.error(`[RoseUtils] Failed to start "${module.label}" on load: ${e}`); - } + for (const module of modules) { + try { + if (module.storage.enabled) module.start(); + } catch (e) { + logger.error(`[RoseUtils] Failed to start "${module.label}" on load: ${e}`); } - return () => { - for (const module of modules) { - try { - module.stop(); - } catch (e) { - logger.error(`[RoseUtils] Failed to stop "${module.label}" cleanly: ${e}`); - } - } - }; - }); + } }, onUnload() { - teardown(); + for (const module of modules) { + try { + module.stop(); + } catch (e) { + logger.error(`[RoseUtils] Failed to stop "${module.label}" cleanly: ${e}`); + } + } }, settings: Settings, }; diff --git a/plugins/server-drawer/src/index.tsx b/plugins/server-drawer/src/index.tsx index 9e61f49..27445e3 100644 --- a/plugins/server-drawer/src/index.tsx +++ b/plugins/server-drawer/src/index.tsx @@ -6,12 +6,11 @@ import { patchExpanded, patchEmpty } from "./patches/contentPatch"; import { patchHideGuildsBar } from "./patches/hideGuildsBar"; import { patchTransparentBackground } from "./patches/transparentBackground"; import { patchCreateElement } from "./patches/createElementIntercept"; -import { id, storage } from "@vendetta/plugin"; -import { guardPlugin } from "@shared/lib/guard"; +import { storage } from "@vendetta/plugin"; import Settings from "./ui/Settings"; const TAG = "[ServerDrawer]"; -let unpatchAll: () => void = () => {}; +const cleanups: (() => void)[] = []; export default { onLoad() { @@ -20,36 +19,30 @@ export default { console.log(TAG, "onLoad"); - unpatchAll = guardPlugin(id, () => { - const cleanups: (() => void)[] = []; - let patched = 0; + let patched = 0; - patchCreateElement(cleanups); - patched++; + patchCreateElement(cleanups); + patched++; - if (patchQuestDockRender(cleanups)) patched++; - if (patchQuestDockBase(cleanups)) patched++; - if (patchMobileQuestDock(cleanups)) patched++; - if (patchGetQuestAsset(cleanups)) patched++; - if (patchExpanded(cleanups)) patched++; - if (patchEmpty("QuestDockContentCollapsed", cleanups)) patched++; - if (patchEmpty("QuestDockEnrolledHeader", cleanups)) patched++; - if (patchEmpty("QuestDockUnenrolledHeader", cleanups)) patched++; - if (patchEmpty("QuestDockEnrolledBody", cleanups)) patched++; - if (patchEmpty("QuestDockUnenrolledBody", cleanups)) patched++; - if (patchHideGuildsBar(cleanups)) patched++; - if (patchTransparentBackground(cleanups)) patched++; + if (patchQuestDockRender(cleanups)) patched++; + if (patchQuestDockBase(cleanups)) patched++; + if (patchMobileQuestDock(cleanups)) patched++; + if (patchGetQuestAsset(cleanups)) patched++; + if (patchExpanded(cleanups)) patched++; + if (patchEmpty("QuestDockContentCollapsed", cleanups)) patched++; + if (patchEmpty("QuestDockEnrolledHeader", cleanups)) patched++; + if (patchEmpty("QuestDockUnenrolledHeader", cleanups)) patched++; + if (patchEmpty("QuestDockEnrolledBody", cleanups)) patched++; + if (patchEmpty("QuestDockUnenrolledBody", cleanups)) patched++; + if (patchHideGuildsBar(cleanups)) patched++; + if (patchTransparentBackground(cleanups)) patched++; - console.log(TAG, `onLoad done — ${patched} patches applied, ${cleanups.length} cleanups`); - return () => { - for (const fn of cleanups) fn(); - cleanups.length = 0; - }; - }); + console.log(TAG, `onLoad done — ${patched} patches applied, ${cleanups.length} cleanups`); }, onUnload() { console.log(TAG, "onUnload"); - unpatchAll(); + for (const fn of cleanups) fn(); + cleanups.length = 0; }, settings: Settings, }; diff --git a/plugins/split-messages/src/index.ts b/plugins/split-messages/src/index.ts index a384a39..7ff3aef 100644 --- a/plugins/split-messages/src/index.ts +++ b/plugins/split-messages/src/index.ts @@ -1,10 +1,8 @@ import { findByProps, findByStoreName } from "@vendetta/metro"; import { instead } from "@vendetta/patcher"; -import { id, storage } from "@vendetta/plugin"; +import { storage } from "@vendetta/plugin"; import { getAssetIDByName } from "@vendetta/ui/assets"; import { showToast } from "@vendetta/ui/toasts"; -import { checkPluginStatus } from "@shared/lib/backend"; -import { checkForUpdate } from "@shared/lib/reload"; import { intoChunks } from "./lib/split"; import Settings from "./ui/Settings"; @@ -22,8 +20,6 @@ export default { onLoad() { storage.splitOnWords ??= false; - checkForUpdate(id).catch(() => {}); - const MaxLengthModule = findByProps("getMaxMessageLength"); const MessageActions = findByProps("sendMessage", "editMessage"); const UserStore = findByStoreName("UserStore"); @@ -75,12 +71,6 @@ export default { } return (async () => { - const status = await checkPluginStatus(UserStore.getCurrentUser()?.id, id); - if (status.blocked) { - showToast("Split Messages is unavailable right now", getAssetIDByName("Small")); - return orig(args); - } - if (hasAttachments) { await sendChunks(channelId, chunks, message); if (chunks.length) await sleep(delayFor(channelId)); @@ -108,12 +98,6 @@ export default { } return (async () => { - const status = await checkPluginStatus(UserStore.getCurrentUser()?.id, id); - if (status.blocked) { - showToast("Split Messages is unavailable right now", getAssetIDByName("Small")); - return orig(args); - } - const result = await orig(withArg(args, 2, { ...message, content: chunks.shift() })); await sendChunks(channelId, chunks, message); return result; diff --git a/plugins/staff-tags/src/index.ts b/plugins/staff-tags/src/index.ts index b83f01d..1473ccb 100644 --- a/plugins/staff-tags/src/index.ts +++ b/plugins/staff-tags/src/index.ts @@ -1,7 +1,6 @@ import { logger } from "@vendetta"; -import { id, storage } from "@vendetta/plugin"; +import { storage } from "@vendetta/plugin"; import { applyPatches } from "@shared/lib/patcher"; -import { guardPlugin } from "@shared/lib/guard"; import patchChat from "./patches/chat"; import patchDetails from "./patches/details"; import patchName from "./patches/name"; @@ -16,13 +15,13 @@ export default { storage.useRoleColor ??= false; storage.tags ??= {}; - unpatchAll = guardPlugin(id, () => applyPatches("Staff Tags", logger, { + unpatchAll = applyPatches("Staff Tags", logger, { tag: patchTag, chat: patchChat, name: patchName, details: patchDetails, profile: patchProfile - })); + }); }, onUnload: () => unpatchAll(), settings: Settings diff --git a/plugins/typing-avatars/src/index.ts b/plugins/typing-avatars/src/index.ts index cad66de..67ed0e0 100644 --- a/plugins/typing-avatars/src/index.ts +++ b/plugins/typing-avatars/src/index.ts @@ -1,16 +1,14 @@ import { logger } from "@vendetta"; -import { id } from "@vendetta/plugin"; import { applyPatches } from "@shared/lib/patcher"; -import { guardPlugin } from "@shared/lib/guard"; import patchTypingIndicator from "./patches/typingIndicator"; let unpatchAll: () => void = () => {}; export default { onLoad: () => { - unpatchAll = guardPlugin(id, () => applyPatches("TypingAvatars", logger, { + unpatchAll = applyPatches("TypingAvatars", logger, { "typing indicator avatars": patchTypingIndicator - })); + }); }, onUnload: () => unpatchAll() }; diff --git a/plugins/urban-dictionary/src/index.ts b/plugins/urban-dictionary/src/index.ts index a4b9d50..fb7f2e3 100644 --- a/plugins/urban-dictionary/src/index.ts +++ b/plugins/urban-dictionary/src/index.ts @@ -1,15 +1,10 @@ -import { id } from "@vendetta/plugin"; -import { guardPlugin } from "@shared/lib/guard"; import loadCommands from "./commands"; -let unpatchAll: () => void = () => {}; +let unregisterFns: (() => void)[] = []; export default { onLoad: () => { - unpatchAll = guardPlugin(id, () => { - const unregisterFns = loadCommands(); - return () => unregisterFns.forEach((fn) => fn()); - }); + unregisterFns = loadCommands(); }, - onUnload: () => unpatchAll() + onUnload: () => unregisterFns.forEach((fn) => fn()) }; diff --git a/plugins/view-raw/src/index.tsx b/plugins/view-raw/src/index.tsx index 5e9a317..479086b 100644 --- a/plugins/view-raw/src/index.tsx +++ b/plugins/view-raw/src/index.tsx @@ -1,13 +1,11 @@ // Forked from bwlok/revenge-plugins (plugins/ViewRaw), GPLv3. Original authors: sapphire, Vendicated, Bwlok. // https://github.com/bwlok/revenge-plugins/tree/master/plugins/ViewRaw import { before, after } from "@vendetta/patcher"; -import { id } from "@vendetta/plugin"; import { getAssetIDByName } from "@vendetta/ui/assets"; import { findInReactTree } from "@vendetta/utils"; import { findByName, findByProps } from "@vendetta/metro"; import { React } from "@vendetta/metro/common"; import { Forms } from "@vendetta/ui/components"; -import { guardPlugin } from "@shared/lib/guard"; import RawPage from "./RawPage"; import { recordDetection } from "./lib/diagnostics"; import Settings from "./ui/Settings"; @@ -66,10 +64,9 @@ function actionSheetRowButton(navigator: () => JSX.Element) { ); } -function applyViewRawPatches(): () => void { - const patches: (() => void)[] = []; +const patches: (() => void)[] = []; - const unpatchOpenLazy = before("openLazy", LazyActionSheet, ([component, key, msg]) => { +const unpatchOpenLazy = before("openLazy", LazyActionSheet, ([component, key, msg]) => { if (key !== "MessageLongPressActionSheet" || !msg?.message) return; component.then((instance: any) => { @@ -159,15 +156,7 @@ function applyViewRawPatches(): () => void { patches.push(unpatchOpenLazy); - return () => patches.forEach((unpatch) => unpatch()); -} - -let unpatchAll: () => void = () => {}; - export default { - onLoad: () => { - unpatchAll = guardPlugin(id, applyViewRawPatches); - }, - onUnload: () => unpatchAll(), + onUnload: () => patches.forEach((unpatch) => unpatch()), settings: Settings, }; diff --git a/plugins/you-bar-plus/src/index.ts b/plugins/you-bar-plus/src/index.ts index 894b62b..c545aeb 100644 --- a/plugins/you-bar-plus/src/index.ts +++ b/plugins/you-bar-plus/src/index.ts @@ -1,6 +1,5 @@ import { logger } from "@vendetta"; -import { id, storage } from "@vendetta/plugin"; -import { guardPlugin } from "@shared/lib/guard"; +import { storage } from "@vendetta/plugin"; import patchYouBarButtons from "./patches/youBarButtons"; import { setInboxTracking } from "./lib/notifications"; import Settings from "./ui/Settings"; @@ -32,8 +31,6 @@ function attempt() { } } -let teardown: () => void = () => {}; - export default { onLoad: () => { storage.showDMButton ??= false; @@ -43,23 +40,18 @@ export default { setInboxTracking(!!storage.showInboxButton); - teardown = guardPlugin(id, () => { - attempt(); - if (!patched) { - let ticks = 0; - retryHandle = setInterval(() => { - attempt(); - if (++ticks >= 30) stopRetrying(); // ~9s at 300ms, then give up - }, 300); - } - return () => { - stopRetrying(); - unpatchButtons(); - }; - }); + attempt(); + if (!patched) { + let ticks = 0; + retryHandle = setInterval(() => { + attempt(); + if (++ticks >= 30) stopRetrying(); // ~9s at 300ms, then give up + }, 300); + } }, onUnload: () => { - teardown(); + stopRetrying(); + unpatchButtons(); setInboxTracking(false); }, settings: Settings diff --git a/plugins/zipline/src/index.ts b/plugins/zipline/src/index.ts index 8296b07..c47b640 100644 --- a/plugins/zipline/src/index.ts +++ b/plugins/zipline/src/index.ts @@ -1,7 +1,5 @@ import { logger } from "@vendetta"; -import { id } from "@vendetta/plugin"; import { applyPatches } from "@shared/lib/patcher"; -import { guardPlugin } from "@shared/lib/guard"; import patchAutoProcess from "./patches/autoProcess"; import { zStorage } from "./lib/api"; import Settings from "./ui/Settings"; @@ -12,9 +10,9 @@ export default { onLoad: () => { zStorage(); - unpatchAll = guardPlugin(id, () => applyPatches("Zipline", logger, { + unpatchAll = applyPatches("Zipline", logger, { autoProcess: patchAutoProcess, - })); + }); }, onUnload: () => unpatchAll(), settings: Settings, diff --git a/shared/lib/backend.ts b/shared/lib/backend.ts deleted file mode 100644 index b49bcb8..0000000 --- a/shared/lib/backend.ts +++ /dev/null @@ -1,48 +0,0 @@ -const BASE_URL = "https://revenge-plugins-backend.allyapp.workers.dev"; - -export interface PluginStatus { - blocked: boolean; - latestHash: string | null; -} - -export async function checkPluginStatus(userId: string | undefined, manifestUrl?: string): Promise { - if (!userId) return { blocked: true, latestHash: null }; - - try { - const params = new URLSearchParams({ userId }); - if (manifestUrl) params.set("manifestUrl", manifestUrl); - - const res = await fetch(`${BASE_URL}/status?${params}`); - if (!res.ok) return { blocked: true, latestHash: null }; - - const data = await res.json(); - return { blocked: data?.blocked !== false, latestHash: data?.latestHash ?? null }; - } catch { - return { blocked: true, latestHash: null }; - } -} - -export async function syncPull(pluginId: string, authToken: string): Promise { - const res = await fetch(`${BASE_URL}/sync/${pluginId}`, { - headers: { Authorization: authToken } - }); - if (!res.ok) throw new Error(`Sync pull failed: ${res.status}`); - return res.json(); -} - -export async function syncPush(pluginId: string, authToken: string, data: unknown): Promise { - const res = await fetch(`${BASE_URL}/sync/${pluginId}`, { - method: "PUT", - headers: { Authorization: authToken, "Content-Type": "application/json" }, - body: JSON.stringify(data) - }); - if (!res.ok) throw new Error(`Sync push failed: ${res.status}`); -} - -export async function syncDelete(pluginId: string, authToken: string): Promise { - const res = await fetch(`${BASE_URL}/sync/${pluginId}`, { - method: "DELETE", - headers: { Authorization: authToken } - }); - if (!res.ok) throw new Error(`Sync delete failed: ${res.status}`); -} diff --git a/shared/lib/guard.ts b/shared/lib/guard.ts deleted file mode 100644 index 8df61e6..0000000 --- a/shared/lib/guard.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { findByStoreName } from "@vendetta/metro"; -import { checkPluginStatus } from "./backend"; -import { checkForUpdate } from "./reload"; - -const UserStore = findByStoreName("UserStore"); - -export function guardPlugin(pluginId: string, applyPatches: () => () => void): () => void { - let unpatch = applyPatches(); - let unloaded = false; - - checkPluginStatus(UserStore?.getCurrentUser?.()?.id, pluginId).then((status) => { - if (unloaded || !status.blocked) return; - unpatch(); - unpatch = () => {}; - }); - - checkForUpdate(pluginId).catch(() => {}); - - return () => { - unloaded = true; - unpatch(); - }; -} diff --git a/shared/lib/reload.ts b/shared/lib/reload.ts deleted file mode 100644 index c52a15e..0000000 --- a/shared/lib/reload.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { fetchPlugin, plugins, startPlugin, stopPlugin } from "@vendetta/plugins"; -import { findByStoreName } from "@vendetta/metro"; -import { checkPluginStatus } from "./backend"; - -const UserStore = findByStoreName("UserStore"); - -export async function checkForUpdate(pluginId: string): Promise { - const plugin = plugins[pluginId]; - if (!plugin) return; - - const userId = UserStore?.getCurrentUser?.()?.id; - const status = await checkPluginStatus(userId, pluginId); - if (status.blocked || !status.latestHash || status.latestHash === plugin.manifest.hash) return; - - stopPlugin(pluginId); - await fetchPlugin(pluginId); - await startPlugin(pluginId); -}