Resolve PluginSettings circular deps better

This commit is contained in:
Nuckyz 2024-05-04 23:15:33 -03:00
parent ce18000c4e
commit 60e6fdacfa
No known key found for this signature in database
GPG key ID: 440BF8296E1C4AD9
3 changed files with 20 additions and 16 deletions

View file

@ -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");

View file

@ -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<string, Array<Record<"tooltip" | "badge", string>>>;

View file

@ -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)),