Add basic themes tab
This commit is contained in:
parent
fc09460d82
commit
f94cbfb2f4
|
@ -29,6 +29,7 @@ export interface Settings {
|
||||||
notifyAboutUpdates: boolean;
|
notifyAboutUpdates: boolean;
|
||||||
useQuickCss: boolean;
|
useQuickCss: boolean;
|
||||||
enableReactDevtools: boolean;
|
enableReactDevtools: boolean;
|
||||||
|
themeLinks: string[];
|
||||||
plugins: {
|
plugins: {
|
||||||
[plugin: string]: {
|
[plugin: string]: {
|
||||||
enabled: boolean;
|
enabled: boolean;
|
||||||
|
@ -40,6 +41,7 @@ export interface Settings {
|
||||||
const DefaultSettings: Settings = {
|
const DefaultSettings: Settings = {
|
||||||
notifyAboutUpdates: true,
|
notifyAboutUpdates: true,
|
||||||
useQuickCss: true,
|
useQuickCss: true,
|
||||||
|
themeLinks: [],
|
||||||
enableReactDevtools: false,
|
enableReactDevtools: false,
|
||||||
plugins: {}
|
plugins: {}
|
||||||
};
|
};
|
||||||
|
|
135
src/components/VencordSettings/ThemesTab.tsx
Normal file
135
src/components/VencordSettings/ThemesTab.tsx
Normal file
|
@ -0,0 +1,135 @@
|
||||||
|
/*
|
||||||
|
* 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 { useSettings } from "@api/settings";
|
||||||
|
import ErrorBoundary from "@components/ErrorBoundary";
|
||||||
|
import { Link } from "@components/Link";
|
||||||
|
import { useAwaiter } from "@utils/misc";
|
||||||
|
import { findLazy } from "@webpack";
|
||||||
|
import { Card, Forms, Margins, React, TextArea } from "@webpack/common";
|
||||||
|
|
||||||
|
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 (
|
||||||
|
<>
|
||||||
|
<Forms.FormTitle className={Margins.marginTop20} tag="h5">Validator</Forms.FormTitle>
|
||||||
|
<Forms.FormText>This section will tell you whether your themes can successfully be loaded</Forms.FormText>
|
||||||
|
<div>
|
||||||
|
{themeLinks.map(link => (
|
||||||
|
<Card style={{
|
||||||
|
padding: ".5em",
|
||||||
|
marginBottom: ".5em"
|
||||||
|
}} key={link}>
|
||||||
|
<Forms.FormTitle tag="h5" style={{
|
||||||
|
overflowWrap: "break-word"
|
||||||
|
}}>
|
||||||
|
{link}
|
||||||
|
</Forms.FormTitle>
|
||||||
|
<Validator link={link} />
|
||||||
|
</Card>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ErrorBoundary.wrap(function () {
|
||||||
|
const settings = useSettings();
|
||||||
|
const ref = React.useRef<HTMLTextAreaElement>();
|
||||||
|
|
||||||
|
function onBlur() {
|
||||||
|
settings.themeLinks = [...new Set(
|
||||||
|
ref.current!.value
|
||||||
|
.trim()
|
||||||
|
.split(/\n+/)
|
||||||
|
.map(s => s.trim())
|
||||||
|
.filter(Boolean)
|
||||||
|
)];
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Card style={{
|
||||||
|
padding: "1em",
|
||||||
|
marginBottom: "1em",
|
||||||
|
marginTop: "1em"
|
||||||
|
}}>
|
||||||
|
<Forms.FormTitle tag="h5">Paste links to .css / .theme.css files here</Forms.FormTitle>
|
||||||
|
<Forms.FormText>One link per line</Forms.FormText>
|
||||||
|
<Forms.FormText>Be careful to use the raw links or github.io links!</Forms.FormText>
|
||||||
|
<Forms.FormDivider />
|
||||||
|
<Forms.FormTitle tag="h5">Find Themes:</Forms.FormTitle>
|
||||||
|
<div>
|
||||||
|
<Link style={{ marginRight: ".5em" }} href="https://betterdiscord.app/themes">
|
||||||
|
BetterDiscord Themes
|
||||||
|
</Link>
|
||||||
|
<Link href="https://github.com/search?q=discord+theme">Github</Link>
|
||||||
|
</div>
|
||||||
|
<Forms.FormText>If using the BD site, click on "Source" somewhere below the Download button</Forms.FormText>
|
||||||
|
<Forms.FormText>In the GitHub repository of your theme, find X.theme.css / X.css, click on it, then click the "Raw" button</Forms.FormText>
|
||||||
|
<Forms.FormText>
|
||||||
|
If the theme has configuration that requires you to edit the file:
|
||||||
|
<ul>
|
||||||
|
<li>• Make a github account</li>
|
||||||
|
<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
|
||||||
|
style={{
|
||||||
|
padding: ".5em",
|
||||||
|
border: "1px solid var(--background-modifier-accent)"
|
||||||
|
}}
|
||||||
|
ref={ref}
|
||||||
|
defaultValue={settings.themeLinks.join("\n")}
|
||||||
|
className={TextAreaProps.textarea}
|
||||||
|
placeholder="Theme Links"
|
||||||
|
spellCheck={false}
|
||||||
|
onBlur={onBlur}
|
||||||
|
/>
|
||||||
|
<Validators themeLinks={settings.themeLinks} />
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
});
|
|
@ -24,6 +24,7 @@ import cssText from "~fileContent/settingsStyles.css";
|
||||||
|
|
||||||
import BackupRestoreTab from "./BackupRestoreTab";
|
import BackupRestoreTab from "./BackupRestoreTab";
|
||||||
import PluginsTab from "./PluginsTab";
|
import PluginsTab from "./PluginsTab";
|
||||||
|
import ThemesTab from "./ThemesTab";
|
||||||
import Updater from "./Updater";
|
import Updater from "./Updater";
|
||||||
import VencordSettings from "./VencordTab";
|
import VencordSettings from "./VencordTab";
|
||||||
|
|
||||||
|
@ -47,7 +48,7 @@ interface SettingsTab {
|
||||||
const SettingsTabs: Record<string, SettingsTab> = {
|
const SettingsTabs: Record<string, SettingsTab> = {
|
||||||
VencordSettings: { name: "Vencord", component: () => <VencordSettings /> },
|
VencordSettings: { name: "Vencord", component: () => <VencordSettings /> },
|
||||||
VencordPlugins: { name: "Plugins", component: () => <PluginsTab /> },
|
VencordPlugins: { name: "Plugins", component: () => <PluginsTab /> },
|
||||||
VencordThemes: { name: "Themes", component: () => <Text variant="text-md/medium">Coming soon to a Vencord near you!</Text> },
|
VencordThemes: { name: "Themes", component: () => <ThemesTab /> },
|
||||||
VencordUpdater: { name: "Updater" }, // Only show updater if IS_WEB is false
|
VencordUpdater: { name: "Updater" }, // Only show updater if IS_WEB is false
|
||||||
VencordSettingsSync: { name: "Backup & Restore", component: () => <BackupRestoreTab /> },
|
VencordSettingsSync: { name: "Backup & Restore", component: () => <BackupRestoreTab /> },
|
||||||
};
|
};
|
||||||
|
|
|
@ -21,6 +21,7 @@ import { addSettingsListener, Settings } from "@api/settings";
|
||||||
import IpcEvents from "./IpcEvents";
|
import IpcEvents from "./IpcEvents";
|
||||||
|
|
||||||
let style: HTMLStyleElement;
|
let style: HTMLStyleElement;
|
||||||
|
let themesStyle: HTMLStyleElement;
|
||||||
|
|
||||||
export async function toggle(isEnabled: boolean) {
|
export async function toggle(isEnabled: boolean) {
|
||||||
if (!style) {
|
if (!style) {
|
||||||
|
@ -35,7 +36,22 @@ export async function toggle(isEnabled: boolean) {
|
||||||
style.disabled = !isEnabled;
|
style.disabled = !isEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function initThemes() {
|
||||||
|
if (!themesStyle) {
|
||||||
|
themesStyle = document.createElement("style");
|
||||||
|
themesStyle.id = "vencord-themes";
|
||||||
|
document.head.appendChild(themesStyle);
|
||||||
|
}
|
||||||
|
|
||||||
|
const { themeLinks } = Settings;
|
||||||
|
const links = themeLinks.map(link => `@import url("${link.trim()}");`).join("\n");
|
||||||
|
themesStyle.textContent = links;
|
||||||
|
}
|
||||||
|
|
||||||
document.addEventListener("DOMContentLoaded", () => {
|
document.addEventListener("DOMContentLoaded", () => {
|
||||||
toggle(Settings.useQuickCss);
|
toggle(Settings.useQuickCss);
|
||||||
addSettingsListener("useQuickCss", toggle);
|
addSettingsListener("useQuickCss", toggle);
|
||||||
|
|
||||||
|
initThemes();
|
||||||
|
addSettingsListener("themeLinks", initThemes);
|
||||||
});
|
});
|
||||||
|
|
|
@ -65,6 +65,7 @@ export let Tooltip: Components.Tooltip;
|
||||||
export let Router: any;
|
export let Router: any;
|
||||||
export let TextInput: any;
|
export let TextInput: any;
|
||||||
export let Text: (props: TextProps) => JSX.Element;
|
export let Text: (props: TextProps) => JSX.Element;
|
||||||
|
export const TextArea = findByCodeLazy("handleSetRef", "textArea") as React.ComponentType<React.PropsWithRef<any>>;
|
||||||
|
|
||||||
export const Select = LazyComponent(() => findByCode("optionClassName", "popoutPosition", "autoFocus", "maxVisibleItems"));
|
export const Select = LazyComponent(() => findByCode("optionClassName", "popoutPosition", "autoFocus", "maxVisibleItems"));
|
||||||
export const Slider = LazyComponent(() => findByCode("closestMarkerIndex", "stickToMarkers"));
|
export const Slider = LazyComponent(() => findByCode("closestMarkerIndex", "stickToMarkers"));
|
||||||
|
|
Loading…
Reference in a new issue