mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-11-15 15:32:21 +08:00
* refactor: mihomo ipc request * refactor: remove redundant write locks and await on mihomo handle * fix(rule): handle non-string types in ProviderButton labels * refactor: handle non-string value types in RuleItem component * refactor(tauri): remove unnecessary await in get_base_config call * chore: update tauri-plugin-mihomo deps * refactor: rename ConnectionId to WsConnectionId * chore: update tauri-plugin-mihomo-api dependency reference * chore(config): use Proxy::default in profile test initialization
73 lines
1.7 KiB
TypeScript
73 lines
1.7 KiB
TypeScript
import { styled, Box, Typography } from '@mui/material'
|
|
import { Rule } from 'tauri-plugin-mihomo-api'
|
|
|
|
const Item = styled(Box)(({ theme }) => ({
|
|
display: 'flex',
|
|
padding: '4px 16px',
|
|
color: theme.palette.text.primary,
|
|
}))
|
|
|
|
const COLOR = [
|
|
'primary',
|
|
'secondary',
|
|
'info.main',
|
|
'warning.main',
|
|
'success.main',
|
|
]
|
|
|
|
interface Props {
|
|
value: Rule & { lineNo: number }
|
|
}
|
|
|
|
const parseColor = (text: string) => {
|
|
if (text === 'REJECT' || text === 'REJECT-DROP') return 'error.main'
|
|
if (text === 'DIRECT') return 'text.primary'
|
|
|
|
let sum = 0
|
|
for (let i = 0; i < text.length; i++) {
|
|
sum += text.charCodeAt(i)
|
|
}
|
|
return COLOR[sum % COLOR.length]
|
|
}
|
|
|
|
const RuleItem = (props: Props) => {
|
|
const { value } = props
|
|
|
|
return (
|
|
<Item sx={{ borderBottom: '1px solid var(--divider-color)' }}>
|
|
<Typography
|
|
color="text.secondary"
|
|
variant="body2"
|
|
sx={{ lineHeight: 2, minWidth: 30, mr: 2.25, textAlign: 'center' }}
|
|
>
|
|
{value.lineNo}
|
|
</Typography>
|
|
|
|
<Box sx={{ userSelect: 'text' }}>
|
|
<Typography component="h6" variant="subtitle1" color="text.primary">
|
|
{value.payload || '-'}
|
|
</Typography>
|
|
|
|
<Typography
|
|
component="span"
|
|
variant="body2"
|
|
color="text.secondary"
|
|
sx={{ mr: 3, minWidth: 120, display: 'inline-block' }}
|
|
>
|
|
{typeof value.type === 'string' ? value.type : value.type.Unknown}
|
|
</Typography>
|
|
|
|
<Typography
|
|
component="span"
|
|
variant="body2"
|
|
color={parseColor(value.proxy)}
|
|
>
|
|
{value.proxy}
|
|
</Typography>
|
|
</Box>
|
|
</Item>
|
|
)
|
|
}
|
|
|
|
export default RuleItem
|