mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-11-20 02:42:12 +08:00
Compare commits
8
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f0e1460a04 | ||
|
|
e90f8c500f | ||
|
|
36f79c6033 | ||
|
|
d535c1b7d1 | ||
|
|
d162478100 | ||
|
|
f4761e763a | ||
|
|
01e28608ef | ||
|
|
0013fb3680 |
@@ -63,6 +63,7 @@
|
|||||||
<details>
|
<details>
|
||||||
<summary><strong> 🚀 优化改进 </strong></summary>
|
<summary><strong> 🚀 优化改进 </strong></summary>
|
||||||
|
|
||||||
|
- 优化首页流量图与代理、订阅、日志、设置页面的渲染效率,长列表滚动与实时刷新更流畅
|
||||||
- 优化连接、规则和日志筛选:切换页面后保留过滤条件
|
- 优化连接、规则和日志筛选:切换页面后保留过滤条件
|
||||||
- 优化全局模式代理列表:仅显示 `GLOBAL` 节点,选中其中的策略组时才显示该组
|
- 优化全局模式代理列表:仅显示 `GLOBAL` 节点,选中其中的策略组时才显示该组
|
||||||
- 优化设置页开关和选项所在行的鼠标悬停高亮,便于对应说明与控件
|
- 优化设置页开关和选项所在行的鼠标悬停高亮,便于对应说明与控件
|
||||||
|
|||||||
@@ -87,18 +87,18 @@ export const TestCard = () => {
|
|||||||
x.uid === uid ? { ...x, ...patch } : x,
|
x.uid === uid ? { ...x, ...patch } : x,
|
||||||
)
|
)
|
||||||
|
|
||||||
mutateVerge({ ...verge, test_list: newList })
|
mutateVerge((prev) => ({ ...prev, test_list: newList }))
|
||||||
},
|
},
|
||||||
[testList, verge, mutateVerge],
|
[testList, mutateVerge],
|
||||||
)
|
)
|
||||||
|
|
||||||
const onDeleteTestListItem = useCallback(
|
const onDeleteTestListItem = useCallback(
|
||||||
(uid: string) => {
|
(uid: string) => {
|
||||||
const newList = testList.filter((x) => x.uid !== uid)
|
const newList = testList.filter((x) => x.uid !== uid)
|
||||||
patchVerge({ test_list: newList })
|
patchVerge({ test_list: newList })
|
||||||
mutateVerge({ ...verge, test_list: newList })
|
mutateVerge((prev) => ({ ...prev, test_list: newList }))
|
||||||
},
|
},
|
||||||
[testList, verge, patchVerge, mutateVerge],
|
[testList, patchVerge, mutateVerge],
|
||||||
)
|
)
|
||||||
|
|
||||||
const onDragEnd = useCallback(
|
const onDragEnd = useCallback(
|
||||||
@@ -129,7 +129,7 @@ export const TestCard = () => {
|
|||||||
newList.splice(newIndex, 0, removed)
|
newList.splice(newIndex, 0, removed)
|
||||||
|
|
||||||
// 优化:先本地更新,再异步 patch,避免UI卡死
|
// 优化:先本地更新,再异步 patch,避免UI卡死
|
||||||
mutateVerge({ ...verge, test_list: newList })
|
mutateVerge((prev) => ({ ...prev, test_list: newList }))
|
||||||
const patchFn = () => {
|
const patchFn = () => {
|
||||||
try {
|
try {
|
||||||
patchVerge({ test_list: newList })
|
patchVerge({ test_list: newList })
|
||||||
@@ -141,7 +141,7 @@ export const TestCard = () => {
|
|||||||
setTimeout(patchFn, 0)
|
setTimeout(patchFn, 0)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[testList, verge, mutateVerge, patchVerge],
|
[testList, mutateVerge, patchVerge],
|
||||||
)
|
)
|
||||||
|
|
||||||
// 仅在verge首次加载时初始化测试列表
|
// 仅在verge首次加载时初始化测试列表
|
||||||
|
|||||||
@@ -176,7 +176,10 @@ export const GroupsEditorViewer = (props: Props) => {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
const [groupList, setGroupList] = useState<IProxyGroupConfig[]>([])
|
const [groupList, setGroupList] = useState<IProxyGroupConfig[]>([])
|
||||||
const [proxyPolicyList, setProxyPolicyList] = useState<string[]>([])
|
const [originPolicy, setOriginPolicy] = useState<{
|
||||||
|
proxyNames: string[]
|
||||||
|
groupNames: string[]
|
||||||
|
}>({ proxyNames: [], groupNames: [] })
|
||||||
const [proxyProviderList, setProxyProviderList] = useState<string[]>([])
|
const [proxyProviderList, setProxyProviderList] = useState<string[]>([])
|
||||||
const [prependSeq, setPrependSeq] = useState<IProxyGroupConfig[]>([])
|
const [prependSeq, setPrependSeq] = useState<IProxyGroupConfig[]>([])
|
||||||
const [appendSeq, setAppendSeq] = useState<IProxyGroupConfig[]>([])
|
const [appendSeq, setAppendSeq] = useState<IProxyGroupConfig[]>([])
|
||||||
@@ -353,6 +356,9 @@ export const GroupsEditorViewer = (props: Props) => {
|
|||||||
}
|
}
|
||||||
}, [prependSeq, appendSeq, deleteSeq])
|
}, [prependSeq, appendSeq, deleteSeq])
|
||||||
|
|
||||||
|
// Origin policy names come from profile files that this dialog never
|
||||||
|
// rewrites while open, so they are read once per open; the live seq states
|
||||||
|
// are folded in by the derived proxyPolicyList below.
|
||||||
const fetchProxyPolicy = useCallback(async () => {
|
const fetchProxyPolicy = useCallback(async () => {
|
||||||
const data = await readProfileFile(profileUid)
|
const data = await readProfileFile(profileUid)
|
||||||
const proxiesData = await readProfileFile(proxiesUid)
|
const proxiesData = await readProfileFile(proxiesUid)
|
||||||
@@ -388,17 +394,13 @@ export const GroupsEditorViewer = (props: Props) => {
|
|||||||
(name): name is string => typeof name === 'string' && name.length > 0,
|
(name): name is string => typeof name === 'string' && name.length > 0,
|
||||||
)
|
)
|
||||||
|
|
||||||
const computedPolicyList = builtinProxyPolicies.concat(
|
setOriginPolicy({
|
||||||
prependSeq.map((group: IProxyGroupConfig) => group.name),
|
|
||||||
(originGroupsObj?.['proxy-groups'] || [])
|
|
||||||
.map((group: IProxyGroupConfig) => group.name)
|
|
||||||
.filter((name) => !deleteSeq.includes(name)),
|
|
||||||
appendSeq.map((group: IProxyGroupConfig) => group.name),
|
|
||||||
proxyNames,
|
proxyNames,
|
||||||
)
|
groupNames: (originGroupsObj?.['proxy-groups'] || []).map(
|
||||||
|
(group) => group.name,
|
||||||
setProxyPolicyList(Array.from(new Set(computedPolicyList)))
|
),
|
||||||
}, [appendSeq, deleteSeq, prependSeq, profileUid, proxiesUid])
|
})
|
||||||
|
}, [profileUid, proxiesUid])
|
||||||
const fetchProfile = useCallback(async () => {
|
const fetchProfile = useCallback(async () => {
|
||||||
const data = await readProfileFile(profileUid)
|
const data = await readProfileFile(profileUid)
|
||||||
const mergeData = await readProfileFile(mergeUid)
|
const mergeData = await readProfileFile(mergeUid)
|
||||||
@@ -442,6 +444,16 @@ export const GroupsEditorViewer = (props: Props) => {
|
|||||||
fetchProxyPolicy()
|
fetchProxyPolicy()
|
||||||
}, [fetchProxyPolicy, open])
|
}, [fetchProxyPolicy, open])
|
||||||
|
|
||||||
|
const proxyPolicyList = useMemo(() => {
|
||||||
|
const computedPolicyList = builtinProxyPolicies.concat(
|
||||||
|
prependSeq.map((group) => group.name),
|
||||||
|
originPolicy.groupNames.filter((name) => !deleteSeq.includes(name)),
|
||||||
|
appendSeq.map((group) => group.name),
|
||||||
|
originPolicy.proxyNames,
|
||||||
|
)
|
||||||
|
return Array.from(new Set(computedPolicyList))
|
||||||
|
}, [appendSeq, deleteSeq, originPolicy, prependSeq])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!open) return
|
if (!open) return
|
||||||
fetchContent()
|
fetchContent()
|
||||||
|
|||||||
@@ -61,6 +61,31 @@ const round = keyframes`
|
|||||||
to { transform: rotate(360deg); }
|
to { transform: rotate(360deg); }
|
||||||
`
|
`
|
||||||
|
|
||||||
|
type ContextMenuItem = {
|
||||||
|
label: string
|
||||||
|
handler: () => void
|
||||||
|
disabled: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
const menuLabels: Record<string, TranslationKey> = {
|
||||||
|
home: 'profiles.components.menu.home',
|
||||||
|
select: 'profiles.components.menu.select',
|
||||||
|
shareQrCode: 'profiles.components.menu.shareQrCode',
|
||||||
|
editInfo: 'profiles.components.menu.editInfo',
|
||||||
|
editFile: 'profiles.components.menu.editFile',
|
||||||
|
editRules: 'profiles.components.menu.editRules',
|
||||||
|
editProxies: 'profiles.components.menu.editProxies',
|
||||||
|
editGroups: 'profiles.components.menu.editGroups',
|
||||||
|
extendConfig: 'profiles.components.menu.extendConfig',
|
||||||
|
extendScript: 'profiles.components.menu.extendScript',
|
||||||
|
openFile: 'profiles.components.menu.openFile',
|
||||||
|
update: 'profiles.components.menu.update',
|
||||||
|
updateViaProxy: 'profiles.components.menu.updateViaProxy',
|
||||||
|
delete: 'shared.actions.delete',
|
||||||
|
} as const
|
||||||
|
|
||||||
|
const EMPTY_CONTEXT_MENU: ContextMenuItem[] = []
|
||||||
|
|
||||||
export interface ProfileItemProps {
|
export interface ProfileItemProps {
|
||||||
id: string
|
id: string
|
||||||
index: number
|
index: number
|
||||||
@@ -68,13 +93,13 @@ export interface ProfileItemProps {
|
|||||||
activating: boolean
|
activating: boolean
|
||||||
itemData: IProfileItem
|
itemData: IProfileItem
|
||||||
mutateProfiles: () => Promise<void>
|
mutateProfiles: () => Promise<void>
|
||||||
onSelect: (force: boolean) => void
|
onSelect: (uid: string, force: boolean) => void
|
||||||
onEdit: () => void
|
onEdit: (item: IProfileItem) => void
|
||||||
onSave?: (prev?: string, curr?: string) => void
|
onSave?: (uid: string, prev?: string, curr?: string) => void
|
||||||
onDelete: () => void
|
onDelete: (uid: string) => void
|
||||||
batchMode?: boolean
|
batchMode?: boolean
|
||||||
isSelected?: boolean
|
isSelected?: boolean
|
||||||
onSelectionChange?: () => void
|
onSelectionChange?: (uid: string) => void
|
||||||
timerUpdateRevision: number
|
timerUpdateRevision: number
|
||||||
completedUpdateRevision: number
|
completedUpdateRevision: number
|
||||||
}
|
}
|
||||||
@@ -322,7 +347,7 @@ const ProfileItemBase = (props: ProfileItemProps) => {
|
|||||||
|
|
||||||
const onEditInfo = () => {
|
const onEditInfo = () => {
|
||||||
setAnchorEl(null)
|
setAnchorEl(null)
|
||||||
onEdit()
|
onEdit(itemData)
|
||||||
}
|
}
|
||||||
|
|
||||||
const onShareQrCode = () => {
|
const onShareQrCode = () => {
|
||||||
@@ -362,7 +387,7 @@ const ProfileItemBase = (props: ProfileItemProps) => {
|
|||||||
|
|
||||||
const onForceSelect = () => {
|
const onForceSelect = () => {
|
||||||
setAnchorEl(null)
|
setAnchorEl(null)
|
||||||
onSelect(true)
|
onSelect(id, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
const onOpenFile = useLockFn(async () => {
|
const onOpenFile = useLockFn(async () => {
|
||||||
@@ -412,175 +437,158 @@ const ProfileItemBase = (props: ProfileItemProps) => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
type ContextMenuItem = {
|
// The context menu is closed on almost every render; building its items
|
||||||
label: string
|
// only while open keeps the idle path allocation-free.
|
||||||
handler: () => void
|
const menuItems: ContextMenuItem[] =
|
||||||
disabled: boolean
|
anchorEl === null
|
||||||
}
|
? EMPTY_CONTEXT_MENU
|
||||||
|
: hasUrl
|
||||||
const menuLabels: Record<string, TranslationKey> = {
|
? [
|
||||||
home: 'profiles.components.menu.home',
|
...(hasHome
|
||||||
select: 'profiles.components.menu.select',
|
? [
|
||||||
shareQrCode: 'profiles.components.menu.shareQrCode',
|
{
|
||||||
editInfo: 'profiles.components.menu.editInfo',
|
label: menuLabels.home,
|
||||||
editFile: 'profiles.components.menu.editFile',
|
handler: onOpenHome,
|
||||||
editRules: 'profiles.components.menu.editRules',
|
disabled: false,
|
||||||
editProxies: 'profiles.components.menu.editProxies',
|
} satisfies ContextMenuItem,
|
||||||
editGroups: 'profiles.components.menu.editGroups',
|
]
|
||||||
extendConfig: 'profiles.components.menu.extendConfig',
|
: []),
|
||||||
extendScript: 'profiles.components.menu.extendScript',
|
{
|
||||||
openFile: 'profiles.components.menu.openFile',
|
label: menuLabels.select,
|
||||||
update: 'profiles.components.menu.update',
|
handler: onForceSelect,
|
||||||
updateViaProxy: 'profiles.components.menu.updateViaProxy',
|
disabled: false,
|
||||||
delete: 'shared.actions.delete',
|
},
|
||||||
} as const
|
{
|
||||||
|
label: menuLabels.shareQrCode,
|
||||||
const urlModeMenu: ContextMenuItem[] = [
|
handler: onShareQrCode,
|
||||||
...(hasHome
|
disabled: false,
|
||||||
? [
|
},
|
||||||
{
|
{
|
||||||
label: menuLabels.home,
|
label: menuLabels.editInfo,
|
||||||
handler: onOpenHome,
|
handler: onEditInfo,
|
||||||
disabled: false,
|
disabled: false,
|
||||||
} satisfies ContextMenuItem,
|
},
|
||||||
]
|
{
|
||||||
: []),
|
label: menuLabels.editFile,
|
||||||
{
|
handler: onEditFile,
|
||||||
label: menuLabels.select,
|
disabled: false,
|
||||||
handler: onForceSelect,
|
},
|
||||||
disabled: false,
|
{
|
||||||
},
|
label: menuLabels.editRules,
|
||||||
{
|
handler: onEditRules,
|
||||||
label: menuLabels.shareQrCode,
|
disabled: !option?.rules,
|
||||||
handler: onShareQrCode,
|
},
|
||||||
disabled: false,
|
{
|
||||||
},
|
label: menuLabels.editProxies,
|
||||||
{
|
handler: onEditProxies,
|
||||||
label: menuLabels.editInfo,
|
disabled: !option?.proxies,
|
||||||
handler: onEditInfo,
|
},
|
||||||
disabled: false,
|
{
|
||||||
},
|
label: menuLabels.editGroups,
|
||||||
{
|
handler: onEditGroups,
|
||||||
label: menuLabels.editFile,
|
disabled: !option?.groups,
|
||||||
handler: onEditFile,
|
},
|
||||||
disabled: false,
|
{
|
||||||
},
|
label: menuLabels.extendConfig,
|
||||||
{
|
handler: onEditMerge,
|
||||||
label: menuLabels.editRules,
|
disabled: !option?.merge,
|
||||||
handler: onEditRules,
|
},
|
||||||
disabled: !option?.rules,
|
{
|
||||||
},
|
label: menuLabels.extendScript,
|
||||||
{
|
handler: onEditScript,
|
||||||
label: menuLabels.editProxies,
|
disabled: !option?.script,
|
||||||
handler: onEditProxies,
|
},
|
||||||
disabled: !option?.proxies,
|
{
|
||||||
},
|
label: menuLabels.openFile,
|
||||||
{
|
handler: onOpenFile,
|
||||||
label: menuLabels.editGroups,
|
disabled: false,
|
||||||
handler: onEditGroups,
|
},
|
||||||
disabled: !option?.groups,
|
{
|
||||||
},
|
label: menuLabels.update,
|
||||||
{
|
handler: () => onUpdate(0),
|
||||||
label: menuLabels.extendConfig,
|
disabled: false,
|
||||||
handler: onEditMerge,
|
},
|
||||||
disabled: !option?.merge,
|
{
|
||||||
},
|
label: menuLabels.updateViaProxy,
|
||||||
{
|
handler: () => onUpdate(2),
|
||||||
label: menuLabels.extendScript,
|
disabled: false,
|
||||||
handler: onEditScript,
|
},
|
||||||
disabled: !option?.script,
|
{
|
||||||
},
|
label: menuLabels.delete,
|
||||||
{
|
handler: () => {
|
||||||
label: menuLabels.openFile,
|
setAnchorEl(null)
|
||||||
handler: onOpenFile,
|
if (batchMode) {
|
||||||
disabled: false,
|
if (onSelectionChange) {
|
||||||
},
|
onSelectionChange(id)
|
||||||
{
|
}
|
||||||
label: menuLabels.update,
|
} else {
|
||||||
handler: () => onUpdate(0),
|
setConfirmOpen(true)
|
||||||
disabled: false,
|
}
|
||||||
},
|
},
|
||||||
{
|
disabled: false,
|
||||||
label: menuLabels.updateViaProxy,
|
},
|
||||||
handler: () => onUpdate(2),
|
]
|
||||||
disabled: false,
|
: [
|
||||||
},
|
{
|
||||||
{
|
label: menuLabels.select,
|
||||||
label: menuLabels.delete,
|
handler: onForceSelect,
|
||||||
handler: () => {
|
disabled: false,
|
||||||
setAnchorEl(null)
|
},
|
||||||
if (batchMode) {
|
{
|
||||||
if (onSelectionChange) {
|
label: menuLabels.editInfo,
|
||||||
onSelectionChange()
|
handler: onEditInfo,
|
||||||
}
|
disabled: false,
|
||||||
} else {
|
},
|
||||||
setConfirmOpen(true)
|
{
|
||||||
}
|
label: menuLabels.editFile,
|
||||||
},
|
handler: onEditFile,
|
||||||
disabled: false,
|
disabled: false,
|
||||||
},
|
},
|
||||||
]
|
{
|
||||||
const fileModeMenu: ContextMenuItem[] = [
|
label: menuLabels.editRules,
|
||||||
{
|
handler: onEditRules,
|
||||||
label: menuLabels.select,
|
disabled: !option?.rules,
|
||||||
handler: onForceSelect,
|
},
|
||||||
disabled: false,
|
{
|
||||||
},
|
label: menuLabels.editProxies,
|
||||||
{
|
handler: onEditProxies,
|
||||||
label: menuLabels.editInfo,
|
disabled: !option?.proxies,
|
||||||
handler: onEditInfo,
|
},
|
||||||
disabled: false,
|
{
|
||||||
},
|
label: menuLabels.editGroups,
|
||||||
{
|
handler: onEditGroups,
|
||||||
label: menuLabels.editFile,
|
disabled: !option?.groups,
|
||||||
handler: onEditFile,
|
},
|
||||||
disabled: false,
|
{
|
||||||
},
|
label: menuLabels.extendConfig,
|
||||||
{
|
handler: onEditMerge,
|
||||||
label: menuLabels.editRules,
|
disabled: !option?.merge,
|
||||||
handler: onEditRules,
|
},
|
||||||
disabled: !option?.rules,
|
{
|
||||||
},
|
label: menuLabels.extendScript,
|
||||||
{
|
handler: onEditScript,
|
||||||
label: menuLabels.editProxies,
|
disabled: !option?.script,
|
||||||
handler: onEditProxies,
|
},
|
||||||
disabled: !option?.proxies,
|
{
|
||||||
},
|
label: menuLabels.openFile,
|
||||||
{
|
handler: onOpenFile,
|
||||||
label: menuLabels.editGroups,
|
disabled: false,
|
||||||
handler: onEditGroups,
|
},
|
||||||
disabled: !option?.groups,
|
{
|
||||||
},
|
label: menuLabels.delete,
|
||||||
{
|
handler: () => {
|
||||||
label: menuLabels.extendConfig,
|
setAnchorEl(null)
|
||||||
handler: onEditMerge,
|
if (batchMode) {
|
||||||
disabled: !option?.merge,
|
if (onSelectionChange) {
|
||||||
},
|
onSelectionChange(id)
|
||||||
{
|
}
|
||||||
label: menuLabels.extendScript,
|
} else {
|
||||||
handler: onEditScript,
|
setConfirmOpen(true)
|
||||||
disabled: !option?.script,
|
}
|
||||||
},
|
},
|
||||||
{
|
disabled: false,
|
||||||
label: menuLabels.openFile,
|
},
|
||||||
handler: onOpenFile,
|
]
|
||||||
disabled: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: menuLabels.delete,
|
|
||||||
handler: () => {
|
|
||||||
setAnchorEl(null)
|
|
||||||
if (batchMode) {
|
|
||||||
if (onSelectionChange) {
|
|
||||||
onSelectionChange()
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
setConfirmOpen(true)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
disabled: false,
|
|
||||||
},
|
|
||||||
]
|
|
||||||
|
|
||||||
const boxStyle = {
|
const boxStyle = {
|
||||||
height: 26,
|
height: 26,
|
||||||
@@ -599,7 +607,7 @@ const ProfileItemBase = (props: ProfileItemProps) => {
|
|||||||
await profileDocument.reload()
|
await profileDocument.reload()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
onSave?.(profileDocument.savedValue, currentValue)
|
onSave?.(id, profileDocument.savedValue, currentValue)
|
||||||
profileDocument.markSaved(currentValue)
|
profileDocument.markSaved(currentValue)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -614,7 +622,7 @@ const ProfileItemBase = (props: ProfileItemProps) => {
|
|||||||
await mergeDocument.reload()
|
await mergeDocument.reload()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
onSave?.(mergeDocument.savedValue, currentValue)
|
onSave?.(id, mergeDocument.savedValue, currentValue)
|
||||||
mergeDocument.markSaved(currentValue)
|
mergeDocument.markSaved(currentValue)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -632,7 +640,7 @@ const ProfileItemBase = (props: ProfileItemProps) => {
|
|||||||
await scriptDocument.reload()
|
await scriptDocument.reload()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
onSave?.(scriptDocument.savedValue, currentValue)
|
onSave?.(id, scriptDocument.savedValue, currentValue)
|
||||||
scriptDocument.markSaved(currentValue)
|
scriptDocument.markSaved(currentValue)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -646,7 +654,7 @@ const ProfileItemBase = (props: ProfileItemProps) => {
|
|||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
onSelect(false)
|
onSelect(id, false)
|
||||||
}}
|
}}
|
||||||
onContextMenu={(event) => {
|
onContextMenu={(event) => {
|
||||||
const { clientX, clientY } = event
|
const { clientX, clientY } = event
|
||||||
@@ -687,7 +695,7 @@ const ProfileItemBase = (props: ProfileItemProps) => {
|
|||||||
onClick={(e) => {
|
onClick={(e) => {
|
||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
if (onSelectionChange) {
|
if (onSelectionChange) {
|
||||||
onSelectionChange()
|
onSelectionChange(id)
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
@@ -853,7 +861,7 @@ const ProfileItemBase = (props: ProfileItemProps) => {
|
|||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{(hasUrl ? urlModeMenu : fileModeMenu).map((item) => (
|
{menuItems.map((item) => (
|
||||||
<MenuItem
|
<MenuItem
|
||||||
key={item.label}
|
key={item.label}
|
||||||
onClick={item.handler}
|
onClick={item.handler}
|
||||||
@@ -897,7 +905,7 @@ const ProfileItemBase = (props: ProfileItemProps) => {
|
|||||||
profileUid={uid!}
|
profileUid={uid!}
|
||||||
property={option?.rules ?? ''}
|
property={option?.rules ?? ''}
|
||||||
open={true}
|
open={true}
|
||||||
onSave={onSave}
|
onSave={(prev, curr) => onSave?.(id, prev, curr)}
|
||||||
onClose={() => setRulesOpen(false)}
|
onClose={() => setRulesOpen(false)}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
@@ -906,7 +914,7 @@ const ProfileItemBase = (props: ProfileItemProps) => {
|
|||||||
profileUid={uid!}
|
profileUid={uid!}
|
||||||
property={option?.proxies ?? ''}
|
property={option?.proxies ?? ''}
|
||||||
open={true}
|
open={true}
|
||||||
onSave={onSave}
|
onSave={(prev, curr) => onSave?.(id, prev, curr)}
|
||||||
onClose={() => setProxiesOpen(false)}
|
onClose={() => setProxiesOpen(false)}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
@@ -917,7 +925,7 @@ const ProfileItemBase = (props: ProfileItemProps) => {
|
|||||||
profileUid={uid!}
|
profileUid={uid!}
|
||||||
property={option?.groups ?? ''}
|
property={option?.groups ?? ''}
|
||||||
open={true}
|
open={true}
|
||||||
onSave={onSave}
|
onSave={(prev, curr) => onSave?.(id, prev, curr)}
|
||||||
onClose={() => {
|
onClose={() => {
|
||||||
setGroupsOpen(false)
|
setGroupsOpen(false)
|
||||||
}}
|
}}
|
||||||
@@ -963,7 +971,7 @@ const ProfileItemBase = (props: ProfileItemProps) => {
|
|||||||
onCancel={() => setConfirmOpen(false)}
|
onCancel={() => setConfirmOpen(false)}
|
||||||
onClose={() => setConfirmOpen(false)}
|
onClose={() => setConfirmOpen(false)}
|
||||||
onOk={() => {
|
onOk={() => {
|
||||||
onDelete()
|
onDelete(id)
|
||||||
setConfirmOpen(false)
|
setConfirmOpen(false)
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -180,7 +180,7 @@ export const ProxiesEditorViewer = (props: Props) => {
|
|||||||
// 优化:异步分片解析,避免主线程阻塞,解析完成后批量setState
|
// 优化:异步分片解析,避免主线程阻塞,解析完成后批量setState
|
||||||
const handleParseAsync = (cb: (proxies: IProxyConfig[]) => void) => {
|
const handleParseAsync = (cb: (proxies: IProxyConfig[]) => void) => {
|
||||||
const proxies: IProxyConfig[] = []
|
const proxies: IProxyConfig[] = []
|
||||||
const names: string[] = []
|
const names = new Set<string>()
|
||||||
let uris: string
|
let uris: string
|
||||||
try {
|
try {
|
||||||
uris = atob(proxyUri)
|
uris = atob(proxyUri)
|
||||||
@@ -198,9 +198,9 @@ export const ProxiesEditorViewer = (props: Props) => {
|
|||||||
const uri = lines[idx]
|
const uri = lines[idx]
|
||||||
try {
|
try {
|
||||||
const proxy = parseUri(uri.trim())
|
const proxy = parseUri(uri.trim())
|
||||||
if (!names.includes(proxy.name)) {
|
if (!names.has(proxy.name)) {
|
||||||
proxies.push(proxy)
|
proxies.push(proxy)
|
||||||
names.push(proxy.name)
|
names.add(proxy.name)
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.warn(
|
console.warn(
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import * as yaml from 'js-yaml'
|
|||||||
import {
|
import {
|
||||||
getRecord,
|
getRecord,
|
||||||
rebindNode,
|
rebindNode,
|
||||||
|
sameSource,
|
||||||
type ProxyNodeView,
|
type ProxyNodeView,
|
||||||
type ProxyViewV1,
|
type ProxyViewV1,
|
||||||
} from '@/types/proxy-view'
|
} from '@/types/proxy-view'
|
||||||
@@ -20,22 +21,47 @@ export const rebindProxyChainItems = (
|
|||||||
items: readonly ProxyChainItem[],
|
items: readonly ProxyChainItem[],
|
||||||
candidates: readonly ProxyNodeView[],
|
candidates: readonly ProxyNodeView[],
|
||||||
proxyView: ProxyViewV1,
|
proxyView: ProxyViewV1,
|
||||||
): ProxyChainItem[] =>
|
): ProxyChainItem[] => {
|
||||||
items.map((item) => {
|
// The proxy view refreshes on a fixed cadence; reusing item and array
|
||||||
|
// identities while the rebound values are equal keeps persistence effects
|
||||||
|
// and memoized chain rows from reprocessing identical content.
|
||||||
|
let reboundItems: ProxyChainItem[] | undefined
|
||||||
|
items.forEach((item, index) => {
|
||||||
const rebound = rebindNode(candidates, {
|
const rebound = rebindNode(candidates, {
|
||||||
name: item.name,
|
name: item.name,
|
||||||
source: item.source,
|
source: item.source,
|
||||||
})
|
})
|
||||||
const record =
|
const record =
|
||||||
rebound === undefined ? undefined : getRecord(proxyView, rebound.recordId)
|
rebound === undefined ? undefined : getRecord(proxyView, rebound.recordId)
|
||||||
return {
|
const source = rebound?.source ?? item.source
|
||||||
|
const type = rebound?.type ?? item.type
|
||||||
|
const delay = record?.history.at(-1)?.delay
|
||||||
|
const sourceReused =
|
||||||
|
item.source === source ||
|
||||||
|
(item.source !== undefined &&
|
||||||
|
source !== undefined &&
|
||||||
|
sameSource(item.source, source))
|
||||||
|
|
||||||
|
if (
|
||||||
|
item.recordId === rebound?.recordId &&
|
||||||
|
sourceReused &&
|
||||||
|
item.type === type &&
|
||||||
|
item.delay === delay
|
||||||
|
) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
reboundItems ??= [...items]
|
||||||
|
reboundItems[index] = {
|
||||||
...item,
|
...item,
|
||||||
recordId: rebound?.recordId,
|
recordId: rebound?.recordId,
|
||||||
source: rebound?.source ?? item.source,
|
source,
|
||||||
type: rebound?.type ?? item.type,
|
type,
|
||||||
delay: record?.history.at(-1)?.delay,
|
delay,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
return reboundItems ?? (items as ProxyChainItem[])
|
||||||
|
}
|
||||||
|
|
||||||
interface ParsedChainConfig {
|
interface ParsedChainConfig {
|
||||||
proxies?: Array<{
|
proxies?: Array<{
|
||||||
|
|||||||
@@ -31,9 +31,9 @@ interface Props {
|
|||||||
url?: string
|
url?: string
|
||||||
groupName: string
|
groupName: string
|
||||||
headState: HeadState
|
headState: HeadState
|
||||||
onLocation: () => void
|
onLocation: (groupName: string) => void
|
||||||
onCheckDelay: () => void
|
onCheckDelay: (groupName: string) => void
|
||||||
onHeadState: (val: Partial<HeadState>) => void
|
onHeadState: (groupName: string, val: Partial<HeadState>) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
export const ProxyGroupTools = memo(function ProxyGroupTools(props: Props) {
|
export const ProxyGroupTools = memo(function ProxyGroupTools(props: Props) {
|
||||||
@@ -76,7 +76,7 @@ export const ProxyGroupTools = memo(function ProxyGroupTools(props: Props) {
|
|||||||
// 因此对写入 headState 的动作做防抖,避免每输入一个字符就过滤一次。
|
// 因此对写入 headState 的动作做防抖,避免每输入一个字符就过滤一次。
|
||||||
const { run: applyFilter, flush: flushFilter } = useDebounceFn(
|
const { run: applyFilter, flush: flushFilter } = useDebounceFn(
|
||||||
(state: SearchState) => {
|
(state: SearchState) => {
|
||||||
onHeadState({
|
onHeadState(groupName, {
|
||||||
filterText: state.text,
|
filterText: state.text,
|
||||||
filterMatchCase: state.matchCase,
|
filterMatchCase: state.matchCase,
|
||||||
filterMatchWholeWord: state.matchWholeWord,
|
filterMatchWholeWord: state.matchWholeWord,
|
||||||
@@ -125,7 +125,7 @@ export const ProxyGroupTools = memo(function ProxyGroupTools(props: Props) {
|
|||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
}}
|
}}
|
||||||
onChange={(e) => onHeadState({ testUrl: e.target.value })}
|
onChange={(e) => onHeadState(groupName, { testUrl: e.target.value })}
|
||||||
sx={{ flex: '1 1 auto', input: { py: 0.65, px: 1 } }}
|
sx={{ flex: '1 1 auto', input: { py: 0.65, px: 1 } }}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
@@ -155,8 +155,8 @@ export const ProxyGroupTools = memo(function ProxyGroupTools(props: Props) {
|
|||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
if (!headState.open)
|
if (!headState.open)
|
||||||
// eslint-disable-next-line @eslint-react/dom-no-flush-sync
|
// eslint-disable-next-line @eslint-react/dom-no-flush-sync
|
||||||
flushSync(() => onHeadState({ open: true }))
|
flushSync(() => onHeadState(groupName, { open: true }))
|
||||||
onLocation()
|
onLocation(groupName)
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<MyLocationRounded fontSize="inherit" />
|
<MyLocationRounded fontSize="inherit" />
|
||||||
@@ -171,16 +171,16 @@ export const ProxyGroupTools = memo(function ProxyGroupTools(props: Props) {
|
|||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
if (!headState.open)
|
if (!headState.open)
|
||||||
// eslint-disable-next-line @eslint-react/dom-no-flush-sync
|
// eslint-disable-next-line @eslint-react/dom-no-flush-sync
|
||||||
flushSync(() => onHeadState({ open: true }))
|
flushSync(() => onHeadState(groupName, { open: true }))
|
||||||
// Remind the user that it is custom test url
|
// Remind the user that it is custom test url
|
||||||
if (testUrl?.trim() && textState !== 'filter') {
|
if (testUrl?.trim() && textState !== 'filter') {
|
||||||
onHeadState({ textState: 'url' })
|
onHeadState(groupName, { textState: 'url' })
|
||||||
}
|
}
|
||||||
if (testUrl?.trim() && !isValidUrl(testUrl)) {
|
if (testUrl?.trim() && !isValidUrl(testUrl)) {
|
||||||
showNotice.warning('proxies.feedback.warnings.invalidTestUrl')
|
showNotice.warning('proxies.feedback.warnings.invalidTestUrl')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
onCheckDelay()
|
onCheckDelay(groupName)
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<NetworkCheckRounded fontSize="inherit" />
|
<NetworkCheckRounded fontSize="inherit" />
|
||||||
@@ -201,8 +201,8 @@ export const ProxyGroupTools = memo(function ProxyGroupTools(props: Props) {
|
|||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
if (!headState.open)
|
if (!headState.open)
|
||||||
// eslint-disable-next-line @eslint-react/dom-no-flush-sync
|
// eslint-disable-next-line @eslint-react/dom-no-flush-sync
|
||||||
flushSync(() => onHeadState({ open: true }))
|
flushSync(() => onHeadState(groupName, { open: true }))
|
||||||
onHeadState({
|
onHeadState(groupName, {
|
||||||
sortType: ((sortType + 1) % 3) as ProxySortType,
|
sortType: ((sortType + 1) % 3) as ProxySortType,
|
||||||
})
|
})
|
||||||
}}
|
}}
|
||||||
@@ -219,7 +219,7 @@ export const ProxyGroupTools = memo(function ProxyGroupTools(props: Props) {
|
|||||||
onClick={(e) => {
|
onClick={(e) => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
onHeadState({
|
onHeadState(groupName, {
|
||||||
textState: textState === 'url' ? null : 'url',
|
textState: textState === 'url' ? null : 'url',
|
||||||
})
|
})
|
||||||
setTimeout(() => inputRef.current?.focus())
|
setTimeout(() => inputRef.current?.focus())
|
||||||
@@ -245,8 +245,8 @@ export const ProxyGroupTools = memo(function ProxyGroupTools(props: Props) {
|
|||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
if (!headState.open)
|
if (!headState.open)
|
||||||
// eslint-disable-next-line @eslint-react/dom-no-flush-sync
|
// eslint-disable-next-line @eslint-react/dom-no-flush-sync
|
||||||
flushSync(() => onHeadState({ open: true }))
|
flushSync(() => onHeadState(groupName, { open: true }))
|
||||||
onHeadState({ showType: !showType })
|
onHeadState(groupName, { showType: !showType })
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{showType ? (
|
{showType ? (
|
||||||
@@ -265,8 +265,10 @@ export const ProxyGroupTools = memo(function ProxyGroupTools(props: Props) {
|
|||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
if (!headState.open && textState !== 'filter')
|
if (!headState.open && textState !== 'filter')
|
||||||
// eslint-disable-next-line @eslint-react/dom-no-flush-sync
|
// eslint-disable-next-line @eslint-react/dom-no-flush-sync
|
||||||
flushSync(() => onHeadState({ open: true }))
|
flushSync(() => onHeadState(groupName, { open: true }))
|
||||||
onHeadState({ textState: textState === 'filter' ? null : 'filter' })
|
onHeadState(groupName, {
|
||||||
|
textState: textState === 'filter' ? null : 'filter',
|
||||||
|
})
|
||||||
setTimeout(() => inputRef.current?.focus())
|
setTimeout(() => inputRef.current?.focus())
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ interface ProxyGroupsChainProps {
|
|||||||
// Shared callbacks
|
// Shared callbacks
|
||||||
onCheckAll: (groupName: string) => void
|
onCheckAll: (groupName: string) => void
|
||||||
onHeadState: (groupName: string, patch: Partial<HeadState>) => void
|
onHeadState: (groupName: string, patch: Partial<HeadState>) => void
|
||||||
onLocation: (group: any) => void
|
onLocation: (groupName: string) => void
|
||||||
onGroupSelect: (groupName: string) => void
|
onGroupSelect: (groupName: string) => void
|
||||||
onScrollToTop: () => void
|
onScrollToTop: () => void
|
||||||
}
|
}
|
||||||
@@ -245,7 +245,7 @@ function ProxyVirtualList({
|
|||||||
activeStickyIndex: number | null
|
activeStickyIndex: number | null
|
||||||
isChainMode?: boolean
|
isChainMode?: boolean
|
||||||
measureElement: (node: Element | null) => void
|
measureElement: (node: Element | null) => void
|
||||||
onLocation: (group: any) => void
|
onLocation: (groupName: string) => void
|
||||||
onCheckAll: (groupName: string) => void
|
onCheckAll: (groupName: string) => void
|
||||||
onHeadState: (groupName: string, patch: Partial<HeadState>) => void
|
onHeadState: (groupName: string, patch: Partial<HeadState>) => void
|
||||||
onChangeProxy: (group: ProxyGroupView, member: ResolvedProxyMember) => void
|
onChangeProxy: (group: ProxyGroupView, member: ResolvedProxyMember) => void
|
||||||
|
|||||||
@@ -324,16 +324,20 @@ function ChainProxyGroups(props: {
|
|||||||
scrollTopRef.current = 0
|
scrollTopRef.current = 0
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
const handleLocation = useStableCallback((group: ProxyGroupView) => {
|
const handleLocation = useStableCallback((groupName: string) => {
|
||||||
if (!group) return
|
// Flat (type 1) headers such as GLOBAL carry the same live group.
|
||||||
const { name, now } = group
|
const headerIndex = renderList.findIndex(
|
||||||
|
(e) => (e.type === 0 || e.type === 1) && e.group?.name === groupName,
|
||||||
|
)
|
||||||
|
const now = renderList[headerIndex]?.group?.now
|
||||||
|
if (!now) return
|
||||||
|
|
||||||
const index = renderList.findIndex(
|
const index = renderList.findIndex(
|
||||||
(item) =>
|
(e) =>
|
||||||
item.group?.name === name &&
|
e.group?.name === groupName &&
|
||||||
((item.type === 2 && item.member?.member.ref.name === now) ||
|
((e.type === 2 && e.member?.member.ref.name === now) ||
|
||||||
(item.type === 4 &&
|
(e.type === 4 &&
|
||||||
item.memberCol?.some(({ member }) => member.ref.name === now))),
|
e.memberCol?.some(({ member }) => member.ref.name === now))),
|
||||||
)
|
)
|
||||||
|
|
||||||
if (index >= 0) {
|
if (index >= 0) {
|
||||||
@@ -496,13 +500,17 @@ function NormalProxyGroups(props: { mode: string }) {
|
|||||||
[globalGroupName, select, setHeadState],
|
[globalGroupName, select, setHeadState],
|
||||||
)
|
)
|
||||||
|
|
||||||
const handleLocation = useStableCallback((group: ProxyGroupView) => {
|
const handleLocation = useStableCallback((groupName: string) => {
|
||||||
if (!group) return
|
// Flat (type 1) headers such as GLOBAL carry the same live group.
|
||||||
const { name, now } = group
|
const headerIndex = renderList.findIndex(
|
||||||
|
(e) => (e.type === 0 || e.type === 1) && e.group?.name === groupName,
|
||||||
|
)
|
||||||
|
const now = renderList[headerIndex]?.group?.now
|
||||||
|
if (!now) return
|
||||||
|
|
||||||
const index = renderList.findIndex(
|
const index = renderList.findIndex(
|
||||||
(e) =>
|
(e) =>
|
||||||
e.group?.name === name &&
|
e.group?.name === groupName &&
|
||||||
((e.type === 2 && e.member?.member.ref.name === now) ||
|
((e.type === 2 && e.member?.member.ref.name === now) ||
|
||||||
(e.type === 4 &&
|
(e.type === 4 &&
|
||||||
e.memberCol?.some(({ member }) => member.ref.name === now))),
|
e.memberCol?.some(({ member }) => member.ref.name === now))),
|
||||||
@@ -516,21 +524,20 @@ function NormalProxyGroups(props: { mode: string }) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const handleGroupLocationByName = useCallback(
|
// Stable identity: this feeds the sticky-header render callback; a
|
||||||
(groupName: string) => {
|
// [renderList] dep would re-create it on every list rebuild.
|
||||||
const index = renderList.findIndex(
|
const handleGroupLocationByName = useStableCallback((groupName: string) => {
|
||||||
(item) => item.type === 0 && item.group?.name === groupName,
|
const index = renderList.findIndex(
|
||||||
)
|
(item) => item.type === 0 && item.group?.name === groupName,
|
||||||
|
)
|
||||||
|
|
||||||
if (index >= 0) {
|
if (index >= 0) {
|
||||||
stickyListRef.current?.scrollToIndex(index, {
|
stickyListRef.current?.scrollToIndex(index, {
|
||||||
align: 'start',
|
align: 'start',
|
||||||
behavior: 'smooth',
|
behavior: 'smooth',
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
},
|
})
|
||||||
[renderList],
|
|
||||||
)
|
|
||||||
|
|
||||||
const proxyGroupNames = useMemo(() => {
|
const proxyGroupNames = useMemo(() => {
|
||||||
const names = renderList
|
const names = renderList
|
||||||
|
|||||||
@@ -30,9 +30,9 @@ interface Props {
|
|||||||
url?: string
|
url?: string
|
||||||
groupName: string
|
groupName: string
|
||||||
headState: HeadState
|
headState: HeadState
|
||||||
onLocation: () => void
|
onLocation: (groupName: string) => void
|
||||||
onCheckDelay: () => void
|
onCheckDelay: (groupName: string) => void
|
||||||
onHeadState: (val: Partial<HeadState>) => void
|
onHeadState: (groupName: string, val: Partial<HeadState>) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultSx: SxProps = {}
|
const defaultSx: SxProps = {}
|
||||||
@@ -81,7 +81,7 @@ export const ProxyHead = ({
|
|||||||
size="small"
|
size="small"
|
||||||
color="inherit"
|
color="inherit"
|
||||||
title={t('proxies.page.tooltips.locate')}
|
title={t('proxies.page.tooltips.locate')}
|
||||||
onClick={onLocation}
|
onClick={() => onLocation(groupName)}
|
||||||
>
|
>
|
||||||
<MyLocationRounded />
|
<MyLocationRounded />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
@@ -95,13 +95,13 @@ export const ProxyHead = ({
|
|||||||
// Remind the user that it is custom test url
|
// Remind the user that it is custom test url
|
||||||
if (testUrl?.trim() && textState !== 'filter') {
|
if (testUrl?.trim() && textState !== 'filter') {
|
||||||
debugLog(`[ProxyHead] 使用自定义测试URL: ${testUrl}`)
|
debugLog(`[ProxyHead] 使用自定义测试URL: ${testUrl}`)
|
||||||
onHeadState({ textState: 'url' })
|
onHeadState(groupName, { textState: 'url' })
|
||||||
}
|
}
|
||||||
if (testUrl?.trim() && !isValidUrl(testUrl)) {
|
if (testUrl?.trim() && !isValidUrl(testUrl)) {
|
||||||
showNotice.warning('proxies.feedback.warnings.invalidTestUrl')
|
showNotice.warning('proxies.feedback.warnings.invalidTestUrl')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
onCheckDelay()
|
onCheckDelay(groupName)
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<NetworkCheckRounded />
|
<NetworkCheckRounded />
|
||||||
@@ -118,7 +118,9 @@ export const ProxyHead = ({
|
|||||||
][sortType]
|
][sortType]
|
||||||
}
|
}
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
onHeadState({ sortType: ((sortType + 1) % 3) as ProxySortType })
|
onHeadState(groupName, {
|
||||||
|
sortType: ((sortType + 1) % 3) as ProxySortType,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
{sortType !== 1 && sortType !== 2 && <SortRounded />}
|
{sortType !== 1 && sortType !== 2 && <SortRounded />}
|
||||||
@@ -131,7 +133,9 @@ export const ProxyHead = ({
|
|||||||
color="inherit"
|
color="inherit"
|
||||||
title={t('proxies.page.tooltips.delayCheckUrl')}
|
title={t('proxies.page.tooltips.delayCheckUrl')}
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
onHeadState({ textState: textState === 'url' ? null : 'url' })
|
onHeadState(groupName, {
|
||||||
|
textState: textState === 'url' ? null : 'url',
|
||||||
|
})
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
{textState === 'url' ? (
|
{textState === 'url' ? (
|
||||||
@@ -149,7 +153,7 @@ export const ProxyHead = ({
|
|||||||
? t('proxies.page.tooltips.showBasic')
|
? t('proxies.page.tooltips.showBasic')
|
||||||
: t('proxies.page.tooltips.showDetail')
|
: t('proxies.page.tooltips.showDetail')
|
||||||
}
|
}
|
||||||
onClick={() => onHeadState({ showType: !showType })}
|
onClick={() => onHeadState(groupName, { showType: !showType })}
|
||||||
>
|
>
|
||||||
{showType ? <VisibilityRounded /> : <VisibilityOffRounded />}
|
{showType ? <VisibilityRounded /> : <VisibilityOffRounded />}
|
||||||
</IconButton>
|
</IconButton>
|
||||||
@@ -159,7 +163,9 @@ export const ProxyHead = ({
|
|||||||
color="inherit"
|
color="inherit"
|
||||||
title={t('proxies.page.tooltips.filter')}
|
title={t('proxies.page.tooltips.filter')}
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
onHeadState({ textState: textState === 'filter' ? null : 'filter' })
|
onHeadState(groupName, {
|
||||||
|
textState: textState === 'filter' ? null : 'filter',
|
||||||
|
})
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
{textState === 'filter' ? <SearchOffRounded /> : <SearchRounded />}
|
{textState === 'filter' ? <SearchOffRounded /> : <SearchRounded />}
|
||||||
@@ -176,7 +182,7 @@ export const ProxyHead = ({
|
|||||||
useRegularExpression: filterUseRegularExpression,
|
useRegularExpression: filterUseRegularExpression,
|
||||||
}}
|
}}
|
||||||
onSearch={(_, state) =>
|
onSearch={(_, state) =>
|
||||||
onHeadState({
|
onHeadState(groupName, {
|
||||||
filterText: state.text,
|
filterText: state.text,
|
||||||
filterMatchCase: state.matchCase,
|
filterMatchCase: state.matchCase,
|
||||||
filterMatchWholeWord: state.matchWholeWord,
|
filterMatchWholeWord: state.matchWholeWord,
|
||||||
@@ -197,7 +203,7 @@ export const ProxyHead = ({
|
|||||||
size="small"
|
size="small"
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
placeholder={t('proxies.page.placeholders.delayCheckUrl')}
|
placeholder={t('proxies.page.placeholders.delayCheckUrl')}
|
||||||
onChange={(e) => onHeadState({ testUrl: e.target.value })}
|
onChange={(e) => onHeadState(groupName, { testUrl: e.target.value })}
|
||||||
sx={{ ml: 0.5, flex: '1 1 auto', input: { py: 0.65, px: 1 } }}
|
sx={{ ml: 0.5, flex: '1 1 auto', input: { py: 0.65, px: 1 } }}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ interface RenderProps {
|
|||||||
item: IRenderItem
|
item: IRenderItem
|
||||||
stickyed?: boolean
|
stickyed?: boolean
|
||||||
isChainMode?: boolean
|
isChainMode?: boolean
|
||||||
onLocation: (group: IRenderItem['group']) => void
|
onLocation: (groupName: string) => void
|
||||||
onCheckAll: (groupName: string) => void
|
onCheckAll: (groupName: string) => void
|
||||||
onHeadState: (groupName: string, patch: Partial<HeadState>) => void
|
onHeadState: (groupName: string, patch: Partial<HeadState>) => void
|
||||||
onChangeProxy: (
|
onChangeProxy: (
|
||||||
@@ -179,9 +179,9 @@ const ProxyGroupHeader = (props: RenderProps) => {
|
|||||||
url={group.testUrl!}
|
url={group.testUrl!}
|
||||||
groupName={group.name}
|
groupName={group.name}
|
||||||
headState={headState!}
|
headState={headState!}
|
||||||
onLocation={() => onLocation(group)}
|
onLocation={onLocation}
|
||||||
onCheckDelay={() => onCheckAll(group.name)}
|
onCheckDelay={onCheckAll}
|
||||||
onHeadState={(p) => onHeadState(group.name, p)}
|
onHeadState={onHeadState}
|
||||||
/>
|
/>
|
||||||
{!toolsOnLeft && proxyCount}
|
{!toolsOnLeft && proxyCount}
|
||||||
</ProxyGroupHeaderBlock>
|
</ProxyGroupHeaderBlock>
|
||||||
@@ -270,9 +270,9 @@ export const ProxyRender = memo(function ProxyRender(props: RenderProps) {
|
|||||||
url={group.testUrl!}
|
url={group.testUrl!}
|
||||||
groupName={group.name}
|
groupName={group.name}
|
||||||
headState={headState!}
|
headState={headState!}
|
||||||
onLocation={() => onLocation(group)}
|
onLocation={onLocation}
|
||||||
onCheckDelay={() => onCheckAll(group.name)}
|
onCheckDelay={onCheckAll}
|
||||||
onHeadState={(p) => onHeadState(group.name, p)}
|
onHeadState={onHeadState}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -175,15 +175,19 @@ export const useRenderList = (
|
|||||||
chainOccurrencesRef.current = chainOccurrences
|
chainOccurrencesRef.current = chainOccurrences
|
||||||
const chainDelayGroup =
|
const chainDelayGroup =
|
||||||
mode === 'rule' && selectedGroup ? selectedGroup : CHAIN_DELAY_GROUP
|
mode === 'rule' && selectedGroup ? selectedGroup : CHAIN_DELAY_GROUP
|
||||||
const chainDelayKey = chainOccurrences
|
const chainDelayKey = useMemo(
|
||||||
.map(({ member }) => {
|
() =>
|
||||||
if (member.kind !== 'node') return `${member.kind}:${member.ref.name}`
|
chainOccurrences
|
||||||
const source = member.node.source
|
.map(({ member }) => {
|
||||||
return source.kind === 'provider'
|
if (member.kind !== 'node') return `${member.kind}:${member.ref.name}`
|
||||||
? `provider:${source.providerName}:${source.proxyName}`
|
const source = member.node.source
|
||||||
: `core:${source.proxyName}`
|
return source.kind === 'provider'
|
||||||
})
|
? `provider:${source.providerName}:${source.proxyName}`
|
||||||
.join('\u0000')
|
: `core:${source.proxyName}`
|
||||||
|
})
|
||||||
|
.join('\u0000'),
|
||||||
|
[chainOccurrences],
|
||||||
|
)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!isChainMode || !chainDelayKey) return
|
if (!isChainMode || !chainDelayKey) return
|
||||||
|
|||||||
@@ -51,6 +51,25 @@ const Item = styled(ListItem)(() => ({
|
|||||||
},
|
},
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
// Static editor settings; a per-render object would re-trigger Monaco's
|
||||||
|
// updateOptions and listener resubscription on every keystroke. The minimap
|
||||||
|
// depends on the live window width and is applied at editor mount instead.
|
||||||
|
const MONACO_OPTIONS = {
|
||||||
|
tabSize: 2,
|
||||||
|
mouseWheelZoom: true,
|
||||||
|
quickSuggestions: {
|
||||||
|
strings: true,
|
||||||
|
comments: true,
|
||||||
|
other: true,
|
||||||
|
},
|
||||||
|
padding: {
|
||||||
|
top: 33,
|
||||||
|
},
|
||||||
|
fontFamily: MONACO_FONT_FAMILY,
|
||||||
|
fontLigatures: false,
|
||||||
|
smoothScrolling: true,
|
||||||
|
} as const
|
||||||
|
|
||||||
type NameserverPolicy = Record<string, any>
|
type NameserverPolicy = Record<string, any>
|
||||||
|
|
||||||
function parseNameserverPolicy(str: string): NameserverPolicy {
|
function parseNameserverPolicy(str: string): NameserverPolicy {
|
||||||
@@ -520,9 +539,21 @@ export function DnsViewer({ ref }: { ref?: Ref<DialogRef> }) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const handleYamlChange = (value?: string) => {
|
const handleYamlChange = useCallback((value?: string) => {
|
||||||
setYamlContent(value || '')
|
setYamlContent(value || '')
|
||||||
}
|
}, [])
|
||||||
|
|
||||||
|
const handleEditorMount = useCallback(
|
||||||
|
(editorInstance: MonacoEditorInstance) => {
|
||||||
|
editorRef.current = editorInstance
|
||||||
|
editorInstance.updateOptions({
|
||||||
|
minimap: {
|
||||||
|
enabled: document.documentElement.clientWidth >= 1500,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
},
|
||||||
|
[],
|
||||||
|
)
|
||||||
|
|
||||||
const handleChange = (field: string) => (event: any) => {
|
const handleChange = (field: string) => (event: any) => {
|
||||||
const value =
|
const value =
|
||||||
@@ -1052,27 +1083,8 @@ export function DnsViewer({ ref }: { ref?: Ref<DialogRef> }) {
|
|||||||
value={yamlContent}
|
value={yamlContent}
|
||||||
theme={themeMode === 'light' ? 'light' : 'vs-dark'}
|
theme={themeMode === 'light' ? 'light' : 'vs-dark'}
|
||||||
className="flex-grow"
|
className="flex-grow"
|
||||||
onMount={(editorInstance) => {
|
onMount={handleEditorMount}
|
||||||
editorRef.current = editorInstance
|
options={MONACO_OPTIONS}
|
||||||
}}
|
|
||||||
options={{
|
|
||||||
tabSize: 2,
|
|
||||||
minimap: {
|
|
||||||
enabled: document.documentElement.clientWidth >= 1500,
|
|
||||||
},
|
|
||||||
mouseWheelZoom: true,
|
|
||||||
quickSuggestions: {
|
|
||||||
strings: true,
|
|
||||||
comments: true,
|
|
||||||
other: true,
|
|
||||||
},
|
|
||||||
padding: {
|
|
||||||
top: 33,
|
|
||||||
},
|
|
||||||
fontFamily: MONACO_FONT_FAMILY,
|
|
||||||
fontLigatures: false,
|
|
||||||
smoothScrolling: true,
|
|
||||||
}}
|
|
||||||
onChange={handleYamlChange}
|
onChange={handleYamlChange}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ export const LayoutViewer = forwardRef<DialogRef>((_, ref) => {
|
|||||||
showNotice.error(err)
|
showNotice.error(err)
|
||||||
}
|
}
|
||||||
const onChangeData = (patch: Partial<IVergeConfig>) => {
|
const onChangeData = (patch: Partial<IVergeConfig>) => {
|
||||||
mutateVerge({ ...verge, ...patch })
|
mutateVerge((prev) => ({ ...prev, ...patch }))
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -326,7 +326,7 @@ export const SysproxyViewer = forwardRef<DialogRef>((props, ref) => {
|
|||||||
Promise.resolve().then(async () => {
|
Promise.resolve().then(async () => {
|
||||||
try {
|
try {
|
||||||
if (Object.keys(patch).length > 0) {
|
if (Object.keys(patch).length > 0) {
|
||||||
mutateVerge({ ...verge, ...patch })
|
mutateVerge((prev) => ({ ...prev, ...patch }))
|
||||||
}
|
}
|
||||||
if (Object.keys(patch).length > 0) {
|
if (Object.keys(patch).length > 0) {
|
||||||
await patchVerge(patch)
|
await patchVerge(patch)
|
||||||
|
|||||||
@@ -114,6 +114,84 @@ const getAlertTypeFromClassName = (
|
|||||||
return match?.[1] as GitHubAlertType | null
|
return match?.[1] as GitHubAlertType | null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const openUrlWithNotice = (url: string) => {
|
||||||
|
void openExternalUrl(url).catch(showNotice.error)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Renderer map is static; a per-render identity would remount every link and
|
||||||
|
// blockquote subtree while download progress re-renders the dialog.
|
||||||
|
const MARKDOWN_COMPONENTS: ReactMarkdownOptions['components'] = {
|
||||||
|
a: ({ href, children, ...props }) => {
|
||||||
|
const isFragment = href?.startsWith('#') ?? false
|
||||||
|
const renderedHref = isFragment
|
||||||
|
? `#${UPDATE_MARKDOWN_ID_PREFIX}${href?.slice(1)}`
|
||||||
|
: href
|
||||||
|
? '#'
|
||||||
|
: undefined
|
||||||
|
|
||||||
|
return (
|
||||||
|
<a
|
||||||
|
{...props}
|
||||||
|
href={renderedHref}
|
||||||
|
target={undefined}
|
||||||
|
rel={undefined}
|
||||||
|
onClick={(event) => {
|
||||||
|
if (isFragment) return
|
||||||
|
event.preventDefault()
|
||||||
|
if (!href) return
|
||||||
|
openUrlWithNotice(href)
|
||||||
|
}}
|
||||||
|
onAuxClick={(event) => {
|
||||||
|
if (isFragment) return
|
||||||
|
event.preventDefault()
|
||||||
|
if (event.button === 1 && href) {
|
||||||
|
openUrlWithNotice(href)
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</a>
|
||||||
|
)
|
||||||
|
},
|
||||||
|
blockquote: ({ className, children }) => {
|
||||||
|
const alertType = getAlertTypeFromClassName(className)
|
||||||
|
|
||||||
|
if (!alertType) {
|
||||||
|
return <blockquote className={className}>{children}</blockquote>
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Box
|
||||||
|
component="blockquote"
|
||||||
|
className={className}
|
||||||
|
sx={(theme) => {
|
||||||
|
const color = GITHUB_ALERTS[alertType].color
|
||||||
|
return {
|
||||||
|
m: '12px 0 18px',
|
||||||
|
px: 2,
|
||||||
|
py: 1,
|
||||||
|
borderLeft: `4px solid ${color}`,
|
||||||
|
borderRadius: 1,
|
||||||
|
bgcolor: alpha(color, theme.palette.mode === 'dark' ? 0.16 : 0.08),
|
||||||
|
'& p': {
|
||||||
|
my: 0.75,
|
||||||
|
},
|
||||||
|
'& .markdown-alert-title': {
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
gap: 0.75,
|
||||||
|
fontWeight: 700,
|
||||||
|
lineHeight: 1.4,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</Box>
|
||||||
|
)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
const findFirstTextNode = (node: MarkdownNode): MarkdownNode | null => {
|
const findFirstTextNode = (node: MarkdownNode): MarkdownNode | null => {
|
||||||
if (node.type === 'text') return node
|
if (node.type === 'text') return node
|
||||||
for (const child of node.children ?? []) {
|
for (const child of node.children ?? []) {
|
||||||
@@ -185,10 +263,6 @@ export function UpdateViewer({ ref }: { ref?: Ref<DialogRef> }) {
|
|||||||
})
|
})
|
||||||
const { downloaded, total } = download
|
const { downloaded, total } = download
|
||||||
|
|
||||||
const openUrlWithNotice = (url: string) => {
|
|
||||||
void openExternalUrl(url).catch(showNotice.error)
|
|
||||||
}
|
|
||||||
|
|
||||||
const progress = useMemo(() => {
|
const progress = useMemo(() => {
|
||||||
if (total <= 0) return 0
|
if (total <= 0) return 0
|
||||||
return Math.min((downloaded / total) * 100, 100)
|
return Math.min((downloaded / total) * 100, 100)
|
||||||
@@ -212,8 +286,8 @@ export function UpdateViewer({ ref }: { ref?: Ref<DialogRef> }) {
|
|||||||
) as Record<GitHubAlertType, string>,
|
) as Record<GitHubAlertType, string>,
|
||||||
[t],
|
[t],
|
||||||
)
|
)
|
||||||
const remarkGitHubAlertsPlugin = useMemo(
|
const remarkPlugins = useMemo(
|
||||||
() => () => remarkGitHubAlerts(githubAlertLabels),
|
() => [() => remarkGitHubAlerts(githubAlertLabels)],
|
||||||
[githubAlertLabels],
|
[githubAlertLabels],
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -475,83 +549,8 @@ export function UpdateViewer({ ref }: { ref?: Ref<DialogRef> }) {
|
|||||||
{open && (
|
{open && (
|
||||||
<Suspense fallback={<LinearProgress />}>
|
<Suspense fallback={<LinearProgress />}>
|
||||||
<LazyReactMarkdown
|
<LazyReactMarkdown
|
||||||
remarkPlugins={[remarkGitHubAlertsPlugin]}
|
remarkPlugins={remarkPlugins}
|
||||||
components={{
|
components={MARKDOWN_COMPONENTS}
|
||||||
a: ({ href, children, ...props }) => {
|
|
||||||
const isFragment = href?.startsWith('#') ?? false
|
|
||||||
const renderedHref = isFragment
|
|
||||||
? `#${UPDATE_MARKDOWN_ID_PREFIX}${href?.slice(1)}`
|
|
||||||
: href
|
|
||||||
? '#'
|
|
||||||
: undefined
|
|
||||||
|
|
||||||
return (
|
|
||||||
<a
|
|
||||||
{...props}
|
|
||||||
href={renderedHref}
|
|
||||||
target={undefined}
|
|
||||||
rel={undefined}
|
|
||||||
onClick={(event) => {
|
|
||||||
if (isFragment) return
|
|
||||||
event.preventDefault()
|
|
||||||
if (!href) return
|
|
||||||
openUrlWithNotice(href)
|
|
||||||
}}
|
|
||||||
onAuxClick={(event) => {
|
|
||||||
if (isFragment) return
|
|
||||||
event.preventDefault()
|
|
||||||
if (event.button === 1 && href) {
|
|
||||||
openUrlWithNotice(href)
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{children}
|
|
||||||
</a>
|
|
||||||
)
|
|
||||||
},
|
|
||||||
blockquote: ({ className, children }) => {
|
|
||||||
const alertType = getAlertTypeFromClassName(className)
|
|
||||||
|
|
||||||
if (!alertType) {
|
|
||||||
return (
|
|
||||||
<blockquote className={className}>{children}</blockquote>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Box
|
|
||||||
component="blockquote"
|
|
||||||
className={className}
|
|
||||||
sx={(theme) => {
|
|
||||||
const color = GITHUB_ALERTS[alertType].color
|
|
||||||
return {
|
|
||||||
m: '12px 0 18px',
|
|
||||||
px: 2,
|
|
||||||
py: 1,
|
|
||||||
borderLeft: `4px solid ${color}`,
|
|
||||||
borderRadius: 1,
|
|
||||||
bgcolor: alpha(
|
|
||||||
color,
|
|
||||||
theme.palette.mode === 'dark' ? 0.16 : 0.08,
|
|
||||||
),
|
|
||||||
'& p': {
|
|
||||||
my: 0.75,
|
|
||||||
},
|
|
||||||
'& .markdown-alert-title': {
|
|
||||||
display: 'flex',
|
|
||||||
alignItems: 'center',
|
|
||||||
gap: 0.75,
|
|
||||||
fontWeight: 700,
|
|
||||||
lineHeight: 1.4,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{children}
|
|
||||||
</Box>
|
|
||||||
)
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
{markdownContent}
|
{markdownContent}
|
||||||
</LazyReactMarkdown>
|
</LazyReactMarkdown>
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ const SettingSystem = ({ onError }: Props) => {
|
|||||||
value: boolean,
|
value: boolean,
|
||||||
) => value
|
) => value
|
||||||
const onChangeData = (patch: Partial<IVergeConfig>) => {
|
const onChangeData = (patch: Partial<IVergeConfig>) => {
|
||||||
mutateVerge({ ...verge, ...patch })
|
mutateVerge((prev) => ({ ...prev, ...patch }))
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ const SettingVergeBasic = ({ onError }: Props) => {
|
|||||||
const backupRef = useRef<DialogRef>(null)
|
const backupRef = useRef<DialogRef>(null)
|
||||||
|
|
||||||
const onChangeData = (patch: any) => {
|
const onChangeData = (patch: any) => {
|
||||||
mutateVerge({ ...verge, ...patch })
|
mutateVerge((prev) => ({ ...prev, ...patch }))
|
||||||
}
|
}
|
||||||
|
|
||||||
const onCopyClashEnv = useCallback(async () => {
|
const onCopyClashEnv = useCallback(async () => {
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import {
|
|||||||
TextField,
|
TextField,
|
||||||
Typography,
|
Typography,
|
||||||
} from '@mui/material'
|
} from '@mui/material'
|
||||||
import { useEffect, useRef, useState, type ReactNode } from 'react'
|
import { useEffect, useMemo, useRef, useState, type ReactNode } from 'react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
|
|
||||||
import getSystem from '@/utils/get-system'
|
import getSystem from '@/utils/get-system'
|
||||||
@@ -21,6 +21,9 @@ import {
|
|||||||
type SearchDialog,
|
type SearchDialog,
|
||||||
} from './settings-search-context'
|
} from './settings-search-context'
|
||||||
|
|
||||||
|
// Constant for the runtime; module-level like the other getSystem() callers.
|
||||||
|
const OS = getSystem()
|
||||||
|
|
||||||
export function SettingsSearch({
|
export function SettingsSearch({
|
||||||
children,
|
children,
|
||||||
}: {
|
}: {
|
||||||
@@ -40,11 +43,17 @@ export function SettingsSearch({
|
|||||||
const originalScrollRef = useRef(0)
|
const originalScrollRef = useRef(0)
|
||||||
const resultScrollRef = useRef(0)
|
const resultScrollRef = useRef(0)
|
||||||
const cancelLocateRef = useRef<() => void>(() => {})
|
const cancelLocateRef = useRef<() => void>(() => {})
|
||||||
const results = searchSettings(
|
// The catalog scan touches every entry with translations; memoizing keeps
|
||||||
query,
|
// unrelated state (arrow-key selection) from re-running it.
|
||||||
getSystem(),
|
const results = useMemo(
|
||||||
(key) => t(key),
|
() =>
|
||||||
(key) => t(key, { lng: 'en' }),
|
searchSettings(
|
||||||
|
query,
|
||||||
|
OS,
|
||||||
|
(key) => t(key),
|
||||||
|
(key) => t(key, { lng: 'en' }),
|
||||||
|
),
|
||||||
|
[query, t],
|
||||||
)
|
)
|
||||||
const searching = !!query.trim()
|
const searching = !!query.trim()
|
||||||
const scroller = () =>
|
const scroller = () =>
|
||||||
|
|||||||
@@ -163,7 +163,7 @@ const ProxyControlSwitches = ({
|
|||||||
})
|
})
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
mutateVerge({ ...verge, enable_tun_mode: value })
|
mutateVerge((prev) => ({ ...prev, enable_tun_mode: value }))
|
||||||
await patchVerge({ enable_tun_mode: value })
|
await patchVerge({ enable_tun_mode: value })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,9 @@ const FLUSH_DELAY_MS = 50
|
|||||||
type LogType = ILogItem['type']
|
type LogType = ILogItem['type']
|
||||||
|
|
||||||
const DEFAULT_LOG_TYPES: LogType[] = ['debug', 'info', 'warning', 'error']
|
const DEFAULT_LOG_TYPES: LogType[] = ['debug', 'info', 'warning', 'error']
|
||||||
|
// Shared empty fallback: a fresh [] would give `refresh` a new identity on
|
||||||
|
// every render and re-run the snapshot effect while logs stream.
|
||||||
|
const EMPTY_LOGS: ILogItem[] = []
|
||||||
const LOG_LEVEL_FILTERS: Record<LogLevel, LogType[]> = {
|
const LOG_LEVEL_FILTERS: Record<LogLevel, LogType[]> = {
|
||||||
DEBUG: DEFAULT_LOG_TYPES,
|
DEBUG: DEFAULT_LOG_TYPES,
|
||||||
INFO: ['info', 'warning', 'error'],
|
INFO: ['info', 'warning', 'error'],
|
||||||
@@ -55,7 +58,7 @@ export const useLogData = () => {
|
|||||||
|
|
||||||
const { response, refresh, setData } = useMihomoWsSubscription<ILogItem[]>({
|
const { response, refresh, setData } = useMihomoWsSubscription<ILogItem[]>({
|
||||||
subscriptionKey: enableLog ? 'getClashLog' : null,
|
subscriptionKey: enableLog ? 'getClashLog' : null,
|
||||||
fallbackData: [],
|
fallbackData: EMPTY_LOGS,
|
||||||
connect: () => MihomoWebSocket.connect_logs(logLevel),
|
connect: () => MihomoWebSocket.connect_logs(logLevel),
|
||||||
setupHandlers: ({ next, scheduleReconnect, isMounted }) => {
|
setupHandlers: ({ next, scheduleReconnect, isMounted }) => {
|
||||||
let flushTimer: ReturnType<typeof setTimeout> | null = null
|
let flushTimer: ReturnType<typeof setTimeout> | null = null
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ export function useProxyDelayState(
|
|||||||
}
|
}
|
||||||
const cachedUpdate = delayManager.getDelayUpdate(name, groupName)
|
const cachedUpdate = delayManager.getDelayUpdate(name, groupName)
|
||||||
if (cachedUpdate) {
|
if (cachedUpdate) {
|
||||||
setDelayState({ ...cachedUpdate })
|
setDelayState(cachedUpdate)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+25
-19
@@ -3,12 +3,16 @@ import { useCallback } from 'react'
|
|||||||
import { getVergeConfig, patchVergeConfig } from '@/services/cmds'
|
import { getVergeConfig, patchVergeConfig } from '@/services/cmds'
|
||||||
import { mutate } from '@/services/mutate'
|
import { mutate } from '@/services/mutate'
|
||||||
import { getPreloadConfig, setPreloadConfig } from '@/services/preload'
|
import { getPreloadConfig, setPreloadConfig } from '@/services/preload'
|
||||||
import { setCacheData, useQuery } from '@/services/query-client'
|
import {
|
||||||
|
revalidateQuery,
|
||||||
|
setCacheData,
|
||||||
|
useQuery,
|
||||||
|
} from '@/services/query-client'
|
||||||
|
|
||||||
export const useVerge = () => {
|
export const useVerge = () => {
|
||||||
const initialVergeConfig = getPreloadConfig()
|
const initialVergeConfig = getPreloadConfig()
|
||||||
|
|
||||||
const { data: verge, refetch } = useQuery({
|
const { data: verge } = useQuery({
|
||||||
queryKey: ['getVergeConfig'],
|
queryKey: ['getVergeConfig'],
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
const config = await getVergeConfig()
|
const config = await getVergeConfig()
|
||||||
@@ -20,23 +24,25 @@ export const useVerge = () => {
|
|||||||
staleTime: 5000,
|
staleTime: 5000,
|
||||||
})
|
})
|
||||||
|
|
||||||
const mutateVerge = (
|
// Stable identity: many consumers list mutateVerge in their own callback
|
||||||
updaterOrData?:
|
// deps, so a per-render closure here would churn their memoization too.
|
||||||
| IVergeConfig
|
// The updater receives the live cache value (preload snapshot when the
|
||||||
| ((prev: IVergeConfig | undefined) => IVergeConfig | undefined)
|
// cache is still empty) instead of a render-time snapshot, so an older
|
||||||
| undefined,
|
// render cannot clobber a newer cache write.
|
||||||
) => {
|
const mutateVerge = useCallback(
|
||||||
if (updaterOrData === undefined) {
|
(
|
||||||
void refetch()
|
updater?: (prev: IVergeConfig | undefined) => IVergeConfig | undefined,
|
||||||
return
|
) => {
|
||||||
}
|
if (updater === undefined) {
|
||||||
void setCacheData<IVergeConfig>(
|
void revalidateQuery(['getVergeConfig'])
|
||||||
['getVergeConfig'],
|
return
|
||||||
typeof updaterOrData === 'function'
|
}
|
||||||
? (current) => updaterOrData(current ?? verge)
|
void setCacheData<IVergeConfig>(['getVergeConfig'], (current) =>
|
||||||
: updaterOrData,
|
updater(current ?? getPreloadConfig() ?? undefined),
|
||||||
)
|
)
|
||||||
}
|
},
|
||||||
|
[],
|
||||||
|
)
|
||||||
|
|
||||||
// Callers own the error toast (GuardState onCatch / page onError), so the
|
// Callers own the error toast (GuardState onCatch / page onError), so the
|
||||||
// funnel must not add a second one.
|
// funnel must not add a second one.
|
||||||
|
|||||||
+46
-20
@@ -462,9 +462,12 @@ const ProfilePage = () => {
|
|||||||
[runProfileSwitchQueue],
|
[runProfileSwitchQueue],
|
||||||
)
|
)
|
||||||
|
|
||||||
const onSelect = async (profile: string, force: boolean) => {
|
const onSelect = useCallback(
|
||||||
await activateProfile(profile, true, force)
|
async (profile: string, force: boolean) => {
|
||||||
}
|
await activateProfile(profile, true, force)
|
||||||
|
},
|
||||||
|
[activateProfile],
|
||||||
|
)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let cancelled = false
|
let cancelled = false
|
||||||
@@ -594,7 +597,7 @@ const ProfilePage = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const toggleProfileSelection = (uid: string) => {
|
const toggleProfileSelection = useCallback((uid: string) => {
|
||||||
setSelectedProfiles((prev) => {
|
setSelectedProfiles((prev) => {
|
||||||
const newSet = new Set(prev)
|
const newSet = new Set(prev)
|
||||||
if (newSet.has(uid)) {
|
if (newSet.has(uid)) {
|
||||||
@@ -604,7 +607,40 @@ const ProfilePage = () => {
|
|||||||
}
|
}
|
||||||
return newSet
|
return newSet
|
||||||
})
|
})
|
||||||
}
|
}, [])
|
||||||
|
|
||||||
|
// Item-grid callbacks stay identity-stable so ProfileItem's memo holds
|
||||||
|
// across unrelated page state (URL input keystrokes, switch spinners).
|
||||||
|
// onEnhance/onDelete are useLockFn wrappers whose identity changes every
|
||||||
|
// render, so they are read through refs here.
|
||||||
|
const onEnhanceRef = useRef(onEnhance)
|
||||||
|
onEnhanceRef.current = onEnhance
|
||||||
|
const onDeleteRef = useRef(onDelete)
|
||||||
|
onDeleteRef.current = onDelete
|
||||||
|
|
||||||
|
const handleItemEdit = useCallback((item: IProfileItem) => {
|
||||||
|
viewerRef.current?.edit(item)
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
const handleItemSave = useCallback(
|
||||||
|
async (uid: string, prev?: string, curr?: string) => {
|
||||||
|
if (prev !== curr && profiles.current === uid) {
|
||||||
|
await onEnhanceRef.current(false)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[profiles],
|
||||||
|
)
|
||||||
|
|
||||||
|
const handleItemDelete = useCallback(
|
||||||
|
(uid: string) => {
|
||||||
|
if (batchMode) {
|
||||||
|
toggleProfileSelection(uid)
|
||||||
|
} else {
|
||||||
|
onDeleteRef.current(uid)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[batchMode, toggleProfileSelection],
|
||||||
|
)
|
||||||
|
|
||||||
const selectAllProfiles = () => {
|
const selectAllProfiles = () => {
|
||||||
setSelectedProfiles(new Set(profileItems.map((item) => item.uid!)))
|
setSelectedProfiles(new Set(profileItems.map((item) => item.uid!)))
|
||||||
@@ -908,23 +944,13 @@ const ProfilePage = () => {
|
|||||||
completedUpdateRevisions.get(item.uid!) ?? 0
|
completedUpdateRevisions.get(item.uid!) ?? 0
|
||||||
}
|
}
|
||||||
mutateProfiles={mutateProfiles}
|
mutateProfiles={mutateProfiles}
|
||||||
onSelect={(f) => onSelect(item.uid!, f)}
|
onSelect={onSelect}
|
||||||
onEdit={() => viewerRef.current?.edit(item)}
|
onEdit={handleItemEdit}
|
||||||
onSave={async (prev, curr) => {
|
onSave={handleItemSave}
|
||||||
if (prev !== curr && profiles.current === item.uid) {
|
onDelete={handleItemDelete}
|
||||||
await onEnhance(false)
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
onDelete={() => {
|
|
||||||
if (batchMode) {
|
|
||||||
toggleProfileSelection(item.uid!)
|
|
||||||
} else {
|
|
||||||
onDelete(item.uid!)
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
batchMode={batchMode}
|
batchMode={batchMode}
|
||||||
isSelected={selectedProfiles.has(item.uid!)}
|
isSelected={selectedProfiles.has(item.uid!)}
|
||||||
onSelectionChange={() => toggleProfileSelection(item.uid!)}
|
onSelectionChange={toggleProfileSelection}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</Box>
|
</Box>
|
||||||
|
|||||||
@@ -237,7 +237,9 @@ class DelayManager {
|
|||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
return { ...entry }
|
// Entries are replaced, never mutated, so the cached object is shared
|
||||||
|
// directly; readers treat it as immutable.
|
||||||
|
return entry
|
||||||
}
|
}
|
||||||
|
|
||||||
getDelay(name: string, group: string) {
|
getDelay(name: string, group: string) {
|
||||||
|
|||||||
@@ -156,7 +156,7 @@ export const selectRuleChainMembers = (
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const sameSource = (
|
export const sameSource = (
|
||||||
left: ProxyNodeView['source'],
|
left: ProxyNodeView['source'],
|
||||||
right: ProxyNodeView['source'],
|
right: ProxyNodeView['source'],
|
||||||
) =>
|
) =>
|
||||||
|
|||||||
@@ -124,10 +124,10 @@ export class TrafficDataSampler {
|
|||||||
) {
|
) {
|
||||||
rawStart++
|
rawStart++
|
||||||
}
|
}
|
||||||
const rawData = this.rawBuffer.slice(rawStart)
|
const rawCount = this.rawBuffer.length - rawStart
|
||||||
|
|
||||||
if (minutes <= this.config.rawDataMinutes) {
|
if (minutes <= this.config.rawDataMinutes) {
|
||||||
return rawData
|
return this.rawBuffer.slice(rawStart)
|
||||||
}
|
}
|
||||||
|
|
||||||
const compressedCutoffUpper =
|
const compressedCutoffUpper =
|
||||||
@@ -140,19 +140,40 @@ export class TrafficDataSampler {
|
|||||||
) {
|
) {
|
||||||
compressedStart++
|
compressedStart++
|
||||||
}
|
}
|
||||||
|
let compressedEnd = compressedStart
|
||||||
|
while (
|
||||||
|
compressedEnd < this.compressedBuffer.length &&
|
||||||
|
this.compressedBuffer[compressedEnd].timestamp <= compressedCutoffUpper
|
||||||
|
) {
|
||||||
|
compressedEnd++
|
||||||
|
}
|
||||||
|
|
||||||
const compressedData = this.compressedBuffer
|
// Single preallocated result; raw entries keep their stored identity.
|
||||||
.slice(compressedStart)
|
const compressedCount = compressedEnd - compressedStart
|
||||||
.filter((p) => p.timestamp <= compressedCutoffUpper)
|
const result: ITrafficDataPoint[] = new Array(compressedCount + rawCount)
|
||||||
.map((p) => ({
|
for (let i = 0; i < compressedCount; i++) {
|
||||||
up: p.up,
|
const point = this.compressedBuffer[compressedStart + i]
|
||||||
down: p.down,
|
result[i] = {
|
||||||
timestamp: p.timestamp,
|
up: point.up,
|
||||||
}))
|
down: point.down,
|
||||||
|
timestamp: point.timestamp,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (let i = 0; i < rawCount; i++) {
|
||||||
|
result[compressedCount + i] = this.rawBuffer[rawStart + i]
|
||||||
|
}
|
||||||
|
|
||||||
return [...compressedData, ...rawData].sort(
|
// Compressed points precede raw ones except across the trim boundary;
|
||||||
(a, b) => a.timestamp - b.timestamp,
|
// sort only when the two ranges actually interleave.
|
||||||
)
|
if (
|
||||||
|
compressedCount > 0 &&
|
||||||
|
rawCount > 0 &&
|
||||||
|
this.compressedBuffer[compressedEnd - 1].timestamp >
|
||||||
|
this.rawBuffer[rawStart].timestamp
|
||||||
|
) {
|
||||||
|
result.sort((a, b) => a.timestamp - b.timestamp)
|
||||||
|
}
|
||||||
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
getStats(): ISamplerStats {
|
getStats(): ISamplerStats {
|
||||||
|
|||||||
Reference in New Issue
Block a user