import { ContentCopyRounded } from "@mui/icons-material";
import { alpha, Box, Button, IconButton } from "@mui/material";
import { writeText } from "@tauri-apps/plugin-clipboard-manager";
import { useImperativeHandle, useState } from "react";
import { useTranslation } from "react-i18next";
import useSWR from "swr";
import { BaseDialog } from "@/components/base";
import { getNetworkInterfacesInfo } from "@/services/cmds";
import { showNotice } from "@/services/noticeService";
export const NetworkInterfaceViewer = ({ ref, ...props }) => {
const { t } = useTranslation();
const [open, setOpen] = useState(false);
const [isV4, setIsV4] = useState(true);
useImperativeHandle(ref, () => ({
open: () => {
setOpen(true);
},
close: () => setOpen(false),
}));
const { data: networkInterfaces } = useSWR(
"clash-verge-rev-internal://network-interfaces",
getNetworkInterfacesInfo,
{
fallbackData: [], // default data before fetch
},
);
return (
{t("Network Interface")}
}
contentSx={{ width: 450 }}
disableOk
cancelBtn={t("Close")}
onClose={() => setOpen(false)}
onCancel={() => setOpen(false)}
>
{networkInterfaces.map((item) => (
{item.name}
{isV4 && (
<>
{item.addr.map(
(address) =>
address.V4 && (
),
)}
>
)}
{!isV4 && (
<>
{item.addr.map(
(address) =>
address.V6 && (
),
)}
>
)}
))}
);
};
const AddressDisplay = (props: { label: string; content: string }) => {
const { t } = useTranslation();
return (
{props.label}
({
borderRadius: "8px",
padding: "2px 2px 2px 8px",
background:
palette.mode === "dark"
? alpha(palette.background.paper, 0.3)
: alpha(palette.grey[400], 0.3),
})}
>
{props.content}
{
await writeText(props.content);
showNotice("success", t("Copy Success"));
}}
>
);
};