/* * Vencord, a modification for Discord's desktop app * Copyright (c) 2022 Vendicated and contributors * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ import "./styles.css"; import * as DataStore from "@api/DataStore"; import { useSettings } from "@api/Settings"; import { classNameFactory } from "@api/Styles"; import { Divider } from "@components/Divider"; import ErrorBoundary from "@components/ErrorBoundary"; import { HeadingTertiary } from "@components/Heading"; import { Paragraph } from "@components/Paragraph"; import { SettingsTab } from "@components/settings"; import { debounce } from "@shared/debounce"; import { ChangeList } from "@utils/ChangeList"; import { proxyLazy } from "@utils/lazy"; import { Logger } from "@utils/Logger"; import { Margins } from "@utils/margins"; import { classes } from "@utils/misc"; import { useAwaiter, useIntersection } from "@utils/react"; import { Alerts, Button, Card, lodash, Parser, React, Select, TextInput, Toasts, Tooltip, useMemo } from "@webpack/common"; import { JSX } from "react"; import Plugins, { ExcludedPlugins, PluginMeta } from "~plugins"; import { PluginCard } from "./PluginCard"; import { openWarningModal } from "./PluginModal"; import { StockPluginsCard, UserPluginsCard } from "./PluginStatCards"; // Avoid circular dependency const { startDependenciesRecursive, startPlugin, stopPlugin } = proxyLazy(() => require("plugins")); export const cl = classNameFactory("vc-plugins-"); export const logger = new Logger("PluginSettings", "#a6d189"); function showErrorToast(message: string) { Toasts.show({ message, type: Toasts.Type.FAILURE, id: Toasts.genId(), options: { position: Toasts.Position.BOTTOM } }); } function ReloadRequiredCard({ required, enabledPlugins, openWarningModal, resetCheckAndDo }) { return ( {required ? ( <> Restart required! Restart now to apply new plugins and their settings ) : ( <> Plugin Management Press the cog wheel or info icon to get more info on a plugin Plugins with a cog wheel have settings you can modify! )} {enabledPlugins.length > 0 && !required && ( )} ); } const enum SearchStatus { ALL, ENABLED, DISABLED, EQUICORD, VENCORD, CUSTOM, NEW, } export const ExcludedReasons: Record<"web" | "discordDesktop" | "vesktop" | "equibop" | "desktop" | "dev", string> = { desktop: "Discord Desktop app or Vesktop", discordDesktop: "Discord Desktop app", vesktop: "Vesktop & Equibop apps", equibop: "Vesktop & Equibop apps", web: "Vesktop & Equibop apps as well as the Web version of Discord", dev: "Developer version of Equicord" }; function ExcludedPluginsList({ search }: { search: string; }) { const matchingExcludedPlugins = Object.entries(ExcludedPlugins) .filter(([name]) => name.toLowerCase().includes(search)); return ( {matchingExcludedPlugins.length ? <> Are you looking for: : "No plugins meet the search criteria." } ); } export default function PluginSettings() { const settings = useSettings(); const changes = React.useMemo(() => new ChangeList(), []); React.useEffect(() => { return () => { if (!changes.hasChanges) return; const allChanges = [...changes.getChanges()]; const maxDisplay = 15; const displayed = allChanges.slice(0, maxDisplay); const remainingCount = allChanges.length - displayed.length; Alerts.show({ title: "Restart required", body: (
{displayed.map((s, i) => ( {i > 0 && ", "} {Parser.parse("`" + s + "`")} ))} {remainingCount > 0 && and {remainingCount} more}
), confirmText: "Restart now", cancelText: "Later!", onConfirm: () => location.reload() }); }; }, []); const depMap = Vencord.Plugins.calculatePluginDependencyMap(); const sortedPlugins = useMemo(() => Object.values(Plugins) .sort((a, b) => a.name.localeCompare(b.name)), []); const [searchValue, setSearchValue] = React.useState({ value: "", status: SearchStatus.ALL }); const search = searchValue.value.toLowerCase(); const onSearch = (query: string) => { setSearchValue(prev => ({ ...prev, value: query })); }; const onStatusChange = (status: SearchStatus) => { setSearchValue(prev => ({ ...prev, status })); }; const pluginFilter = (plugin: typeof Plugins[keyof typeof Plugins]) => { const { status } = searchValue; const enabled = Vencord.Plugins.isPluginEnabled(plugin.name); const pluginMeta = PluginMeta[plugin.name]; const isEquicordPlugin = pluginMeta.folderName.startsWith("src/equicordplugins/") ?? false; const isUserplugin = pluginMeta.userPlugin ?? false; if (enabled && status === SearchStatus.DISABLED) return false; if (!enabled && status === SearchStatus.ENABLED) return false; if (status === SearchStatus.NEW && !newPlugins?.includes(plugin.name)) return false; if (status === SearchStatus.EQUICORD && !isEquicordPlugin) return false; if (status === SearchStatus.VENCORD && isEquicordPlugin) return false; if (status === SearchStatus.CUSTOM && !isUserplugin) return false; if (!search.length) return true; return ( plugin.name.toLowerCase().includes(search.replace(/\s+/g, "")) || plugin.description.toLowerCase().includes(search) || plugin.tags?.some(t => t.toLowerCase().includes(search)) ); }; const [newPlugins] = useAwaiter(() => DataStore.get("Vencord_existingPlugins").then((cachedPlugins: Record | undefined) => { const now = Date.now() / 1000; const existingTimestamps: Record = {}; const sortedPluginNames = Object.values(sortedPlugins).map(plugin => plugin.name); const newPlugins: string[] = []; for (const { name: p } of sortedPlugins) { const time = existingTimestamps[p] = cachedPlugins?.[p] ?? now; if ((time + 60 * 60 * 24 * 2) > now) { newPlugins.push(p); } } DataStore.set("Vencord_existingPlugins", existingTimestamps); return lodash.isEqual(newPlugins, sortedPluginNames) ? [] : newPlugins; })); const plugins = [] as JSX.Element[]; const requiredPlugins = [] as JSX.Element[]; const showApi = searchValue.value.includes("API"); for (const p of sortedPlugins) { if (p.hidden || (!p.options && p.name.endsWith("API") && !showApi)) continue; if (!pluginFilter(p)) continue; const isRequired = p.required || p.isDependency || depMap[p.name]?.some(d => settings.plugins[d].enabled); if (isRequired) { const tooltipText = p.required || !depMap[p.name] ? "This plugin is required for Equicord to function." : settings.plugins[d].enabled)} />; requiredPlugins.push( {({ onMouseLeave, onMouseEnter }) => ( changes.handleChange(name)} disabled={true} plugin={p} key={p.name} /> )} ); } else { plugins.push( changes.handleChange(name)} disabled={false} plugin={p} isNew={newPlugins?.includes(p.name)} key={p.name} /> ); } } function resetCheckAndDo() { let restartNeeded = false; for (const plugin of enabledPlugins) { const pluginSettings = settings.plugins[plugin]; if (Plugins[plugin].patches?.length) { pluginSettings.enabled = false; changes.handleChange(plugin); restartNeeded = true; continue; } const result = stopPlugin(Plugins[plugin]); if (!result) { logger.error(`Error while stopping plugin ${plugin}`); showErrorToast(`Error while stopping plugin ${plugin}`); continue; } pluginSettings.enabled = false; } if (restartNeeded) { Alerts.show({ title: "Restart Required", body: ( <>

Some plugins require a restart to fully disable.

Would you like to restart now?

), confirmText: "Restart Now", cancelText: "Later", onConfirm: () => location.reload() }); } } // Code directly taken from supportHelper.tsx const isApiPlugin = (plugin: string) => plugin.endsWith("API") || Plugins[plugin].required; const totalPlugins = Object.keys(Plugins).filter(p => !isApiPlugin(p)); const enabledPlugins = Object.keys(Plugins).filter(p => Vencord.Plugins.isPluginEnabled(p) && !isApiPlugin(p)); const totalStockPlugins = totalPlugins.filter(p => !PluginMeta[p].userPlugin && !Plugins[p].hidden).length; const totalUserPlugins = totalPlugins.filter(p => PluginMeta[p].userPlugin).length; const enabledStockPlugins = enabledPlugins.filter(p => !PluginMeta[p].userPlugin).length; const enabledUserPlugins = enabledPlugins.filter(p => PluginMeta[p].userPlugin).length; const pluginsToLoad = Math.min(36, plugins.length); const [visibleCount, setVisibleCount] = React.useState(pluginsToLoad); const loadMore = React.useCallback(() => { setVisibleCount(v => Math.min(v + pluginsToLoad, plugins.length)); }, [plugins.length]); const dLoadMore = useMemo(() => debounce(loadMore, 100), [loadMore]); const [sentinelRef, isSentinelVisible] = useIntersection(); React.useEffect(() => { if (isSentinelVisible && visibleCount < plugins.length) { dLoadMore(); } }, [isSentinelVisible, visibleCount, plugins.length, dLoadMore]); const visiblePlugins = plugins.slice(0, visibleCount); return (
Filters