diff --git a/src/components/profile/group-item.tsx b/src/components/profile/group-item.tsx index bff1f0e9..7bf18cf5 100644 --- a/src/components/profile/group-item.tsx +++ b/src/components/profile/group-item.tsx @@ -9,6 +9,9 @@ import { import { DeleteForeverRounded, UndoRounded } from "@mui/icons-material"; import { useSortable } from "@dnd-kit/sortable"; import { CSS } from "@dnd-kit/utilities"; +import { downloadIconCache } from "@/services/cmds"; +import { convertFileSrc } from "@tauri-apps/api/tauri"; +import { useEffect, useState } from "react"; interface Props { type: "prepend" | "original" | "delete" | "append"; group: IProxyGroupConfig; @@ -28,6 +31,26 @@ export const GroupItem = (props: Props) => { transform: null, transition: null, }; + + const [iconCachePath, setIconCachePath] = useState(""); + + useEffect(() => { + initIconCachePath(); + }, [group]); + + async function initIconCachePath() { + if (group.icon && group.icon.trim().startsWith("http")) { + const fileName = + group.name.replaceAll(" ", "") + "-" + getFileName(group.icon); + const iconPath = await downloadIconCache(group.icon, fileName); + setIconCachePath(convertFileSrc(iconPath)); + } + } + + function getFileName(url: string) { + return url.substring(url.lastIndexOf("/") + 1); + } + return ( { > {group.icon && group.icon?.trim().startsWith("http") && (