/* * Vencord, a Discord client mod * Copyright (c) 2024 Vendicated and contributors * SPDX-License-Identifier: GPL-3.0-or-later */ import { CodeBlock } from "@components/CodeBlock"; import { Heading } from "@components/Heading"; import { Heart } from "@components/Heart"; import { Paragraph } from "@components/Paragraph"; import { Theme, ThemeInfoModalProps } from "@equicordplugins/themeLibrary/types"; import { ClockIcon, WarningIcon } from "@equicordplugins/themeLibrary/utils/Icons"; import { copyToClipboard } from "@utils/clipboard"; import { openInviteModal } from "@utils/discord"; import { Margins } from "@utils/margins"; import type { PluginNative } from "@utils/types"; import { findComponentByCodeLazy } from "@webpack"; import { Button, Modal, openModal, Parser, React, showToast, Toasts } from "@webpack/common"; import { logger } from "./ThemeTab"; const Native = VencordNative.pluginHelpers.ThemeLibrary as PluginNative; const UserSummaryItem = findComponentByCodeLazy("defaultRenderUser", "showDefaultAvatarsForNullUsers"); async function downloadTheme(themesDir: string, theme: Theme) { try { await Native.downloadTheme(themesDir, theme); showToast(`Downloaded ${theme.name}!`, Toasts.Type.SUCCESS); } catch (err: unknown) { logger.error(err); showToast(`Failed to download ${theme.name}! (check console)`, Toasts.Type.FAILURE); } } export const ThemeInfoModal: React.FC = ({ author, theme, ...props }) => { const { type, content, likes, guild, tags, last_updated, requiresThemeAttributes } = theme; const themeContent = window.atob(content); const metadata = themeContent.match(/\/\*\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+\//g)?.[0] || ""; const donate = metadata.match(/@donate\s+(.+)/)?.[1] || ""; const version = metadata.match(/@version\s+(.+)/)?.[1] || ""; const invite = metadata.match(/@invite\s+(.+)/)?.[1] || ""; const authors = Array.isArray(author) ? author : [author]; const lastUpdated = Math.floor(new Date(last_updated ?? 0).getTime() / 1000); return ( props.onClose() }, { text: "Download", variant: "positive", disabled: !theme.content || theme.id === "preview", onClick: async () => { const themesDir = await VencordNative.themes.getThemesDir(); const exists = await Native.themeExists(themesDir, theme); const validThemesDir = await Native.getThemesDir(themesDir, theme); if (exists) { openModal(modalProps => ( { await downloadTheme(themesDir, theme); modalProps.onClose(); } }, { text: "Keep my file", variant: "positive", onClick: () => modalProps.onClose() } ]} >

A theme with the same name already exists in your themes directory! Do you want to overwrite it?

{validThemesDir}
)); } else { await downloadTheme(themesDir, theme); } } } ]} > {authors.length > 1 ? "Authors" : "Author"}
{authors.map(author => author.username).join(", ")}
{version && ( <> Version {version} )} Likes {likes === 0 ? `Nobody liked this ${type} yet.` : `${likes} users liked this ${type}!`} {donate && ( <> Donate You can support the author by donating below! )} {(guild || invite) && ( <> Support Server {guild && ( {guild.name} )} )} Source {tags && ( <> Tags {tags.map(tag => ( {tag} ))} )} {requiresThemeAttributes && ( This theme requires the ThemeAttributes plugin! )} {last_updated && ( This theme was last updated {Parser.parse("")} ({Parser.parse("")}) )}
); };