2022-11-25 22:38:55 +00:00
|
|
|
/*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2022-12-25 19:47:35 +00:00
|
|
|
import "./settingsStyles.css";
|
|
|
|
|
2023-01-03 01:30:54 +00:00
|
|
|
import { classNameFactory } from "@api/Styles";
|
2022-11-28 12:58:14 +00:00
|
|
|
import ErrorBoundary from "@components/ErrorBoundary";
|
2022-11-28 12:37:55 +00:00
|
|
|
import { findByCodeLazy } from "@webpack";
|
2023-01-25 02:25:29 +00:00
|
|
|
import { Forms, SettingsRouter, Text } from "@webpack/common";
|
2022-11-28 12:37:55 +00:00
|
|
|
|
2022-11-25 22:38:55 +00:00
|
|
|
import BackupRestoreTab from "./BackupRestoreTab";
|
|
|
|
import PluginsTab from "./PluginsTab";
|
2022-12-01 02:01:44 +00:00
|
|
|
import ThemesTab from "./ThemesTab";
|
2022-11-25 22:38:55 +00:00
|
|
|
import Updater from "./Updater";
|
|
|
|
import VencordSettings from "./VencordTab";
|
|
|
|
|
2023-01-03 01:30:54 +00:00
|
|
|
const cl = classNameFactory("vc-settings-");
|
2022-11-25 22:38:55 +00:00
|
|
|
|
2022-11-28 12:37:55 +00:00
|
|
|
const TabBar = findByCodeLazy('[role="tab"][aria-disabled="false"]');
|
2022-11-25 22:38:55 +00:00
|
|
|
|
|
|
|
interface SettingsProps {
|
|
|
|
tab: string;
|
|
|
|
}
|
|
|
|
|
2022-11-27 15:07:31 +00:00
|
|
|
interface SettingsTab {
|
|
|
|
name: string;
|
|
|
|
component?: React.ComponentType;
|
|
|
|
}
|
|
|
|
|
|
|
|
const SettingsTabs: Record<string, SettingsTab> = {
|
2022-11-25 22:38:55 +00:00
|
|
|
VencordSettings: { name: "Vencord", component: () => <VencordSettings /> },
|
|
|
|
VencordPlugins: { name: "Plugins", component: () => <PluginsTab /> },
|
2022-12-01 02:01:44 +00:00
|
|
|
VencordThemes: { name: "Themes", component: () => <ThemesTab /> },
|
2022-11-27 15:07:31 +00:00
|
|
|
VencordUpdater: { name: "Updater" }, // Only show updater if IS_WEB is false
|
2022-11-25 22:38:55 +00:00
|
|
|
VencordSettingsSync: { name: "Backup & Restore", component: () => <BackupRestoreTab /> },
|
|
|
|
};
|
|
|
|
|
2022-11-27 15:07:31 +00:00
|
|
|
if (!IS_WEB) SettingsTabs.VencordUpdater.component = () => Updater && <Updater />;
|
2022-11-25 22:38:55 +00:00
|
|
|
|
|
|
|
function Settings(props: SettingsProps) {
|
|
|
|
const { tab = "VencordSettings" } = props;
|
|
|
|
|
2022-11-27 15:07:31 +00:00
|
|
|
const CurrentTab = SettingsTabs[tab]?.component;
|
2022-11-25 22:38:55 +00:00
|
|
|
|
|
|
|
return <Forms.FormSection>
|
|
|
|
<Text variant="heading-md/normal" tag="h2">Vencord Settings</Text>
|
|
|
|
|
|
|
|
<TabBar
|
|
|
|
type={TabBar.Types.TOP}
|
|
|
|
look={TabBar.Looks.BRAND}
|
2023-01-03 01:30:54 +00:00
|
|
|
className={cl("tab-bar")}
|
2022-11-25 22:38:55 +00:00
|
|
|
selectedItem={tab}
|
2023-01-25 02:25:29 +00:00
|
|
|
onItemSelect={SettingsRouter.open}
|
2022-11-25 22:38:55 +00:00
|
|
|
>
|
2022-11-27 15:07:31 +00:00
|
|
|
{Object.entries(SettingsTabs).map(([key, { name, component }]) => {
|
|
|
|
if (!component) return null;
|
2022-11-25 22:38:55 +00:00
|
|
|
return <TabBar.Item
|
|
|
|
id={key}
|
2023-01-03 01:30:54 +00:00
|
|
|
className={cl("tab-bar-item")}
|
2022-11-25 22:38:55 +00:00
|
|
|
key={key}>
|
|
|
|
{name}
|
|
|
|
</TabBar.Item>;
|
|
|
|
})}
|
|
|
|
</TabBar>
|
|
|
|
<Forms.FormDivider />
|
2022-11-27 15:07:31 +00:00
|
|
|
{CurrentTab && <CurrentTab />}
|
2022-11-25 22:38:55 +00:00
|
|
|
</Forms.FormSection >;
|
|
|
|
}
|
|
|
|
|
|
|
|
export default function (props: SettingsProps) {
|
|
|
|
return <ErrorBoundary>
|
|
|
|
<Settings tab={props.tab} />
|
|
|
|
</ErrorBoundary>;
|
|
|
|
}
|