feat: support closed connections (#5244)

* feat: support closed connections

* fix: clear closed connections

* feat: show footer

* feat: show closed connection detail

* docs: update Changelog.md

* chore: update
This commit is contained in:
oomeow
2025-11-13 19:50:23 +08:00
committed by GitHub
parent d73036a3b6
commit 1125dc0562
22 changed files with 195 additions and 120 deletions
+25 -16
View File
@@ -8,19 +8,21 @@ import { closeConnections } from "tauri-plugin-mihomo-api";
import parseTraffic from "@/utils/parse-traffic";
export interface ConnectionDetailRef {
open: (detail: IConnectionsItem) => void;
open: (detail: IConnectionsItem, closed: boolean) => void;
}
export function ConnectionDetail({ ref }: { ref?: Ref<ConnectionDetailRef> }) {
const [open, setOpen] = useState(false);
const [detail, setDetail] = useState<IConnectionsItem>(null!);
const [closed, setClosed] = useState(false);
const theme = useTheme();
useImperativeHandle(ref, () => ({
open: (detail: IConnectionsItem) => {
open: (detail: IConnectionsItem, closed: boolean) => {
if (open) return;
setOpen(true);
setDetail(detail);
setClosed(closed);
},
}));
@@ -42,7 +44,11 @@ export function ConnectionDetail({ ref }: { ref?: Ref<ConnectionDetailRef> }) {
}}
message={
detail ? (
<InnerConnectionDetail data={detail} onClose={onClose} />
<InnerConnectionDetail
data={detail}
closed={closed}
onClose={onClose}
/>
) : null
}
/>
@@ -51,10 +57,11 @@ export function ConnectionDetail({ ref }: { ref?: Ref<ConnectionDetailRef> }) {
interface InnerProps {
data: IConnectionsItem;
closed: boolean;
onClose?: () => void;
}
const InnerConnectionDetail = ({ data, onClose }: InnerProps) => {
const InnerConnectionDetail = ({ data, closed, onClose }: InnerProps) => {
const { t } = useTranslation();
const { metadata, rulePayload } = data;
const theme = useTheme();
@@ -134,18 +141,20 @@ const InnerConnectionDetail = ({ data, onClose }: InnerProps) => {
</div>
))}
<Box sx={{ textAlign: "right" }}>
<Button
variant="contained"
title={t("connections.components.actions.closeConnection")}
onClick={() => {
onDelete();
onClose?.();
}}
>
{t("connections.components.actions.closeConnection")}
</Button>
</Box>
{!closed && (
<Box sx={{ textAlign: "right" }}>
<Button
variant="contained"
title={t("connections.components.actions.closeConnection")}
onClick={() => {
onDelete();
onClose?.();
}}
>
{t("connections.components.actions.closeConnection")}
</Button>
</Box>
)}
</Box>
);
};
+13 -10
View File
@@ -27,11 +27,12 @@ const Tag = styled("span")(({ theme }) => ({
interface Props {
value: IConnectionsItem;
closed: boolean;
onShowDetail?: () => void;
}
export const ConnectionItem = (props: Props) => {
const { value, onShowDetail } = props;
const { value, closed, onShowDetail } = props;
const { id, metadata, chains, start, curUpload, curDownload } = value;
const { t } = useTranslation();
@@ -44,15 +45,17 @@ export const ConnectionItem = (props: Props) => {
dense
sx={{ borderBottom: "1px solid var(--divider-color)" }}
secondaryAction={
<IconButton
edge="end"
color="inherit"
onClick={onDelete}
title={t("connections.components.actions.closeConnection")}
aria-label={t("connections.components.actions.closeConnection")}
>
<CloseRounded />
</IconButton>
!closed && (
<IconButton
edge="end"
color="inherit"
onClick={onDelete}
title={t("connections.components.actions.closeConnection")}
aria-label={t("connections.components.actions.closeConnection")}
>
<CloseRounded />
</IconButton>
)
}
>
<ListItemText
@@ -516,7 +516,6 @@ export const ConnectionTable = (props: Props) => {
>
<DataGrid
apiRef={apiRef}
hideFooter
rows={connRows}
columns={columns}
onRowClick={(e) => onShowDetail(e.row.connectionData)}
@@ -187,7 +187,7 @@ export const EnhancedTrafficStats = () => {
uploadTotalUnit,
downloadTotal,
downloadTotalUnit,
connectionsCount: connections?.connections.length,
connectionsCount: connections?.activeConnections.length,
};
}, [traffic, memory, connections]);