import Plugins from "plugins"; import { Settings, useSettings } from "../../api/settings"; import { startPlugin, stopPlugin } from "../../plugins"; import { Modals } from "../../utils"; import { ChangeList } from "../../utils/ChangeList"; import { classes, lazyWebpack } from "../../utils/misc"; import { Plugin } from "../../utils/types"; import { filters } from "../../webpack"; import { Alerts, Button, Forms, Margins, Parser, React, Text, TextInput, Toasts, Tooltip } from "../../webpack/common"; import ErrorBoundary from "../ErrorBoundary"; import { Flex } from "../Flex"; import PluginModal from "./PluginModal"; import * as styles from "./styles"; const Select = lazyWebpack(filters.byCode("optionClassName", "popoutPosition", "autoFocus", "maxVisibleItems")); const InputStyles = lazyWebpack(filters.byProps(["inputDefault", "inputWrapper"])); function showErrorToast(message: string) { Toasts.show({ message, type: Toasts.Type.FAILURE, id: Toasts.genId(), options: { position: Toasts.Position.BOTTOM } }); } interface PluginCardProps extends React.HTMLProps { plugin: Plugin; disabled: boolean; onRestartNeeded(): void; } function PluginCard({ plugin, disabled, onRestartNeeded, onMouseEnter, onMouseLeave }: PluginCardProps) { const settings = useSettings().plugins[plugin.name]; function isEnabled() { return settings?.enabled || plugin.started; } function openModal() { Modals.openModalLazy(async () => { return modalProps => { return ; }; }); } function toggleEnabled() { const enabled = isEnabled(); const result = enabled ? stopPlugin(plugin) : startPlugin(plugin); const action = enabled ? "stop" : "start"; if (!result) { showErrorToast(`Failed to ${action} plugin: ${plugin.name}`); return; } settings.enabled = !settings.enabled; if (plugin.patches) onRestartNeeded(); } return ( openModal()} onMouseEnter={onMouseEnter} onMouseLeave={onMouseLeave}> {plugin.name} {plugin.description} {plugin.options && Click to configure} ); } export default ErrorBoundary.wrap(function Settings() { const settings = useSettings(); const changes = React.useMemo(() => new ChangeList(), []); React.useEffect(() => { return () => void (changes.hasChanges && Alerts.show({ title: "Restart required", body: ( <>

The following plugins require a restart:

{changes.map((s, i) => ( <> {i > 0 && ", "} {Parser.parse("`" + s + "`")} ))}
), confirmText: "Restart now", cancelText: "Later!", onConfirm: () => location.reload() })); }, []); const depMap = React.useMemo(() => { const o = {} as Record; for (const plugin in Plugins) { const deps = Plugins[plugin].dependencies; if (deps) { for (const dep of deps) { o[dep] ??= []; o[dep].push(plugin); } } } return o; }, []); function hasDependents(plugin: Plugin) { const enabledDependants = depMap[plugin.name]?.filter(d => settings.plugins[d].enabled); return !!enabledDependants?.length; } const sortedPlugins = React.useMemo(() => Object.values(Plugins) .sort((a, b) => a.name.localeCompare(b.name)), []); const [searchValue, setSearchValue] = React.useState({ value: "", status: "all" }); const onSearch = (query: string) => setSearchValue(prev => ({ ...prev, value: query })); const onStatusChange = (status: string) => setSearchValue(prev => ({ ...prev, status })); const pluginFilter = (plugin: typeof Plugins[keyof typeof Plugins]) => { const showEnabled = searchValue.status === "enabled" || searchValue.status === "all"; const showDisabled = searchValue.status === "disabled" || searchValue.status === "all"; const enabled = settings.plugins[plugin.name]?.enabled || plugin.started; return ( ((showEnabled && enabled) || (showDisabled && !enabled)) && ( plugin.name.toLowerCase().includes(searchValue.value.toLowerCase()) || plugin.description.toLowerCase().includes(searchValue.value.toLowerCase()) ) ); }; return ( Plugins