/* * 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 { Heart } from "@components/Heart"; import { copyToClipboard } from "@utils/clipboard"; import { openInviteModal } from "@utils/discord"; import { Margins } from "@utils/margins"; import { classes } from "@utils/misc"; import { ModalContent, ModalFooter, ModalHeader, ModalRoot, ModalSize, openModal } from "@utils/modal"; import type { PluginNative } from "@utils/types"; import { findComponentByCodeLazy } from "@webpack"; import { Button, Forms, Parser, React, showToast, Toasts } from "@webpack/common"; import { Theme, ThemeInfoModalProps } from "../types"; import { ClockIcon, DownloadIcon, WarningIcon } from "../utils/Icons"; 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 ( {type} Details {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 ))} > View Theme 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("")}) )}
)); } else { await downloadTheme(themesDir, theme); } }} >
Download
); };