mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2024-11-16 11:42:21 +08:00
feat: support cache for groups editor
This commit is contained in:
parent
f5ee4fb5b5
commit
60d0b29236
|
@ -9,6 +9,9 @@ import {
|
||||||
import { DeleteForeverRounded, UndoRounded } from "@mui/icons-material";
|
import { DeleteForeverRounded, UndoRounded } from "@mui/icons-material";
|
||||||
import { useSortable } from "@dnd-kit/sortable";
|
import { useSortable } from "@dnd-kit/sortable";
|
||||||
import { CSS } from "@dnd-kit/utilities";
|
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 {
|
interface Props {
|
||||||
type: "prepend" | "original" | "delete" | "append";
|
type: "prepend" | "original" | "delete" | "append";
|
||||||
group: IProxyGroupConfig;
|
group: IProxyGroupConfig;
|
||||||
|
@ -28,6 +31,26 @@ export const GroupItem = (props: Props) => {
|
||||||
transform: null,
|
transform: null,
|
||||||
transition: 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 (
|
return (
|
||||||
<ListItem
|
<ListItem
|
||||||
dense
|
dense
|
||||||
|
@ -49,7 +72,7 @@ export const GroupItem = (props: Props) => {
|
||||||
>
|
>
|
||||||
{group.icon && group.icon?.trim().startsWith("http") && (
|
{group.icon && group.icon?.trim().startsWith("http") && (
|
||||||
<img
|
<img
|
||||||
src={group.icon}
|
src={iconCachePath === "" ? group.icon : iconCachePath}
|
||||||
width="32px"
|
width="32px"
|
||||||
style={{
|
style={{
|
||||||
marginRight: "12px",
|
marginRight: "12px",
|
||||||
|
|
Loading…
Reference in New Issue
Block a user