From 8c26116ffaacac0690796de25661ff52f756078a Mon Sep 17 00:00:00 2001 From: thororen1234 <78185467+thororen1234@users.noreply.github.com> Date: Thu, 25 Jul 2024 07:16:18 -0400 Subject: [PATCH] Change to a different CustomAppIcons --- .../customAppIcons/AppIconModal.tsx | 104 ------------- src/equicordplugins/customAppIcons/index.tsx | 147 +++++++++--------- src/utils/constants.ts | 4 + 3 files changed, 74 insertions(+), 181 deletions(-) delete mode 100644 src/equicordplugins/customAppIcons/AppIconModal.tsx diff --git a/src/equicordplugins/customAppIcons/AppIconModal.tsx b/src/equicordplugins/customAppIcons/AppIconModal.tsx deleted file mode 100644 index c8883a96..00000000 --- a/src/equicordplugins/customAppIcons/AppIconModal.tsx +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Vencord, a Discord client mod - * Copyright (c) 2024 Vendicated and contributors - * SPDX-License-Identifier: GPL-3.0-or-later - */ - -import { localStorage } from "@utils/localStorage"; -import { ModalCloseButton, ModalContent, ModalFooter, ModalHeader, ModalProps, ModalRoot, ModalSize } from "@utils/modal"; -import { findByProps } from "@webpack"; -import { Button, FluxDispatcher, Forms, React, showToast, Text, TextInput, Toasts, useState } from "@webpack/common"; - - -interface AppIcon { - id: string, - iconSource: string, - name: string, - isPremium: boolean; -} -function AppIconModal(props: ModalProps) { - const [name, setName] = useState(""); - const [imageUrl, setimageUrl] = useState(""); - - function addAppIcon(name, url) { - const appIcons = JSON.parse(localStorage.getItem("vc_app_icons") ?? "[]"); - const id = `${name.replaceAll(" ", "")}_${Date.now()}`; // avoid crashing if repeated name - const icon = { - "id": id, - "iconSource": url, - "isPremium": false, - "name": name - } as AppIcon; - - - appIcons.push(icon); - findByProps("M9", "UZ", "QA").UZ.push(icon); - findByProps("M9", "UZ", "QA").QA[icon.id] = icon; - showToast("Added custom app icon!", Toasts.Type.SUCCESS); - props.onClose(); - const oldIcon = findByProps("getCurrentDesktopIcon").getCurrentDesktopIcon(); - - let random_icon = Object.keys(findByProps("UZ")).filter(icon => icon !== oldIcon) as []; - random_icon = random_icon[Math.floor(Math.random() * random_icon.length)]; - - FluxDispatcher.dispatch({ - type: "APP_ICON_UPDATED", - id: random_icon - }); - FluxDispatcher.dispatch({ - type: "APP_ICON_UPDATED", - id: oldIcon - }); - localStorage.setItem("vc_app_icons", JSON.stringify(appIcons)); - } - - return - - Add a custom app icon: - - - -
- - - This name will be shown in the App Icons list. - - - -
- - - Paste here your image URL to upload your icon (.webp, .jpg, .jpeg, .png, .gif, .ico and Discord Icons, Emojis, PFPs, etc.). - - - -
- - - - -
; -} - -export default AppIconModal; diff --git a/src/equicordplugins/customAppIcons/index.tsx b/src/equicordplugins/customAppIcons/index.tsx index 7fc75f9a..0339c688 100644 --- a/src/equicordplugins/customAppIcons/index.tsx +++ b/src/equicordplugins/customAppIcons/index.tsx @@ -4,95 +4,88 @@ * SPDX-License-Identifier: GPL-3.0-or-later */ -import { Link } from "@components/Link"; +import { definePluginSettings } from "@api/Settings"; +import { CodeBlock } from "@components/CodeBlock"; import { Devs, EquicordDevs } from "@utils/constants"; -import { localStorage } from "@utils/localStorage"; -import { closeAllModals, openModal } from "@utils/modal"; -import definePlugin from "@utils/types"; -import { findByProps } from "@webpack"; -import { Button, FluxDispatcher, Forms, React, showToast, Toasts } from "@webpack/common"; +import definePlugin, { OptionType, PluginSettingComponentDef } from "@utils/types"; +import { Forms, React, TextArea } from "@webpack/common"; -import AppIconModal from "./AppIconModal"; +type Icon = { + id: string, + iconSource: string, + isPremium: boolean, + name: string, +}; -function removeAppIcon() { - const current_icon = findByProps("getCurrentDesktopIcon").getCurrentDesktopIcon(); - let icons = JSON.parse(localStorage.getItem("vc_app_icons") || "[]"); - const index = icons.findIndex(icon => current_icon === icon.id); - if (index !== -1) { - icons = icons.filter(e => e.id !== current_icon); - delete findByProps("M9", "UZ", "QA").QA[current_icon]; - delete findByProps("M9", "UZ", "QA").UZ[findByProps("M9", "UZ", "QA").UZ.findIndex((icon => current_icon === icon?.id))]; - localStorage.setItem("vc_app_icons", JSON.stringify(icons)); - showToast("Icon successfully deleted!", Toasts.Type.SUCCESS); - FluxDispatcher.dispatch({ - type: "APP_ICON_UPDATED", - id: "AppIcon" - }); - } else { - showToast("Cannot delete native App Icons!", Toasts.Type.FAILURE); - return; +const settings = definePluginSettings({ + icons: { + description: "Icons to add", + type: OptionType.COMPONENT, + restartNeeded: true, + component: iconSettingsComponent + } +}); + +function iconSettingsComponent(props: Parameters[0]) { + const [state, setState] = React.useState(settings.store.icons ?? ""); + + function handleChange(newValue: string) { + setState(newValue); + props.setValue(newValue); } + return + Icons + The icons you want to add. + +