2022-12-01 02:01:44 +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/>.
|
|
|
|
*/
|
|
|
|
|
2023-05-05 23:36:00 +00:00
|
|
|
import { useSettings } from "@api/Settings";
|
2022-12-01 02:01:44 +00:00
|
|
|
import { Link } from "@components/Link";
|
2023-03-01 20:35:08 +00:00
|
|
|
import { Margins } from "@utils/margins";
|
2023-05-05 23:36:00 +00:00
|
|
|
import { useAwaiter } from "@utils/react";
|
2022-12-01 02:01:44 +00:00
|
|
|
import { findLazy } from "@webpack";
|
2023-03-01 20:35:08 +00:00
|
|
|
import { Card, Forms, React, TextArea } from "@webpack/common";
|
2022-12-01 02:01:44 +00:00
|
|
|
|
2023-05-11 23:40:43 +00:00
|
|
|
import { SettingsTab, wrapTab } from "./shared";
|
|
|
|
|
2022-12-01 02:01:44 +00:00
|
|
|
const TextAreaProps = findLazy(m => typeof m.textarea === "string");
|
|
|
|
|
|
|
|
function Validator({ link }: { link: string; }) {
|
|
|
|
const [res, err, pending] = useAwaiter(() => fetch(link).then(res => {
|
|
|
|
if (res.status > 300) throw `${res.status} ${res.statusText}`;
|
|
|
|
const contentType = res.headers.get("Content-Type");
|
|
|
|
if (!contentType?.startsWith("text/css") && !contentType?.startsWith("text/plain"))
|
|
|
|
throw "Not a CSS file. Remember to use the raw link!";
|
|
|
|
|
|
|
|
return "Okay!";
|
|
|
|
}));
|
|
|
|
|
|
|
|
const text = pending
|
|
|
|
? "Checking..."
|
|
|
|
: err
|
|
|
|
? `Error: ${err instanceof Error ? err.message : String(err)}`
|
|
|
|
: "Valid!";
|
|
|
|
|
|
|
|
return <Forms.FormText style={{
|
|
|
|
color: pending ? "var(--text-muted)" : err ? "var(--text-danger)" : "var(--text-positive)"
|
|
|
|
}}>{text}</Forms.FormText>;
|
|
|
|
}
|
|
|
|
|
|
|
|
function Validators({ themeLinks }: { themeLinks: string[]; }) {
|
|
|
|
if (!themeLinks.length) return null;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2023-03-01 20:35:08 +00:00
|
|
|
<Forms.FormTitle className={Margins.top20} tag="h5">Validator</Forms.FormTitle>
|
2022-12-01 02:01:44 +00:00
|
|
|
<Forms.FormText>This section will tell you whether your themes can successfully be loaded</Forms.FormText>
|
|
|
|
<div>
|
|
|
|
{themeLinks.map(link => (
|
|
|
|
<Card style={{
|
|
|
|
padding: ".5em",
|
2022-12-08 22:51:18 +00:00
|
|
|
marginBottom: ".5em",
|
|
|
|
marginTop: ".5em"
|
2022-12-01 02:01:44 +00:00
|
|
|
}} key={link}>
|
|
|
|
<Forms.FormTitle tag="h5" style={{
|
|
|
|
overflowWrap: "break-word"
|
|
|
|
}}>
|
|
|
|
{link}
|
|
|
|
</Forms.FormTitle>
|
|
|
|
<Validator link={link} />
|
|
|
|
</Card>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-05-11 23:40:43 +00:00
|
|
|
function ThemesTab() {
|
|
|
|
const settings = useSettings(["themeLinks"]);
|
2023-01-25 16:49:19 +00:00
|
|
|
const [themeText, setThemeText] = React.useState(settings.themeLinks.join("\n"));
|
2022-12-01 02:01:44 +00:00
|
|
|
|
|
|
|
function onBlur() {
|
|
|
|
settings.themeLinks = [...new Set(
|
2023-01-25 16:49:19 +00:00
|
|
|
themeText
|
2022-12-01 02:01:44 +00:00
|
|
|
.trim()
|
|
|
|
.split(/\n+/)
|
|
|
|
.map(s => s.trim())
|
|
|
|
.filter(Boolean)
|
|
|
|
)];
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2023-05-11 23:40:43 +00:00
|
|
|
<SettingsTab title="Themes">
|
2023-04-08 21:28:12 +00:00
|
|
|
<Card className="vc-settings-card vc-text-selectable">
|
2023-04-16 22:23:22 +00:00
|
|
|
<Forms.FormTitle tag="h5">Paste links to .theme.css files here</Forms.FormTitle>
|
2022-12-01 02:01:44 +00:00
|
|
|
<Forms.FormText>One link per line</Forms.FormText>
|
2023-05-05 00:47:18 +00:00
|
|
|
<Forms.FormText><strong>Make sure to use the raw links or github.io links!</strong></Forms.FormText>
|
2023-03-01 20:35:08 +00:00
|
|
|
<Forms.FormDivider className={Margins.top8 + " " + Margins.bottom8} />
|
2022-12-01 02:01:44 +00:00
|
|
|
<Forms.FormTitle tag="h5">Find Themes:</Forms.FormTitle>
|
2022-12-08 22:51:18 +00:00
|
|
|
<div style={{ marginBottom: ".5em" }}>
|
2022-12-01 02:01:44 +00:00
|
|
|
<Link style={{ marginRight: ".5em" }} href="https://betterdiscord.app/themes">
|
|
|
|
BetterDiscord Themes
|
|
|
|
</Link>
|
2022-12-08 22:51:18 +00:00
|
|
|
<Link href="https://github.com/search?q=discord+theme">GitHub</Link>
|
2022-12-01 02:01:44 +00:00
|
|
|
</div>
|
|
|
|
<Forms.FormText>If using the BD site, click on "Source" somewhere below the Download button</Forms.FormText>
|
2023-04-16 22:23:22 +00:00
|
|
|
<Forms.FormText>In the GitHub repository of your theme, find X.theme.css, click on it, then click the "Raw" button</Forms.FormText>
|
2022-12-01 02:01:44 +00:00
|
|
|
<Forms.FormText>
|
|
|
|
If the theme has configuration that requires you to edit the file:
|
|
|
|
<ul>
|
2022-12-08 22:51:18 +00:00
|
|
|
<li>• Make a <Link href="https://github.com/signup">GitHub</Link> account</li>
|
2022-12-01 02:01:44 +00:00
|
|
|
<li>• Click the fork button on the top right</li>
|
|
|
|
<li>• Edit the file</li>
|
|
|
|
<li>• Use the link to your own repository instead</li>
|
|
|
|
</ul>
|
|
|
|
</Forms.FormText>
|
|
|
|
</Card>
|
|
|
|
<Forms.FormTitle tag="h5">Themes</Forms.FormTitle>
|
|
|
|
<TextArea
|
2023-01-25 16:49:19 +00:00
|
|
|
value={themeText}
|
2023-04-04 20:24:16 +00:00
|
|
|
onChange={setThemeText}
|
2023-03-28 16:20:06 +00:00
|
|
|
className={`${TextAreaProps.textarea} vc-settings-theme-links`}
|
2022-12-01 02:01:44 +00:00
|
|
|
placeholder="Theme Links"
|
|
|
|
spellCheck={false}
|
|
|
|
onBlur={onBlur}
|
|
|
|
/>
|
|
|
|
<Validators themeLinks={settings.themeLinks} />
|
2023-05-11 23:40:43 +00:00
|
|
|
</SettingsTab>
|
2022-12-01 02:01:44 +00:00
|
|
|
);
|
2023-05-11 23:40:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default wrapTab(ThemesTab, "Themes");
|