From 60e6fdacfa2b07d27b69b9a0ab52a5e5ccfa689b Mon Sep 17 00:00:00 2001 From: Nuckyz <61953774+Nuckyz@users.noreply.github.com> Date: Sat, 4 May 2024 23:15:33 -0300 Subject: [PATCH] Resolve PluginSettings circular deps better --- src/components/PluginSettings/index.tsx | 5 +++-- src/plugins/_api/badges/index.tsx | 8 ++------ src/plugins/_core/settings.tsx | 23 +++++++++++++++-------- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/components/PluginSettings/index.tsx b/src/components/PluginSettings/index.tsx index 33a472c1..e6b2cf1f 100644 --- a/src/components/PluginSettings/index.tsx +++ b/src/components/PluginSettings/index.tsx @@ -27,6 +27,7 @@ import PluginModal from "@components/PluginSettings/PluginModal"; import { AddonCard } from "@components/VencordSettings/AddonCard"; import { SettingsTab } from "@components/VencordSettings/shared"; import { ChangeList } from "@utils/ChangeList"; +import { proxyLazy } from "@utils/lazy"; import { Logger } from "@utils/Logger"; import { Margins } from "@utils/margins"; import { classes, isObjectEmpty } from "@utils/misc"; @@ -38,8 +39,8 @@ import { Alerts, Button, Card, Forms, lodash, Parser, React, Select, Text, TextI import Plugins from "~plugins"; -import { startDependenciesRecursive, startPlugin, stopPlugin } from "../../plugins"; - +// Avoid circular dependency +const { startDependenciesRecursive, startPlugin, stopPlugin } = proxyLazy(() => require("../../plugins")); const cl = classNameFactory("vc-plugins-"); const logger = new Logger("PluginSettings", "#a6d189"); diff --git a/src/plugins/_api/badges/index.tsx b/src/plugins/_api/badges/index.tsx index 5493d4b6..bbccf0a1 100644 --- a/src/plugins/_api/badges/index.tsx +++ b/src/plugins/_api/badges/index.tsx @@ -23,6 +23,7 @@ import DonateButton from "@components/DonateButton"; import ErrorBoundary from "@components/ErrorBoundary"; import { Flex } from "@components/Flex"; import { Heart } from "@components/Heart"; +import { openContributorModal } from "@components/PluginSettings/ContributorModal"; import { Devs } from "@utils/constants"; import { Margins } from "@utils/margins"; import { isPluginDev } from "@utils/misc"; @@ -37,12 +38,7 @@ const ContributorBadge: ProfileBadge = { image: CONTRIBUTOR_BADGE, position: BadgePosition.START, shouldShow: ({ user }) => isPluginDev(user.id), - onClick(_, { user }) { - // circular import shenanigans - const { openContributorModal } = require("@components/PluginSettings/ContributorModal") as typeof import("@components/PluginSettings/ContributorModal"); - // setImmediate is needed to run on later tick to workaround limitation in proxyLazy - setImmediate(() => openContributorModal(user)); - } + onClick: (_, { user }) => openContributorModal(user) }; let DonorBadges = {} as Record>>; diff --git a/src/plugins/_core/settings.tsx b/src/plugins/_core/settings.tsx index 1aea0d6e..772ee9b6 100644 --- a/src/plugins/_core/settings.tsx +++ b/src/plugins/_core/settings.tsx @@ -17,6 +17,13 @@ */ import { Settings } from "@api/Settings"; +import BackupAndRestoreTab from "@components/VencordSettings/BackupAndRestoreTab"; +import CloudTab from "@components/VencordSettings/CloudTab"; +import PatchHelperTab from "@components/VencordSettings/PatchHelperTab"; +import PluginsTab from "@components/VencordSettings/PluginsTab"; +import ThemesTab from "@components/VencordSettings/ThemesTab"; +import UpdaterTab from "@components/VencordSettings/UpdaterTab"; +import VencordTab from "@components/VencordSettings/VencordTab"; import { Devs } from "@utils/constants"; import definePlugin, { OptionType } from "@utils/types"; import { React } from "@webpack/common"; @@ -36,7 +43,7 @@ export default definePlugin({ match: /\[\(0,.{1,3}\.jsxs?\)\((.{1,10}),(\{[^{}}]+\{.{0,20}.versionHash,.+?\})\)," "/, replace: (m, component, props) => { props = props.replace(/children:\[.+\]/, ""); - return `${m},Vencord.Plugins.plugins.Settings.makeInfoElements(${component}, ${props})`; + return `${m},$self.makeInfoElements(${component}, ${props})`; } } ] @@ -77,43 +84,43 @@ export default definePlugin({ { section: "VencordSettings", label: "Vencord", - element: require("@components/VencordSettings/VencordTab").default, + element: VencordTab, className: "vc-settings" }, { section: "VencordPlugins", label: "Plugins", - element: require("@components/VencordSettings/PluginsTab").default, + element: PluginsTab, className: "vc-plugins" }, { section: "VencordThemes", label: "Themes", - element: require("@components/VencordSettings/ThemesTab").default, + element: ThemesTab, className: "vc-themes" }, !IS_UPDATER_DISABLED && { section: "VencordUpdater", label: "Updater", - element: require("@components/VencordSettings/UpdaterTab").default, + element: UpdaterTab, className: "vc-updater" }, { section: "VencordCloud", label: "Cloud", - element: require("@components/VencordSettings/CloudTab").default, + element: CloudTab, className: "vc-cloud" }, { section: "VencordSettingsSync", label: "Backup & Restore", - element: require("@components/VencordSettings/BackupAndRestoreTab").default, + element: BackupAndRestoreTab, className: "vc-backup-restore" }, IS_DEV && { section: "VencordPatchHelper", label: "Patch Helper", - element: require("@components/VencordSettings/PatchHelperTab").default, + element: PatchHelperTab, className: "vc-patch-helper" }, ...this.customSections.map(func => func(SectionTypes)),