-
Notifications
You must be signed in to change notification settings - Fork 618
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
pompurin404
committed
Aug 3, 2024
1 parent
cd994e2
commit b65e678
Showing
6 changed files
with
137 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/renderer/src/components/connections/connection-item.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { Button, Card, CardBody } from '@nextui-org/react' | ||
import { mihomoCloseConnection } from '@renderer/utils/ipc' | ||
import { IoClose } from 'react-icons/io5' | ||
import React from 'react' | ||
|
||
interface Props extends IMihomoConnectionDetail { | ||
mutate: () => void | ||
} | ||
const ConnectionItem: React.FC<Props> = (props) => { | ||
const { id, metadata, mutate } = props | ||
return ( | ||
<Card className="m-2"> | ||
<CardBody className=""> | ||
<div className="flex justify-between"> | ||
<div className="select-none h-[32px] leading-[32px]"> | ||
{metadata.type}({metadata.network}) | ||
</div> | ||
<div className="select-none h-[32px] leading-[32px]">{metadata.inboundIP}</div> | ||
<div className="select-none h-[32px] leading-[32px]">{'-->'}</div> | ||
<div className="select-none h-[32px] leading-[32px]">{metadata.remoteDestination}</div> | ||
<Button | ||
isIconOnly | ||
size="sm" | ||
color="danger" | ||
variant="light" | ||
onPress={() => { | ||
mihomoCloseConnection(id).then(() => { | ||
mutate() | ||
}) | ||
}} | ||
> | ||
<IoClose className="text-[20px]" /> | ||
</Button> | ||
</div> | ||
</CardBody> | ||
</Card> | ||
) | ||
} | ||
|
||
export default ConnectionItem |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,80 @@ | ||
import ConnectionItem from '@renderer/components/connections/connection-item' | ||
import BasePage from '@renderer/components/base/base-page' | ||
import { mihomoCloseAllConnections, mihomoConnections } from '@renderer/utils/ipc' | ||
import { useMemo, useState } from 'react' | ||
import { Button, Input } from '@nextui-org/react' | ||
import useSWR from 'swr' | ||
import { calcTraffic } from '@renderer/utils/calc' | ||
|
||
const Connections: React.FC = () => { | ||
return <BasePage title="连接"></BasePage> | ||
const { data: connections = { downloadTotal: 0, uploadTotal: 0, connections: [] }, mutate } = | ||
useSWR<IMihomoConnectionsInfo>('mihomoConnections', mihomoConnections, { | ||
refreshInterval: 1000 | ||
}) | ||
const [filter, setFilter] = useState('') | ||
|
||
const filteredConnections = useMemo(() => { | ||
if (filter === '') return connections.connections | ||
return connections.connections?.filter((connection) => { | ||
return connection.metadata.remoteDestination.includes(filter) | ||
}) | ||
}, [connections, filter]) | ||
|
||
return ( | ||
<BasePage | ||
title="连接" | ||
header={ | ||
<div className="flex"> | ||
<div className="flex items-center"> | ||
<span className="mx-1 text-gray-400"> | ||
下载: {calcTraffic(connections.downloadTotal)}{' '} | ||
</span> | ||
<span className="mx-1 text-gray-400"> | ||
上传: {calcTraffic(connections.uploadTotal)}{' '} | ||
</span> | ||
</div> | ||
<Button | ||
className="ml-1" | ||
size="sm" | ||
color="primary" | ||
onPress={() => | ||
mihomoCloseAllConnections().then(() => { | ||
mutate() | ||
}) | ||
} | ||
> | ||
关闭所有连接 | ||
</Button> | ||
</div> | ||
} | ||
> | ||
<div className="sticky top-[48px] z-40 backdrop-blur bg-background/40 flex p-2"> | ||
<Input | ||
variant="bordered" | ||
size="sm" | ||
value={filter} | ||
placeholder="筛选过滤" | ||
onValueChange={setFilter} | ||
/> | ||
</div> | ||
{filteredConnections?.map((connection) => { | ||
return ( | ||
<ConnectionItem | ||
mutate={mutate} | ||
key={connection.id} | ||
id={connection.id} | ||
chains={connection.chains} | ||
download={connection.download} | ||
upload={connection.upload} | ||
metadata={connection.metadata} | ||
rule={connection.rule} | ||
rulePayload={connection.rulePayload} | ||
start={connection.start} | ||
/> | ||
) | ||
})} | ||
</BasePage> | ||
) | ||
} | ||
|
||
export default Connections |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters