|
|
@ -1,9 +1,9 @@
|
|
|
|
import { useAwaiter } from "../utils/misc";
|
|
|
|
import { humanFriendlyJoin, useAwaiter } from "../utils/misc";
|
|
|
|
import Plugins from 'plugins';
|
|
|
|
import Plugins from 'plugins';
|
|
|
|
import { useSettings } from "../api/settings";
|
|
|
|
import { useSettings } from "../api/settings";
|
|
|
|
import IpcEvents from "../utils/IpcEvents";
|
|
|
|
import IpcEvents from "../utils/IpcEvents";
|
|
|
|
|
|
|
|
|
|
|
|
import { Button, ButtonProps, Flex, Switch, Forms } from "../webpack/common";
|
|
|
|
import { Button, ButtonProps, Flex, Switch, Forms, React } from "../webpack/common";
|
|
|
|
import ErrorBoundary from "./ErrorBoundary";
|
|
|
|
import ErrorBoundary from "./ErrorBoundary";
|
|
|
|
import { startPlugin } from "../plugins";
|
|
|
|
import { startPlugin } from "../plugins";
|
|
|
|
import { stopPlugin } from '../plugins/index';
|
|
|
|
import { stopPlugin } from '../plugins/index';
|
|
|
@ -12,6 +12,22 @@ export default ErrorBoundary.wrap(function Settings(props) {
|
|
|
|
const [settingsDir, , settingsDirPending] = useAwaiter(() => VencordNative.ipc.invoke<string>(IpcEvents.GET_SETTINGS_DIR), "Loading...");
|
|
|
|
const [settingsDir, , settingsDirPending] = useAwaiter(() => VencordNative.ipc.invoke<string>(IpcEvents.GET_SETTINGS_DIR), "Loading...");
|
|
|
|
const settings = useSettings();
|
|
|
|
const settings = useSettings();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const depMap = React.useMemo(() => {
|
|
|
|
|
|
|
|
const o = {} as Record<string, string[]>;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
console.log(depMap);
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
<Forms.FormSection tag="h1" title="Vencord">
|
|
|
|
<Forms.FormSection tag="h1" title="Vencord">
|
|
|
|
<Forms.FormText>SettingsDir: {settingsDir}</Forms.FormText>
|
|
|
|
<Forms.FormText>SettingsDir: {settingsDir}</Forms.FormText>
|
|
|
@ -45,39 +61,50 @@ export default ErrorBoundary.wrap(function Settings(props) {
|
|
|
|
</Switch>
|
|
|
|
</Switch>
|
|
|
|
<Forms.FormDivider />
|
|
|
|
<Forms.FormDivider />
|
|
|
|
<Forms.FormTitle tag="h5">Plugins</Forms.FormTitle>
|
|
|
|
<Forms.FormTitle tag="h5">Plugins</Forms.FormTitle>
|
|
|
|
{Object.values(Plugins).map(p => (
|
|
|
|
{Object.values(Plugins).map(p => {
|
|
|
|
<Switch
|
|
|
|
const enabledDependants = depMap[p.name]?.filter(d => settings.plugins[d].enabled);
|
|
|
|
disabled={p.required === true}
|
|
|
|
const dependency = enabledDependants?.length;
|
|
|
|
key={p.name}
|
|
|
|
|
|
|
|
value={settings.plugins[p.name].enabled}
|
|
|
|
return (
|
|
|
|
onChange={v => {
|
|
|
|
<Switch
|
|
|
|
settings.plugins[p.name].enabled = v;
|
|
|
|
disabled={p.required || dependency}
|
|
|
|
if (v) {
|
|
|
|
key={p.name}
|
|
|
|
p.dependencies?.forEach(d => {
|
|
|
|
value={settings.plugins[p.name].enabled || p.required || dependency}
|
|
|
|
settings.plugins[d].enabled = true;
|
|
|
|
onChange={v => {
|
|
|
|
if (!Plugins[d].started && !stopPlugin) {
|
|
|
|
settings.plugins[p.name].enabled = v;
|
|
|
|
|
|
|
|
if (v) {
|
|
|
|
|
|
|
|
p.dependencies?.forEach(d => {
|
|
|
|
|
|
|
|
settings.plugins[d].enabled = true;
|
|
|
|
|
|
|
|
if (!Plugins[d].started && !stopPlugin) {
|
|
|
|
|
|
|
|
// TODO show notification
|
|
|
|
|
|
|
|
settings.plugins[p.name].enabled = false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!p.started && !startPlugin(p)) {
|
|
|
|
|
|
|
|
// TODO show notification
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if (p.started && !stopPlugin(p)) {
|
|
|
|
// TODO show notification
|
|
|
|
// TODO show notification
|
|
|
|
settings.plugins[p.name].enabled = false;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!p.started && !startPlugin(p)) {
|
|
|
|
|
|
|
|
// TODO show notification
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (p.patches) {
|
|
|
|
if (p.started && !stopPlugin(p)) {
|
|
|
|
|
|
|
|
// TODO show notification
|
|
|
|
// TODO show notification
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}}
|
|
|
|
|
|
|
|
note={p.description}
|
|
|
|
|
|
|
|
tooltipNote={
|
|
|
|
|
|
|
|
p.required ?
|
|
|
|
|
|
|
|
"This plugin is required. Thus you cannot disable it."
|
|
|
|
|
|
|
|
: dependency ?
|
|
|
|
|
|
|
|
`${humanFriendlyJoin(enabledDependants)} ${enabledDependants.length === 1 ? "depends" : "depend"} on this plugin. Thus you cannot disable it.`
|
|
|
|
|
|
|
|
: ""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (p.patches) {
|
|
|
|
>
|
|
|
|
// TODO show notification
|
|
|
|
{p.name}
|
|
|
|
}
|
|
|
|
</Switch>
|
|
|
|
}}
|
|
|
|
);
|
|
|
|
note={p.description}
|
|
|
|
})
|
|
|
|
tooltipNote={p.required ? "This plugin is required. Thus you cannot disable it." : undefined}
|
|
|
|
|
|
|
|
>
|
|
|
|
|
|
|
|
{p.name}
|
|
|
|
|
|
|
|
</Switch>
|
|
|
|
|
|
|
|
))
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</Forms.FormSection >
|
|
|
|
</Forms.FormSection >
|
|
|
|
);
|
|
|
|
);
|
|
|
|