import { alpha, Box, ListItemText, ListItemButton, Typography, styled, } from "@mui/material"; import { ExpandLessRounded, ExpandMoreRounded, InboxRounded, } from "@mui/icons-material"; import { HeadState } from "./use-head-state"; import { ProxyHead } from "./proxy-head"; import { ProxyItem } from "./proxy-item"; import { ProxyItemMini } from "./proxy-item-mini"; import type { IRenderItem } from "./use-render-list"; import { useVerge } from "@/hooks/use-verge"; import { useThemeMode } from "@/services/states"; import { useEffect, useMemo, useState } from "react"; import { convertFileSrc } from "@tauri-apps/api/core"; import { downloadIconCache } from "@/services/cmds"; interface RenderProps { item: IRenderItem; indent: boolean; onLocation: (group: IProxyGroupItem) => void; onCheckAll: (groupName: string) => void; onHeadState: (groupName: string, patch: Partial) => void; onChangeProxy: (group: IProxyGroupItem, proxy: IProxyItem) => void; } export const ProxyRender = (props: RenderProps) => { const { indent, item, onLocation, onCheckAll, onHeadState, onChangeProxy } = props; const { type, group, headState, proxy, proxyCol } = item; const { verge } = useVerge(); const enable_group_icon = verge?.enable_group_icon ?? true; const mode = useThemeMode(); const isDark = mode === "light" ? false : true; const itembackgroundcolor = isDark ? "#282A36" : "#ffffff"; 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); } if (type === 0) { return ( onHeadState(group.name, { open: !headState?.open })} > {enable_group_icon && group.icon && group.icon.trim().startsWith("http") && ( )} {enable_group_icon && group.icon && group.icon.trim().startsWith("data") && ( )} {enable_group_icon && group.icon && group.icon.trim().startsWith(" )} {group.name}} secondary={ {group.type} {group.now} } slotProps={{ secondary: { component: "div", sx: { display: "flex", alignItems: "center", color: "#ccc" }, }, }} /> {headState?.open ? : } ); } if (type === 1) { return ( onLocation(group)} onCheckDelay={() => onCheckAll(group.name)} onHeadState={(p) => onHeadState(group.name, p)} /> ); } if (type === 2) { return ( onChangeProxy(group, proxy!)} /> ); } if (type === 3) { return ( No Proxies ); } if (type === 4) { const proxyColItemsMemo = useMemo(() => { return proxyCol?.map((proxy) => ( onChangeProxy(group, proxy!)} /> )); }, [proxyCol, group, headState]); return ( {proxyColItemsMemo} ); } return null; }; const StyledPrimary = styled("span")` font-size: 16px; font-weight: 700; line-height: 1.5; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; `; const StyledSubtitle = styled("span")` font-size: 13px; overflow: hidden; color: text.secondary; text-overflow: ellipsis; white-space: nowrap; `; const StyledTypeBox = styled(Box)(({ theme }) => ({ display: "inline-block", border: "1px solid #ccc", borderColor: alpha(theme.palette.primary.main, 0.5), color: alpha(theme.palette.primary.main, 0.8), borderRadius: 4, fontSize: 10, padding: "0 4px", lineHeight: 1.5, marginRight: "8px", }));