aboutsummaryrefslogtreecommitdiff
path: root/src/components/VencordSettings/index.tsx
blob: 37dab8f50f1927d949d5780eee809b8693ac73b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
 * 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 <https://www.gnu.org/licenses/>.
*/

import ErrorBoundary from "@components/ErrorBoundary";
import { findByCodeLazy } from "@webpack";
import { Forms, Router, Text } from "@webpack/common";

import cssText from "~fileContent/settingsStyles.css";

import BackupRestoreTab from "./BackupRestoreTab";
import PluginsTab from "./PluginsTab";
import Updater from "./Updater";
import VencordSettings from "./VencordTab";

const style = document.createElement("style");
style.textContent = cssText;
document.head.appendChild(style);

const st = (style: string) => `vcSettings${style}`;

const TabBar = findByCodeLazy('[role="tab"][aria-disabled="false"]');

interface SettingsProps {
    tab: string;
}

interface SettingsTab {
    name: string;
    component?: React.ComponentType;
}

const SettingsTabs: Record<string, SettingsTab> = {
    VencordSettings: { name: "Vencord", component: () => <VencordSettings /> },
    VencordPlugins: { name: "Plugins", component: () => <PluginsTab /> },
    VencordThemes: { name: "Themes", component: () => <Text variant="text-md/medium">Coming soon to a Vencord near you!</Text> },
    VencordUpdater: { name: "Updater" }, // Only show updater if IS_WEB is false
    VencordSettingsSync: { name: "Backup & Restore", component: () => <BackupRestoreTab /> },
};

if (!IS_WEB) SettingsTabs.VencordUpdater.component = () => Updater && <Updater />;

function Settings(props: SettingsProps) {
    const { tab = "VencordSettings" } = props;

    const CurrentTab = SettingsTabs[tab]?.component;

    return <Forms.FormSection>
        <Text variant="heading-md/normal" tag="h2">Vencord Settings</Text>

        <TabBar
            type={TabBar.Types.TOP}
            look={TabBar.Looks.BRAND}
            className={st("TabBar")}
            selectedItem={tab}
            onItemSelect={Router.open}
        >
            {Object.entries(SettingsTabs).map(([key, { name, component }]) => {
                if (!component) return null;
                return <TabBar.Item
                    id={key}
                    className={st("TabBarItem")}
                    key={key}>
                    {name}
                </TabBar.Item>;
            })}
        </TabBar>
        <Forms.FormDivider />
        {CurrentTab && <CurrentTab />}
    </Forms.FormSection >;
}

export default function (props: SettingsProps) {
    return <ErrorBoundary>
        <Settings tab={props.tab} />
    </ErrorBoundary>;
}