Skip to content
This repository has been archived by the owner on Feb 5, 2025. It is now read-only.

Commit

Permalink
Add more connection details
Browse files Browse the repository at this point in the history
  • Loading branch information
xishang0128 committed Nov 20, 2024
1 parent e265317 commit c338051
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 20 deletions.
59 changes: 39 additions & 20 deletions src/renderer/src/components/connections/connection-detail-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface Props {

const CopyableSettingItem: React.FC<{
title: string
value: string
value: string | string[]
displayName?: string
prefix?: string[]
suffix?: string
Expand All @@ -23,18 +23,23 @@ const CopyableSettingItem: React.FC<{
: domain.split('.').map((_, i, parts) => parts.slice(i).join('.')).slice(0, -1)

const menuItems = [
{ key: 'raw', text: value },
...prefix.flatMap(p =>
(p === 'DOMAIN-SUFFIX'
? getSubDomains(value)
: p === 'IP-ASN'
? [value.split(' ')[0]]
: [value]
).map(v => ({
key: `${p},${v}${suffix}`,
text: `${p},${v}${suffix}`
}))
)
{ key: 'raw', text: displayName || (Array.isArray(value) ? value.join(', ') : value) },
...(Array.isArray(value) && value.length === prefix.length
? prefix.map((p, i) => value[i] ? ({
key: `${p},${value[i]}${suffix}`,
text: `${p},${value[i]}${suffix}`
}) : null).filter(Boolean)
: prefix.flatMap(p =>
(p === 'DOMAIN-SUFFIX'
? getSubDomains(Array.isArray(value) ? value[0] : value)
: p === 'IP-ASN'
? [(Array.isArray(value) ? value[0] : value).split(' ')[0]]
: [Array.isArray(value) ? value[0] : value]
).map(v => ({
key: `${p},${v}${suffix}`,
text: `${p},${v}${suffix}`
}))
))
]

return (
Expand All @@ -49,17 +54,17 @@ const CopyableSettingItem: React.FC<{
</DropdownTrigger>
<DropdownMenu
onAction={key =>
navigator.clipboard.writeText(key === 'raw' ? value : key as string)
navigator.clipboard.writeText(key === 'raw' ? (Array.isArray(value) ? value.join(', ') : value) : key as string)
}
>
{menuItems.map(({ key, text }) => (
{menuItems.filter(item => item !== null).map(({ key, text }) => (
<DropdownItem key={key}>{text}</DropdownItem>
))}
</DropdownMenu>
</Dropdown>
}
>
{displayName || value}
{displayName || (Array.isArray(value) ? value.join(', ') : value)}
</SettingItem>
)
}
Expand Down Expand Up @@ -91,9 +96,9 @@ const ConnectionDetailModal: React.FC<Props> = (props) => {
<SettingItem title='下载量'>{calcTraffic(connection.download)}</SettingItem>
<CopyableSettingItem
title='连接类型'
value={connection.metadata.type}
value={[connection.metadata.type, connection.metadata.network]}
displayName={`${connection.metadata.type}(${connection.metadata.network})`}
prefix={['IN-TYPE']}
prefix={['IN-TYPE', 'NETWORK']}
/>
{connection.metadata.host && (
<CopyableSettingItem
Expand All @@ -112,9 +117,9 @@ const ConnectionDetailModal: React.FC<Props> = (props) => {
{connection.metadata.process && (
<CopyableSettingItem
title='进程名'
value={connection.metadata.process}
value={[connection.metadata.process, connection.metadata.uid ? connection.metadata.uid.toString() : '']}
displayName={`${connection.metadata.process}${connection.metadata.uid ? `(${connection.metadata.uid})` : ''}`}
prefix={['PROCESS-NAME']}
prefix={['PROCESS-NAME', 'UID']}
/>
)}
{connection.metadata.processPath && (
Expand All @@ -132,6 +137,20 @@ const ConnectionDetailModal: React.FC<Props> = (props) => {
suffix='/32'
/>
)}
{connection.metadata.sourceGeoIP && (
<CopyableSettingItem
title='来源GeoIP'
value={connection.metadata.sourceGeoIP}
prefix={['SRC-GEOIP']}
/>
)}
{connection.metadata.sourceIPASN && (
<CopyableSettingItem
title='来源ASN'
value={connection.metadata.sourceIPASN}
prefix={['SRC-IP-ASN']}
/>
)}
{connection.metadata.destinationIP && (
<CopyableSettingItem
title='目标IP'
Expand Down
2 changes: 2 additions & 0 deletions src/shared/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ interface IMihomoConnectionDetail {
network: 'tcp' | 'udp'
type: string
sourceIP: string
sourceGeoIP: string
sourceIPASN: string
destinationIP: string
destinationGeoIP: string
destinationIPASN: string
Expand Down

0 comments on commit c338051

Please sign in to comment.