mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-11-20 10:52:08 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
da7ccebf66 | ||
|
|
df4d09167d | ||
|
|
cc202fa312 | ||
|
|
f2c70c5180 |
+3
-1
@@ -28,6 +28,8 @@
|
|||||||
<details>
|
<details>
|
||||||
<summary><strong> 🐞 修复问题 </strong></summary>
|
<summary><strong> 🐞 修复问题 </strong></summary>
|
||||||
|
|
||||||
|
- 修复「外部控制器」复制成功的提示一闪而过
|
||||||
|
- 修复订阅的规则、代理组、节点编辑器快速连续操作时条目可能重复或错位
|
||||||
- 修复检测更新后又发布新版时,应用内更新失败
|
- 修复检测更新后又发布新版时,应用内更新失败
|
||||||
- 修复订阅响应过大导致内存占用过高,限制单次下载为 4 MiB
|
- 修复订阅响应过大导致内存占用过高,限制单次下载为 4 MiB
|
||||||
- 修复全局模式默认停在 `DIRECT` 或 `REJECT` 导致流量未经代理,现自动切换到第一个策略组
|
- 修复全局模式默认停在 `DIRECT` 或 `REJECT` 导致流量未经代理,现自动切换到第一个策略组
|
||||||
@@ -63,7 +65,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((prev) => ({ ...prev, test_list: newList }))
|
mutateVerge({ ...verge, test_list: newList })
|
||||||
},
|
},
|
||||||
[testList, mutateVerge],
|
[testList, verge, 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((prev) => ({ ...prev, test_list: newList }))
|
mutateVerge({ ...verge, test_list: newList })
|
||||||
},
|
},
|
||||||
[testList, patchVerge, mutateVerge],
|
[testList, verge, 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((prev) => ({ ...prev, test_list: newList }))
|
mutateVerge({ ...verge, 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, mutateVerge, patchVerge],
|
[testList, verge, mutateVerge, patchVerge],
|
||||||
)
|
)
|
||||||
|
|
||||||
// 仅在verge首次加载时初始化测试列表
|
// 仅在verge首次加载时初始化测试列表
|
||||||
|
|||||||
@@ -176,10 +176,7 @@ export const GroupsEditorViewer = (props: Props) => {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
const [groupList, setGroupList] = useState<IProxyGroupConfig[]>([])
|
const [groupList, setGroupList] = useState<IProxyGroupConfig[]>([])
|
||||||
const [originPolicy, setOriginPolicy] = useState<{
|
const [proxyPolicyList, setProxyPolicyList] = useState<string[]>([])
|
||||||
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[]>([])
|
||||||
@@ -221,7 +218,7 @@ export const GroupsEditorViewer = (props: Props) => {
|
|||||||
group={item}
|
group={item}
|
||||||
onDelete={() => {
|
onDelete={() => {
|
||||||
if (isDeleted) {
|
if (isDeleted) {
|
||||||
setDeleteSeq(deleteSeq.filter((v) => v !== item.name))
|
setDeleteSeq((prev) => prev.filter((v) => v !== item.name))
|
||||||
} else {
|
} else {
|
||||||
setDeleteSeq((prev) => [...prev, item.name])
|
setDeleteSeq((prev) => [...prev, item.name])
|
||||||
}
|
}
|
||||||
@@ -236,7 +233,7 @@ export const GroupsEditorViewer = (props: Props) => {
|
|||||||
type="prepend"
|
type="prepend"
|
||||||
group={item}
|
group={item}
|
||||||
onDelete={() => {
|
onDelete={() => {
|
||||||
setPrependSeq(prependSeq.filter((v) => v.name !== item.name))
|
setPrependSeq((prev) => prev.filter((v) => v.name !== item.name))
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
@@ -247,7 +244,7 @@ export const GroupsEditorViewer = (props: Props) => {
|
|||||||
type="append"
|
type="append"
|
||||||
group={item}
|
group={item}
|
||||||
onDelete={() => {
|
onDelete={() => {
|
||||||
setAppendSeq(appendSeq.filter((v) => v.name !== item.name))
|
setAppendSeq((prev) => prev.filter((v) => v.name !== item.name))
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
@@ -258,21 +255,22 @@ export const GroupsEditorViewer = (props: Props) => {
|
|||||||
activeIndex: number,
|
activeIndex: number,
|
||||||
overIndex: number,
|
overIndex: number,
|
||||||
) => {
|
) => {
|
||||||
const list = category === 'prepend' ? prependSeq : appendSeq
|
|
||||||
const filtered =
|
|
||||||
category === 'prepend' ? filteredPrependSeq : filteredAppendSeq
|
|
||||||
const setList = category === 'prepend' ? setPrependSeq : setAppendSeq
|
const setList = category === 'prepend' ? setPrependSeq : setAppendSeq
|
||||||
const activeRealIndex = findRealIndex(list, filtered, activeIndex)
|
// Recompute inside the updater: two writes in one batch must not read the same pre-batch array.
|
||||||
const overRealIndex = findRealIndex(list, filtered, overIndex)
|
setList((prev) => {
|
||||||
if (
|
const filtered = prev.filter((v) => match(v.name))
|
||||||
activeRealIndex < 0 ||
|
const activeRealIndex = findRealIndex(prev, filtered, activeIndex)
|
||||||
overRealIndex < 0 ||
|
const overRealIndex = findRealIndex(prev, filtered, overIndex)
|
||||||
activeRealIndex === overRealIndex
|
if (
|
||||||
) {
|
activeRealIndex < 0 ||
|
||||||
return
|
overRealIndex < 0 ||
|
||||||
}
|
activeRealIndex === overRealIndex
|
||||||
|
) {
|
||||||
|
return prev
|
||||||
|
}
|
||||||
|
|
||||||
setList(arrayMove(list, activeRealIndex, overRealIndex))
|
return arrayMove(prev, activeRealIndex, overRealIndex)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const fetchContent = useCallback(async () => {
|
const fetchContent = useCallback(async () => {
|
||||||
@@ -356,9 +354,6 @@ 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)
|
||||||
@@ -394,13 +389,17 @@ 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,
|
||||||
)
|
)
|
||||||
|
|
||||||
setOriginPolicy({
|
const computedPolicyList = builtinProxyPolicies.concat(
|
||||||
|
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)
|
||||||
@@ -444,16 +443,6 @@ 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()
|
||||||
@@ -1031,14 +1020,20 @@ export const GroupsEditorViewer = (props: Props) => {
|
|||||||
onClick={() => {
|
onClick={() => {
|
||||||
try {
|
try {
|
||||||
validateGroup()
|
validateGroup()
|
||||||
|
const values = formIns.getValues()
|
||||||
for (const item of [...prependSeq, ...groupList]) {
|
for (const item of [...prependSeq, ...groupList]) {
|
||||||
if (item.name === formIns.getValues().name) {
|
if (item.name === values.name) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
t('profiles.modals.groupsEditor.errors.nameExists'),
|
t('profiles.modals.groupsEditor.errors.nameExists'),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setPrependSeq([formIns.getValues(), ...prependSeq])
|
// Recheck inside the updater so a same-batch second click cannot duplicate the entry.
|
||||||
|
setPrependSeq((prev) =>
|
||||||
|
prev.some((v) => v.name === values.name)
|
||||||
|
? prev
|
||||||
|
: [values, ...prev],
|
||||||
|
)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
showNotice.error(err)
|
showNotice.error(err)
|
||||||
}
|
}
|
||||||
@@ -1055,14 +1050,20 @@ export const GroupsEditorViewer = (props: Props) => {
|
|||||||
onClick={() => {
|
onClick={() => {
|
||||||
try {
|
try {
|
||||||
validateGroup()
|
validateGroup()
|
||||||
|
const values = formIns.getValues()
|
||||||
for (const item of [...appendSeq, ...groupList]) {
|
for (const item of [...appendSeq, ...groupList]) {
|
||||||
if (item.name === formIns.getValues().name) {
|
if (item.name === values.name) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
t('profiles.modals.groupsEditor.errors.nameExists'),
|
t('profiles.modals.groupsEditor.errors.nameExists'),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setAppendSeq([...appendSeq, formIns.getValues()])
|
// Recheck inside the updater so a same-batch second click cannot duplicate the entry.
|
||||||
|
setAppendSeq((prev) =>
|
||||||
|
prev.some((v) => v.name === values.name)
|
||||||
|
? prev
|
||||||
|
: [...prev, values],
|
||||||
|
)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
showNotice.error(err)
|
showNotice.error(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,31 +61,6 @@ 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
|
||||||
@@ -93,13 +68,13 @@ export interface ProfileItemProps {
|
|||||||
activating: boolean
|
activating: boolean
|
||||||
itemData: IProfileItem
|
itemData: IProfileItem
|
||||||
mutateProfiles: () => Promise<void>
|
mutateProfiles: () => Promise<void>
|
||||||
onSelect: (uid: string, force: boolean) => void
|
onSelect: (force: boolean) => void
|
||||||
onEdit: (item: IProfileItem) => void
|
onEdit: () => void
|
||||||
onSave?: (uid: string, prev?: string, curr?: string) => void
|
onSave?: (prev?: string, curr?: string) => void
|
||||||
onDelete: (uid: string) => void
|
onDelete: () => void
|
||||||
batchMode?: boolean
|
batchMode?: boolean
|
||||||
isSelected?: boolean
|
isSelected?: boolean
|
||||||
onSelectionChange?: (uid: string) => void
|
onSelectionChange?: () => void
|
||||||
timerUpdateRevision: number
|
timerUpdateRevision: number
|
||||||
completedUpdateRevision: number
|
completedUpdateRevision: number
|
||||||
}
|
}
|
||||||
@@ -347,7 +322,7 @@ const ProfileItemBase = (props: ProfileItemProps) => {
|
|||||||
|
|
||||||
const onEditInfo = () => {
|
const onEditInfo = () => {
|
||||||
setAnchorEl(null)
|
setAnchorEl(null)
|
||||||
onEdit(itemData)
|
onEdit()
|
||||||
}
|
}
|
||||||
|
|
||||||
const onShareQrCode = () => {
|
const onShareQrCode = () => {
|
||||||
@@ -387,7 +362,7 @@ const ProfileItemBase = (props: ProfileItemProps) => {
|
|||||||
|
|
||||||
const onForceSelect = () => {
|
const onForceSelect = () => {
|
||||||
setAnchorEl(null)
|
setAnchorEl(null)
|
||||||
onSelect(id, true)
|
onSelect(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
const onOpenFile = useLockFn(async () => {
|
const onOpenFile = useLockFn(async () => {
|
||||||
@@ -437,158 +412,175 @@ const ProfileItemBase = (props: ProfileItemProps) => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// The context menu is closed on almost every render; building its items
|
type ContextMenuItem = {
|
||||||
// only while open keeps the idle path allocation-free.
|
label: string
|
||||||
const menuItems: ContextMenuItem[] =
|
handler: () => void
|
||||||
anchorEl === null
|
disabled: boolean
|
||||||
? EMPTY_CONTEXT_MENU
|
}
|
||||||
: hasUrl
|
|
||||||
? [
|
const menuLabels: Record<string, TranslationKey> = {
|
||||||
...(hasHome
|
home: 'profiles.components.menu.home',
|
||||||
? [
|
select: 'profiles.components.menu.select',
|
||||||
{
|
shareQrCode: 'profiles.components.menu.shareQrCode',
|
||||||
label: menuLabels.home,
|
editInfo: 'profiles.components.menu.editInfo',
|
||||||
handler: onOpenHome,
|
editFile: 'profiles.components.menu.editFile',
|
||||||
disabled: false,
|
editRules: 'profiles.components.menu.editRules',
|
||||||
} satisfies ContextMenuItem,
|
editProxies: 'profiles.components.menu.editProxies',
|
||||||
]
|
editGroups: 'profiles.components.menu.editGroups',
|
||||||
: []),
|
extendConfig: 'profiles.components.menu.extendConfig',
|
||||||
{
|
extendScript: 'profiles.components.menu.extendScript',
|
||||||
label: menuLabels.select,
|
openFile: 'profiles.components.menu.openFile',
|
||||||
handler: onForceSelect,
|
update: 'profiles.components.menu.update',
|
||||||
disabled: false,
|
updateViaProxy: 'profiles.components.menu.updateViaProxy',
|
||||||
},
|
delete: 'shared.actions.delete',
|
||||||
{
|
} as const
|
||||||
label: menuLabels.shareQrCode,
|
|
||||||
handler: onShareQrCode,
|
const urlModeMenu: ContextMenuItem[] = [
|
||||||
disabled: false,
|
...(hasHome
|
||||||
},
|
? [
|
||||||
{
|
{
|
||||||
label: menuLabels.editInfo,
|
label: menuLabels.home,
|
||||||
handler: onEditInfo,
|
handler: onOpenHome,
|
||||||
disabled: false,
|
disabled: false,
|
||||||
},
|
} satisfies ContextMenuItem,
|
||||||
{
|
]
|
||||||
label: menuLabels.editFile,
|
: []),
|
||||||
handler: onEditFile,
|
{
|
||||||
disabled: false,
|
label: menuLabels.select,
|
||||||
},
|
handler: onForceSelect,
|
||||||
{
|
disabled: false,
|
||||||
label: menuLabels.editRules,
|
},
|
||||||
handler: onEditRules,
|
{
|
||||||
disabled: !option?.rules,
|
label: menuLabels.shareQrCode,
|
||||||
},
|
handler: onShareQrCode,
|
||||||
{
|
disabled: false,
|
||||||
label: menuLabels.editProxies,
|
},
|
||||||
handler: onEditProxies,
|
{
|
||||||
disabled: !option?.proxies,
|
label: menuLabels.editInfo,
|
||||||
},
|
handler: onEditInfo,
|
||||||
{
|
disabled: false,
|
||||||
label: menuLabels.editGroups,
|
},
|
||||||
handler: onEditGroups,
|
{
|
||||||
disabled: !option?.groups,
|
label: menuLabels.editFile,
|
||||||
},
|
handler: onEditFile,
|
||||||
{
|
disabled: false,
|
||||||
label: menuLabels.extendConfig,
|
},
|
||||||
handler: onEditMerge,
|
{
|
||||||
disabled: !option?.merge,
|
label: menuLabels.editRules,
|
||||||
},
|
handler: onEditRules,
|
||||||
{
|
disabled: !option?.rules,
|
||||||
label: menuLabels.extendScript,
|
},
|
||||||
handler: onEditScript,
|
{
|
||||||
disabled: !option?.script,
|
label: menuLabels.editProxies,
|
||||||
},
|
handler: onEditProxies,
|
||||||
{
|
disabled: !option?.proxies,
|
||||||
label: menuLabels.openFile,
|
},
|
||||||
handler: onOpenFile,
|
{
|
||||||
disabled: false,
|
label: menuLabels.editGroups,
|
||||||
},
|
handler: onEditGroups,
|
||||||
{
|
disabled: !option?.groups,
|
||||||
label: menuLabels.update,
|
},
|
||||||
handler: () => onUpdate(0),
|
{
|
||||||
disabled: false,
|
label: menuLabels.extendConfig,
|
||||||
},
|
handler: onEditMerge,
|
||||||
{
|
disabled: !option?.merge,
|
||||||
label: menuLabels.updateViaProxy,
|
},
|
||||||
handler: () => onUpdate(2),
|
{
|
||||||
disabled: false,
|
label: menuLabels.extendScript,
|
||||||
},
|
handler: onEditScript,
|
||||||
{
|
disabled: !option?.script,
|
||||||
label: menuLabels.delete,
|
},
|
||||||
handler: () => {
|
{
|
||||||
setAnchorEl(null)
|
label: menuLabels.openFile,
|
||||||
if (batchMode) {
|
handler: onOpenFile,
|
||||||
if (onSelectionChange) {
|
disabled: false,
|
||||||
onSelectionChange(id)
|
},
|
||||||
}
|
{
|
||||||
} else {
|
label: menuLabels.update,
|
||||||
setConfirmOpen(true)
|
handler: () => onUpdate(0),
|
||||||
}
|
disabled: false,
|
||||||
},
|
},
|
||||||
disabled: false,
|
{
|
||||||
},
|
label: menuLabels.updateViaProxy,
|
||||||
]
|
handler: () => onUpdate(2),
|
||||||
: [
|
disabled: false,
|
||||||
{
|
},
|
||||||
label: menuLabels.select,
|
{
|
||||||
handler: onForceSelect,
|
label: menuLabels.delete,
|
||||||
disabled: false,
|
handler: () => {
|
||||||
},
|
setAnchorEl(null)
|
||||||
{
|
if (batchMode) {
|
||||||
label: menuLabels.editInfo,
|
if (onSelectionChange) {
|
||||||
handler: onEditInfo,
|
onSelectionChange()
|
||||||
disabled: false,
|
}
|
||||||
},
|
} else {
|
||||||
{
|
setConfirmOpen(true)
|
||||||
label: menuLabels.editFile,
|
}
|
||||||
handler: onEditFile,
|
},
|
||||||
disabled: false,
|
disabled: false,
|
||||||
},
|
},
|
||||||
{
|
]
|
||||||
label: menuLabels.editRules,
|
const fileModeMenu: ContextMenuItem[] = [
|
||||||
handler: onEditRules,
|
{
|
||||||
disabled: !option?.rules,
|
label: menuLabels.select,
|
||||||
},
|
handler: onForceSelect,
|
||||||
{
|
disabled: false,
|
||||||
label: menuLabels.editProxies,
|
},
|
||||||
handler: onEditProxies,
|
{
|
||||||
disabled: !option?.proxies,
|
label: menuLabels.editInfo,
|
||||||
},
|
handler: onEditInfo,
|
||||||
{
|
disabled: false,
|
||||||
label: menuLabels.editGroups,
|
},
|
||||||
handler: onEditGroups,
|
{
|
||||||
disabled: !option?.groups,
|
label: menuLabels.editFile,
|
||||||
},
|
handler: onEditFile,
|
||||||
{
|
disabled: false,
|
||||||
label: menuLabels.extendConfig,
|
},
|
||||||
handler: onEditMerge,
|
{
|
||||||
disabled: !option?.merge,
|
label: menuLabels.editRules,
|
||||||
},
|
handler: onEditRules,
|
||||||
{
|
disabled: !option?.rules,
|
||||||
label: menuLabels.extendScript,
|
},
|
||||||
handler: onEditScript,
|
{
|
||||||
disabled: !option?.script,
|
label: menuLabels.editProxies,
|
||||||
},
|
handler: onEditProxies,
|
||||||
{
|
disabled: !option?.proxies,
|
||||||
label: menuLabels.openFile,
|
},
|
||||||
handler: onOpenFile,
|
{
|
||||||
disabled: false,
|
label: menuLabels.editGroups,
|
||||||
},
|
handler: onEditGroups,
|
||||||
{
|
disabled: !option?.groups,
|
||||||
label: menuLabels.delete,
|
},
|
||||||
handler: () => {
|
{
|
||||||
setAnchorEl(null)
|
label: menuLabels.extendConfig,
|
||||||
if (batchMode) {
|
handler: onEditMerge,
|
||||||
if (onSelectionChange) {
|
disabled: !option?.merge,
|
||||||
onSelectionChange(id)
|
},
|
||||||
}
|
{
|
||||||
} else {
|
label: menuLabels.extendScript,
|
||||||
setConfirmOpen(true)
|
handler: onEditScript,
|
||||||
}
|
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,
|
||||||
@@ -607,7 +599,7 @@ const ProfileItemBase = (props: ProfileItemProps) => {
|
|||||||
await profileDocument.reload()
|
await profileDocument.reload()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
onSave?.(id, profileDocument.savedValue, currentValue)
|
onSave?.(profileDocument.savedValue, currentValue)
|
||||||
profileDocument.markSaved(currentValue)
|
profileDocument.markSaved(currentValue)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -622,7 +614,7 @@ const ProfileItemBase = (props: ProfileItemProps) => {
|
|||||||
await mergeDocument.reload()
|
await mergeDocument.reload()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
onSave?.(id, mergeDocument.savedValue, currentValue)
|
onSave?.(mergeDocument.savedValue, currentValue)
|
||||||
mergeDocument.markSaved(currentValue)
|
mergeDocument.markSaved(currentValue)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -640,7 +632,7 @@ const ProfileItemBase = (props: ProfileItemProps) => {
|
|||||||
await scriptDocument.reload()
|
await scriptDocument.reload()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
onSave?.(id, scriptDocument.savedValue, currentValue)
|
onSave?.(scriptDocument.savedValue, currentValue)
|
||||||
scriptDocument.markSaved(currentValue)
|
scriptDocument.markSaved(currentValue)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -654,7 +646,7 @@ const ProfileItemBase = (props: ProfileItemProps) => {
|
|||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
onSelect(id, false)
|
onSelect(false)
|
||||||
}}
|
}}
|
||||||
onContextMenu={(event) => {
|
onContextMenu={(event) => {
|
||||||
const { clientX, clientY } = event
|
const { clientX, clientY } = event
|
||||||
@@ -695,7 +687,7 @@ const ProfileItemBase = (props: ProfileItemProps) => {
|
|||||||
onClick={(e) => {
|
onClick={(e) => {
|
||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
if (onSelectionChange) {
|
if (onSelectionChange) {
|
||||||
onSelectionChange(id)
|
onSelectionChange()
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
@@ -861,7 +853,7 @@ const ProfileItemBase = (props: ProfileItemProps) => {
|
|||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{menuItems.map((item) => (
|
{(hasUrl ? urlModeMenu : fileModeMenu).map((item) => (
|
||||||
<MenuItem
|
<MenuItem
|
||||||
key={item.label}
|
key={item.label}
|
||||||
onClick={item.handler}
|
onClick={item.handler}
|
||||||
@@ -905,7 +897,7 @@ const ProfileItemBase = (props: ProfileItemProps) => {
|
|||||||
profileUid={uid!}
|
profileUid={uid!}
|
||||||
property={option?.rules ?? ''}
|
property={option?.rules ?? ''}
|
||||||
open={true}
|
open={true}
|
||||||
onSave={(prev, curr) => onSave?.(id, prev, curr)}
|
onSave={onSave}
|
||||||
onClose={() => setRulesOpen(false)}
|
onClose={() => setRulesOpen(false)}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
@@ -914,7 +906,7 @@ const ProfileItemBase = (props: ProfileItemProps) => {
|
|||||||
profileUid={uid!}
|
profileUid={uid!}
|
||||||
property={option?.proxies ?? ''}
|
property={option?.proxies ?? ''}
|
||||||
open={true}
|
open={true}
|
||||||
onSave={(prev, curr) => onSave?.(id, prev, curr)}
|
onSave={onSave}
|
||||||
onClose={() => setProxiesOpen(false)}
|
onClose={() => setProxiesOpen(false)}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
@@ -925,7 +917,7 @@ const ProfileItemBase = (props: ProfileItemProps) => {
|
|||||||
profileUid={uid!}
|
profileUid={uid!}
|
||||||
property={option?.groups ?? ''}
|
property={option?.groups ?? ''}
|
||||||
open={true}
|
open={true}
|
||||||
onSave={(prev, curr) => onSave?.(id, prev, curr)}
|
onSave={onSave}
|
||||||
onClose={() => {
|
onClose={() => {
|
||||||
setGroupsOpen(false)
|
setGroupsOpen(false)
|
||||||
}}
|
}}
|
||||||
@@ -971,7 +963,7 @@ const ProfileItemBase = (props: ProfileItemProps) => {
|
|||||||
onCancel={() => setConfirmOpen(false)}
|
onCancel={() => setConfirmOpen(false)}
|
||||||
onClose={() => setConfirmOpen(false)}
|
onClose={() => setConfirmOpen(false)}
|
||||||
onOk={() => {
|
onOk={() => {
|
||||||
onDelete(id)
|
onDelete()
|
||||||
setConfirmOpen(false)
|
setConfirmOpen(false)
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ export const ProxiesEditorViewer = (props: Props) => {
|
|||||||
proxy={item}
|
proxy={item}
|
||||||
onDelete={() => {
|
onDelete={() => {
|
||||||
if (isDeleted) {
|
if (isDeleted) {
|
||||||
setDeleteSeq(deleteSeq.filter((v) => v !== item.name))
|
setDeleteSeq((prev) => prev.filter((v) => v !== item.name))
|
||||||
} else {
|
} else {
|
||||||
setDeleteSeq((prev) => [...prev, item.name])
|
setDeleteSeq((prev) => [...prev, item.name])
|
||||||
}
|
}
|
||||||
@@ -138,7 +138,7 @@ export const ProxiesEditorViewer = (props: Props) => {
|
|||||||
type="prepend"
|
type="prepend"
|
||||||
proxy={item}
|
proxy={item}
|
||||||
onDelete={() => {
|
onDelete={() => {
|
||||||
setPrependSeq(prependSeq.filter((v) => v.name !== item.name))
|
setPrependSeq((prev) => prev.filter((v) => v.name !== item.name))
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
@@ -149,7 +149,7 @@ export const ProxiesEditorViewer = (props: Props) => {
|
|||||||
type="append"
|
type="append"
|
||||||
proxy={item}
|
proxy={item}
|
||||||
onDelete={() => {
|
onDelete={() => {
|
||||||
setAppendSeq(appendSeq.filter((v) => v.name !== item.name))
|
setAppendSeq((prev) => prev.filter((v) => v.name !== item.name))
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
@@ -160,27 +160,28 @@ export const ProxiesEditorViewer = (props: Props) => {
|
|||||||
activeIndex: number,
|
activeIndex: number,
|
||||||
overIndex: number,
|
overIndex: number,
|
||||||
) => {
|
) => {
|
||||||
const list = category === 'prepend' ? prependSeq : appendSeq
|
|
||||||
const filtered =
|
|
||||||
category === 'prepend' ? filteredPrependSeq : filteredAppendSeq
|
|
||||||
const setList = category === 'prepend' ? setPrependSeq : setAppendSeq
|
const setList = category === 'prepend' ? setPrependSeq : setAppendSeq
|
||||||
const activeRealIndex = findRealIndex(list, filtered, activeIndex)
|
// Recompute inside the updater: two writes in one batch must not read the same pre-batch array.
|
||||||
const overRealIndex = findRealIndex(list, filtered, overIndex)
|
setList((prev) => {
|
||||||
if (
|
const filtered = prev.filter((v) => hasValidName(v) && match(v.name))
|
||||||
activeRealIndex < 0 ||
|
const activeRealIndex = findRealIndex(prev, filtered, activeIndex)
|
||||||
overRealIndex < 0 ||
|
const overRealIndex = findRealIndex(prev, filtered, overIndex)
|
||||||
activeRealIndex === overRealIndex
|
if (
|
||||||
) {
|
activeRealIndex < 0 ||
|
||||||
return
|
overRealIndex < 0 ||
|
||||||
}
|
activeRealIndex === overRealIndex
|
||||||
|
) {
|
||||||
|
return prev
|
||||||
|
}
|
||||||
|
|
||||||
setList(arrayMove(list, activeRealIndex, overRealIndex))
|
return arrayMove(prev, activeRealIndex, overRealIndex)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 优化:异步分片解析,避免主线程阻塞,解析完成后批量setState
|
// 优化:异步分片解析,避免主线程阻塞,解析完成后批量setState
|
||||||
const handleParseAsync = (cb: (proxies: IProxyConfig[]) => void) => {
|
const handleParseAsync = (cb: (proxies: IProxyConfig[]) => void) => {
|
||||||
const proxies: IProxyConfig[] = []
|
const proxies: IProxyConfig[] = []
|
||||||
const names = new Set<string>()
|
const names: string[] = []
|
||||||
let uris: string
|
let uris: string
|
||||||
try {
|
try {
|
||||||
uris = atob(proxyUri)
|
uris = atob(proxyUri)
|
||||||
@@ -198,9 +199,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.has(proxy.name)) {
|
if (!names.includes(proxy.name)) {
|
||||||
proxies.push(proxy)
|
proxies.push(proxy)
|
||||||
names.add(proxy.name)
|
names.push(proxy.name)
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.warn(
|
console.warn(
|
||||||
|
|||||||
@@ -318,7 +318,7 @@ export const RulesEditorViewer = (props: Props) => {
|
|||||||
ruleRaw={item}
|
ruleRaw={item}
|
||||||
onDelete={() => {
|
onDelete={() => {
|
||||||
if (isDeleted) {
|
if (isDeleted) {
|
||||||
setDeleteSeq(deleteSeq.filter((v) => v !== item))
|
setDeleteSeq((prev) => prev.filter((v) => v !== item))
|
||||||
} else {
|
} else {
|
||||||
setDeleteSeq((prev) => [...prev, item])
|
setDeleteSeq((prev) => [...prev, item])
|
||||||
}
|
}
|
||||||
@@ -333,13 +333,13 @@ export const RulesEditorViewer = (props: Props) => {
|
|||||||
type="prepend"
|
type="prepend"
|
||||||
ruleRaw={item}
|
ruleRaw={item}
|
||||||
onDelete={() => {
|
onDelete={() => {
|
||||||
setPrependSeq(prependSeq.filter((v) => v !== item))
|
setPrependSeq((prev) => prev.filter((v) => v !== item))
|
||||||
}}
|
}}
|
||||||
onAppend={() => {
|
onAppend={() => {
|
||||||
setAppendSeq((prev) =>
|
setAppendSeq((prev) =>
|
||||||
prev.includes(item) ? prev : [...prev, item],
|
prev.includes(item) ? prev : [...prev, item],
|
||||||
)
|
)
|
||||||
setPrependSeq(prependSeq.filter((v) => v !== item))
|
setPrependSeq((prev) => prev.filter((v) => v !== item))
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
@@ -350,13 +350,13 @@ export const RulesEditorViewer = (props: Props) => {
|
|||||||
type="append"
|
type="append"
|
||||||
ruleRaw={item}
|
ruleRaw={item}
|
||||||
onDelete={() => {
|
onDelete={() => {
|
||||||
setAppendSeq(appendSeq.filter((v) => v !== item))
|
setAppendSeq((prev) => prev.filter((v) => v !== item))
|
||||||
}}
|
}}
|
||||||
onPrepend={() => {
|
onPrepend={() => {
|
||||||
setPrependSeq((prev) =>
|
setPrependSeq((prev) =>
|
||||||
prev.includes(item) ? prev : [...prev, item],
|
prev.includes(item) ? prev : [...prev, item],
|
||||||
)
|
)
|
||||||
setAppendSeq(appendSeq.filter((v) => v !== item))
|
setAppendSeq((prev) => prev.filter((v) => v !== item))
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
@@ -367,21 +367,22 @@ export const RulesEditorViewer = (props: Props) => {
|
|||||||
activeIndex: number,
|
activeIndex: number,
|
||||||
overIndex: number,
|
overIndex: number,
|
||||||
) => {
|
) => {
|
||||||
const list = category === 'prepend' ? prependSeq : appendSeq
|
|
||||||
const filtered =
|
|
||||||
category === 'prepend' ? filteredPrependSeq : filteredAppendSeq
|
|
||||||
const setList = category === 'prepend' ? setPrependSeq : setAppendSeq
|
const setList = category === 'prepend' ? setPrependSeq : setAppendSeq
|
||||||
const activeRealIndex = findRealIndex(list, filtered, activeIndex)
|
// Recompute inside the updater: two writes in one batch must not read the same pre-batch array.
|
||||||
const overRealIndex = findRealIndex(list, filtered, overIndex)
|
setList((prev) => {
|
||||||
if (
|
const filtered = prev.filter(match)
|
||||||
activeRealIndex < 0 ||
|
const activeRealIndex = findRealIndex(prev, filtered, activeIndex)
|
||||||
overRealIndex < 0 ||
|
const overRealIndex = findRealIndex(prev, filtered, overIndex)
|
||||||
activeRealIndex === overRealIndex
|
if (
|
||||||
) {
|
activeRealIndex < 0 ||
|
||||||
return
|
overRealIndex < 0 ||
|
||||||
}
|
activeRealIndex === overRealIndex
|
||||||
|
) {
|
||||||
|
return prev
|
||||||
|
}
|
||||||
|
|
||||||
setList(arrayMove(list, activeRealIndex, overRealIndex))
|
return arrayMove(prev, activeRealIndex, overRealIndex)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const fetchContent = useCallback(async () => {
|
const fetchContent = useCallback(async () => {
|
||||||
@@ -748,8 +749,9 @@ export const RulesEditorViewer = (props: Props) => {
|
|||||||
onClick={() => {
|
onClick={() => {
|
||||||
try {
|
try {
|
||||||
const raw = validateRule()
|
const raw = validateRule()
|
||||||
if (prependSeq.includes(raw)) return
|
setPrependSeq((prev) =>
|
||||||
setPrependSeq([raw, ...prependSeq])
|
prev.includes(raw) ? prev : [raw, ...prev],
|
||||||
|
)
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
showNotice.error(err)
|
showNotice.error(err)
|
||||||
}
|
}
|
||||||
@@ -766,8 +768,9 @@ export const RulesEditorViewer = (props: Props) => {
|
|||||||
onClick={() => {
|
onClick={() => {
|
||||||
try {
|
try {
|
||||||
const raw = validateRule()
|
const raw = validateRule()
|
||||||
if (appendSeq.includes(raw)) return
|
setAppendSeq((prev) =>
|
||||||
setAppendSeq([...appendSeq, raw])
|
prev.includes(raw) ? prev : [...prev, raw],
|
||||||
|
)
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
showNotice.error(err)
|
showNotice.error(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ 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'
|
||||||
@@ -21,47 +20,22 @@ export const rebindProxyChainItems = (
|
|||||||
items: readonly ProxyChainItem[],
|
items: readonly ProxyChainItem[],
|
||||||
candidates: readonly ProxyNodeView[],
|
candidates: readonly ProxyNodeView[],
|
||||||
proxyView: ProxyViewV1,
|
proxyView: ProxyViewV1,
|
||||||
): ProxyChainItem[] => {
|
): ProxyChainItem[] =>
|
||||||
// The proxy view refreshes on a fixed cadence; reusing item and array
|
items.map((item) => {
|
||||||
// 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)
|
||||||
const source = rebound?.source ?? item.source
|
return {
|
||||||
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,
|
source: rebound?.source ?? item.source,
|
||||||
type,
|
type: rebound?.type ?? item.type,
|
||||||
delay,
|
delay: record?.history.at(-1)?.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: (groupName: string) => void
|
onLocation: () => void
|
||||||
onCheckDelay: (groupName: string) => void
|
onCheckDelay: () => void
|
||||||
onHeadState: (groupName: string, val: Partial<HeadState>) => void
|
onHeadState: (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(groupName, {
|
onHeadState({
|
||||||
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(groupName, { testUrl: e.target.value })}
|
onChange={(e) => onHeadState({ 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(groupName, { open: true }))
|
flushSync(() => onHeadState({ open: true }))
|
||||||
onLocation(groupName)
|
onLocation()
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<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(groupName, { open: true }))
|
flushSync(() => onHeadState({ 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(groupName, { textState: 'url' })
|
onHeadState({ 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(groupName)
|
onCheckDelay()
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<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(groupName, { open: true }))
|
flushSync(() => onHeadState({ open: true }))
|
||||||
onHeadState(groupName, {
|
onHeadState({
|
||||||
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(groupName, {
|
onHeadState({
|
||||||
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(groupName, { open: true }))
|
flushSync(() => onHeadState({ open: true }))
|
||||||
onHeadState(groupName, { showType: !showType })
|
onHeadState({ showType: !showType })
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{showType ? (
|
{showType ? (
|
||||||
@@ -265,10 +265,8 @@ 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(groupName, { open: true }))
|
flushSync(() => onHeadState({ open: true }))
|
||||||
onHeadState(groupName, {
|
onHeadState({ textState: textState === 'filter' ? null : 'filter' })
|
||||||
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: (groupName: string) => void
|
onLocation: (group: any) => 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: (groupName: string) => void
|
onLocation: (group: any) => 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,20 +324,16 @@ function ChainProxyGroups(props: {
|
|||||||
scrollTopRef.current = 0
|
scrollTopRef.current = 0
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
const handleLocation = useStableCallback((groupName: string) => {
|
const handleLocation = useStableCallback((group: ProxyGroupView) => {
|
||||||
// Flat (type 1) headers such as GLOBAL carry the same live group.
|
if (!group) return
|
||||||
const headerIndex = renderList.findIndex(
|
const { name, now } = group
|
||||||
(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) =>
|
(item) =>
|
||||||
e.group?.name === groupName &&
|
item.group?.name === name &&
|
||||||
((e.type === 2 && e.member?.member.ref.name === now) ||
|
((item.type === 2 && item.member?.member.ref.name === now) ||
|
||||||
(e.type === 4 &&
|
(item.type === 4 &&
|
||||||
e.memberCol?.some(({ member }) => member.ref.name === now))),
|
item.memberCol?.some(({ member }) => member.ref.name === now))),
|
||||||
)
|
)
|
||||||
|
|
||||||
if (index >= 0) {
|
if (index >= 0) {
|
||||||
@@ -500,17 +496,13 @@ function NormalProxyGroups(props: { mode: string }) {
|
|||||||
[globalGroupName, select, setHeadState],
|
[globalGroupName, select, setHeadState],
|
||||||
)
|
)
|
||||||
|
|
||||||
const handleLocation = useStableCallback((groupName: string) => {
|
const handleLocation = useStableCallback((group: ProxyGroupView) => {
|
||||||
// Flat (type 1) headers such as GLOBAL carry the same live group.
|
if (!group) return
|
||||||
const headerIndex = renderList.findIndex(
|
const { name, now } = group
|
||||||
(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 === groupName &&
|
e.group?.name === name &&
|
||||||
((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))),
|
||||||
@@ -524,20 +516,21 @@ function NormalProxyGroups(props: { mode: string }) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// Stable identity: this feeds the sticky-header render callback; a
|
const handleGroupLocationByName = useCallback(
|
||||||
// [renderList] dep would re-create it on every list rebuild.
|
(groupName: string) => {
|
||||||
const handleGroupLocationByName = useStableCallback((groupName: string) => {
|
const index = renderList.findIndex(
|
||||||
const index = renderList.findIndex(
|
(item) => item.type === 0 && item.group?.name === groupName,
|
||||||
(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: (groupName: string) => void
|
onLocation: () => void
|
||||||
onCheckDelay: (groupName: string) => void
|
onCheckDelay: () => void
|
||||||
onHeadState: (groupName: string, val: Partial<HeadState>) => void
|
onHeadState: (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(groupName)}
|
onClick={onLocation}
|
||||||
>
|
>
|
||||||
<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(groupName, { textState: 'url' })
|
onHeadState({ 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(groupName)
|
onCheckDelay()
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<NetworkCheckRounded />
|
<NetworkCheckRounded />
|
||||||
@@ -118,9 +118,7 @@ export const ProxyHead = ({
|
|||||||
][sortType]
|
][sortType]
|
||||||
}
|
}
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
onHeadState(groupName, {
|
onHeadState({ sortType: ((sortType + 1) % 3) as ProxySortType })
|
||||||
sortType: ((sortType + 1) % 3) as ProxySortType,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
{sortType !== 1 && sortType !== 2 && <SortRounded />}
|
{sortType !== 1 && sortType !== 2 && <SortRounded />}
|
||||||
@@ -133,9 +131,7 @@ export const ProxyHead = ({
|
|||||||
color="inherit"
|
color="inherit"
|
||||||
title={t('proxies.page.tooltips.delayCheckUrl')}
|
title={t('proxies.page.tooltips.delayCheckUrl')}
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
onHeadState(groupName, {
|
onHeadState({ textState: textState === 'url' ? null : 'url' })
|
||||||
textState: textState === 'url' ? null : 'url',
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
{textState === 'url' ? (
|
{textState === 'url' ? (
|
||||||
@@ -153,7 +149,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(groupName, { showType: !showType })}
|
onClick={() => onHeadState({ showType: !showType })}
|
||||||
>
|
>
|
||||||
{showType ? <VisibilityRounded /> : <VisibilityOffRounded />}
|
{showType ? <VisibilityRounded /> : <VisibilityOffRounded />}
|
||||||
</IconButton>
|
</IconButton>
|
||||||
@@ -163,9 +159,7 @@ export const ProxyHead = ({
|
|||||||
color="inherit"
|
color="inherit"
|
||||||
title={t('proxies.page.tooltips.filter')}
|
title={t('proxies.page.tooltips.filter')}
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
onHeadState(groupName, {
|
onHeadState({ textState: textState === 'filter' ? null : 'filter' })
|
||||||
textState: textState === 'filter' ? null : 'filter',
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
{textState === 'filter' ? <SearchOffRounded /> : <SearchRounded />}
|
{textState === 'filter' ? <SearchOffRounded /> : <SearchRounded />}
|
||||||
@@ -182,7 +176,7 @@ export const ProxyHead = ({
|
|||||||
useRegularExpression: filterUseRegularExpression,
|
useRegularExpression: filterUseRegularExpression,
|
||||||
}}
|
}}
|
||||||
onSearch={(_, state) =>
|
onSearch={(_, state) =>
|
||||||
onHeadState(groupName, {
|
onHeadState({
|
||||||
filterText: state.text,
|
filterText: state.text,
|
||||||
filterMatchCase: state.matchCase,
|
filterMatchCase: state.matchCase,
|
||||||
filterMatchWholeWord: state.matchWholeWord,
|
filterMatchWholeWord: state.matchWholeWord,
|
||||||
@@ -203,7 +197,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(groupName, { testUrl: e.target.value })}
|
onChange={(e) => onHeadState({ 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: (groupName: string) => void
|
onLocation: (group: IRenderItem['group']) => 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}
|
onLocation={() => onLocation(group)}
|
||||||
onCheckDelay={onCheckAll}
|
onCheckDelay={() => onCheckAll(group.name)}
|
||||||
onHeadState={onHeadState}
|
onHeadState={(p) => onHeadState(group.name, p)}
|
||||||
/>
|
/>
|
||||||
{!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}
|
onLocation={() => onLocation(group)}
|
||||||
onCheckDelay={onCheckAll}
|
onCheckDelay={() => onCheckAll(group.name)}
|
||||||
onHeadState={onHeadState}
|
onHeadState={(p) => onHeadState(group.name, p)}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -175,19 +175,15 @@ 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 = useMemo(
|
const chainDelayKey = chainOccurrences
|
||||||
() =>
|
.map(({ member }) => {
|
||||||
chainOccurrences
|
if (member.kind !== 'node') return `${member.kind}:${member.ref.name}`
|
||||||
.map(({ member }) => {
|
const source = member.node.source
|
||||||
if (member.kind !== 'node') return `${member.kind}:${member.ref.name}`
|
return source.kind === 'provider'
|
||||||
const source = member.node.source
|
? `provider:${source.providerName}:${source.proxyName}`
|
||||||
return source.kind === 'provider'
|
: `core:${source.proxyName}`
|
||||||
? `provider:${source.providerName}:${source.proxyName}`
|
})
|
||||||
: `core:${source.proxyName}`
|
.join('\u0000')
|
||||||
})
|
|
||||||
.join('\u0000'),
|
|
||||||
[chainOccurrences],
|
|
||||||
)
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!isChainMode || !chainDelayKey) return
|
if (!isChainMode || !chainDelayKey) return
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import {
|
|||||||
Tooltip,
|
Tooltip,
|
||||||
} from '@mui/material'
|
} from '@mui/material'
|
||||||
import { useLockFn } from 'ahooks'
|
import { useLockFn } from 'ahooks'
|
||||||
import { useState, type Ref } from 'react'
|
import { useRef, useState, type Ref } from 'react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
|
|
||||||
import { BaseDialog, DialogRef, Switch } from '@/components/base'
|
import { BaseDialog, DialogRef, Switch } from '@/components/base'
|
||||||
@@ -26,6 +26,10 @@ export function ControllerViewer({ ref }: { ref?: Ref<DialogRef> }) {
|
|||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const [open, setOpen] = useState(false)
|
const [open, setOpen] = useState(false)
|
||||||
const [copySuccess, setCopySuccess] = useState<null | string>(null)
|
const [copySuccess, setCopySuccess] = useState<null | string>(null)
|
||||||
|
// A second copy within the window must not be hidden by the first timer.
|
||||||
|
const copySuccessTimerRef = useRef<ReturnType<typeof setTimeout> | undefined>(
|
||||||
|
undefined,
|
||||||
|
)
|
||||||
const [isSaving, setIsSaving] = useState(false)
|
const [isSaving, setIsSaving] = useState(false)
|
||||||
|
|
||||||
const { clashInfo, patchInfo } = useClashInfo()
|
const { clashInfo, patchInfo } = useClashInfo()
|
||||||
@@ -96,7 +100,11 @@ export function ControllerViewer({ ref }: { ref?: Ref<DialogRef> }) {
|
|||||||
try {
|
try {
|
||||||
await navigator.clipboard.writeText(text)
|
await navigator.clipboard.writeText(text)
|
||||||
setCopySuccess(type)
|
setCopySuccess(type)
|
||||||
setTimeout(() => setCopySuccess(null))
|
clearTimeout(copySuccessTimerRef.current)
|
||||||
|
copySuccessTimerRef.current = setTimeout(
|
||||||
|
() => setCopySuccess(null),
|
||||||
|
2000,
|
||||||
|
)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.warn('[ControllerViewer] copy to clipboard failed:', err)
|
console.warn('[ControllerViewer] copy to clipboard failed:', err)
|
||||||
showNotice.error(
|
showNotice.error(
|
||||||
|
|||||||
@@ -51,25 +51,6 @@ 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 {
|
||||||
@@ -539,21 +520,9 @@ export function DnsViewer({ ref }: { ref?: Ref<DialogRef> }) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const handleYamlChange = useCallback((value?: string) => {
|
const handleYamlChange = (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 =
|
||||||
@@ -1083,8 +1052,27 @@ 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={handleEditorMount}
|
onMount={(editorInstance) => {
|
||||||
options={MONACO_OPTIONS}
|
editorRef.current = editorInstance
|
||||||
|
}}
|
||||||
|
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}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import { convertFileSrc } from '@tauri-apps/api/core'
|
|||||||
import { join } from '@tauri-apps/api/path'
|
import { join } from '@tauri-apps/api/path'
|
||||||
import { open as openDialog } from '@tauri-apps/plugin-dialog'
|
import { open as openDialog } from '@tauri-apps/plugin-dialog'
|
||||||
import { exists } from '@tauri-apps/plugin-fs'
|
import { exists } from '@tauri-apps/plugin-fs'
|
||||||
import { forwardRef, useEffect, useState } from 'react'
|
import { forwardRef, useEffect, useRef, useState } from 'react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
|
|
||||||
import { BaseDialog, DialogRef, Switch, TooltipIcon } from '@/components/base'
|
import { BaseDialog, DialogRef, Switch, TooltipIcon } from '@/components/base'
|
||||||
@@ -62,9 +62,16 @@ export const LayoutViewer = forwardRef<DialogRef>((_, ref) => {
|
|||||||
|
|
||||||
const { decorated, toggleDecorations } = useWindowDecorations()
|
const { decorated, toggleDecorations } = useWindowDecorations()
|
||||||
|
|
||||||
|
// Icon paths are only reachable from the open dialog; both settings sections
|
||||||
|
// mount this viewer, so an eager read would double ~11 IPC calls per visit.
|
||||||
|
// Loaded once per mount, deferred to the first open.
|
||||||
|
const iconsLoadedRef = useRef(false)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if (!open || iconsLoadedRef.current) return
|
||||||
|
iconsLoadedRef.current = true
|
||||||
initIconPath()
|
initIconPath()
|
||||||
}, [])
|
}, [open])
|
||||||
|
|
||||||
async function initIconPath() {
|
async function initIconPath() {
|
||||||
const appDir = await getAppDir()
|
const appDir = await getAppDir()
|
||||||
@@ -109,7 +116,7 @@ export const LayoutViewer = forwardRef<DialogRef>((_, ref) => {
|
|||||||
showNotice.error(err)
|
showNotice.error(err)
|
||||||
}
|
}
|
||||||
const onChangeData = (patch: Partial<IVergeConfig>) => {
|
const onChangeData = (patch: Partial<IVergeConfig>) => {
|
||||||
mutateVerge((prev) => ({ ...prev, ...patch }))
|
mutateVerge({ ...verge, ...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((prev) => ({ ...prev, ...patch }))
|
mutateVerge({ ...verge, ...patch })
|
||||||
}
|
}
|
||||||
if (Object.keys(patch).length > 0) {
|
if (Object.keys(patch).length > 0) {
|
||||||
await patchVerge(patch)
|
await patchVerge(patch)
|
||||||
|
|||||||
@@ -114,84 +114,6 @@ 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 ?? []) {
|
||||||
@@ -263,6 +185,10 @@ 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)
|
||||||
@@ -286,8 +212,8 @@ export function UpdateViewer({ ref }: { ref?: Ref<DialogRef> }) {
|
|||||||
) as Record<GitHubAlertType, string>,
|
) as Record<GitHubAlertType, string>,
|
||||||
[t],
|
[t],
|
||||||
)
|
)
|
||||||
const remarkPlugins = useMemo(
|
const remarkGitHubAlertsPlugin = useMemo(
|
||||||
() => [() => remarkGitHubAlerts(githubAlertLabels)],
|
() => () => remarkGitHubAlerts(githubAlertLabels),
|
||||||
[githubAlertLabels],
|
[githubAlertLabels],
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -549,8 +475,83 @@ export function UpdateViewer({ ref }: { ref?: Ref<DialogRef> }) {
|
|||||||
{open && (
|
{open && (
|
||||||
<Suspense fallback={<LinearProgress />}>
|
<Suspense fallback={<LinearProgress />}>
|
||||||
<LazyReactMarkdown
|
<LazyReactMarkdown
|
||||||
remarkPlugins={remarkPlugins}
|
remarkPlugins={[remarkGitHubAlertsPlugin]}
|
||||||
components={MARKDOWN_COMPONENTS}
|
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((prev) => ({ ...prev, ...patch }))
|
mutateVerge({ ...verge, ...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((prev) => ({ ...prev, ...patch }))
|
mutateVerge({ ...verge, ...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, useMemo, useRef, useState, type ReactNode } from 'react'
|
import { useEffect, 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,9 +21,6 @@ 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,
|
||||||
}: {
|
}: {
|
||||||
@@ -43,17 +40,11 @@ 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>(() => {})
|
||||||
// The catalog scan touches every entry with translations; memoizing keeps
|
const results = searchSettings(
|
||||||
// unrelated state (arrow-key selection) from re-running it.
|
query,
|
||||||
const results = useMemo(
|
getSystem(),
|
||||||
() =>
|
(key) => t(key),
|
||||||
searchSettings(
|
(key) => t(key, { lng: 'en' }),
|
||||||
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((prev) => ({ ...prev, enable_tun_mode: value }))
|
mutateVerge({ ...verge, enable_tun_mode: value })
|
||||||
await patchVerge({ enable_tun_mode: value })
|
await patchVerge({ enable_tun_mode: value })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,9 +12,6 @@ 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'],
|
||||||
@@ -58,7 +55,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: EMPTY_LOGS,
|
fallbackData: [],
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -48,10 +48,14 @@ export const useSystemProxyState = () => {
|
|||||||
// Coalesce rapid clicks so only the latest requested state is applied.
|
// Coalesce rapid clicks so only the latest requested state is applied.
|
||||||
const pendingRef = useRef<boolean | null>(null)
|
const pendingRef = useRef<boolean | null>(null)
|
||||||
const busyRef = useRef(false)
|
const busyRef = useRef(false)
|
||||||
|
// The drain loop outlives the render it started in; reading the config
|
||||||
|
// through a ref keeps mid-loop revalidations visible to later iterations.
|
||||||
|
const vergeRef = useRef(verge)
|
||||||
|
vergeRef.current = verge
|
||||||
|
|
||||||
const toggleSystemProxy = async (enabled: boolean) => {
|
const toggleSystemProxy = async (enabled: boolean) => {
|
||||||
// Roll failed optimistic writes back to the latest confirmed state.
|
// Roll failed optimistic writes back to the latest confirmed state.
|
||||||
let confirmed = verge?.enable_system_proxy ?? false
|
let confirmed = vergeRef.current?.enable_system_proxy ?? false
|
||||||
mutateVerge((prev) =>
|
mutateVerge((prev) =>
|
||||||
prev ? { ...prev, enable_system_proxy: enabled } : prev,
|
prev ? { ...prev, enable_system_proxy: enabled } : prev,
|
||||||
)
|
)
|
||||||
@@ -69,7 +73,7 @@ export const useSystemProxyState = () => {
|
|||||||
errorNotice: false,
|
errorNotice: false,
|
||||||
})
|
})
|
||||||
confirmed = target
|
confirmed = target
|
||||||
if (!target && verge?.auto_close_connection) {
|
if (!target && vergeRef.current?.auto_close_connection) {
|
||||||
await mutate(() => closeAllConnections(), {
|
await mutate(() => closeAllConnections(), {
|
||||||
id: 'close-all-connections',
|
id: 'close-all-connections',
|
||||||
errorNotice: false,
|
errorNotice: false,
|
||||||
|
|||||||
+19
-25
@@ -3,16 +3,12 @@ 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 {
|
import { setCacheData, useQuery } from '@/services/query-client'
|
||||||
revalidateQuery,
|
|
||||||
setCacheData,
|
|
||||||
useQuery,
|
|
||||||
} from '@/services/query-client'
|
|
||||||
|
|
||||||
export const useVerge = () => {
|
export const useVerge = () => {
|
||||||
const initialVergeConfig = getPreloadConfig()
|
const initialVergeConfig = getPreloadConfig()
|
||||||
|
|
||||||
const { data: verge } = useQuery({
|
const { data: verge, refetch } = useQuery({
|
||||||
queryKey: ['getVergeConfig'],
|
queryKey: ['getVergeConfig'],
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
const config = await getVergeConfig()
|
const config = await getVergeConfig()
|
||||||
@@ -24,25 +20,23 @@ export const useVerge = () => {
|
|||||||
staleTime: 5000,
|
staleTime: 5000,
|
||||||
})
|
})
|
||||||
|
|
||||||
// Stable identity: many consumers list mutateVerge in their own callback
|
const mutateVerge = (
|
||||||
// deps, so a per-render closure here would churn their memoization too.
|
updaterOrData?:
|
||||||
// The updater receives the live cache value (preload snapshot when the
|
| IVergeConfig
|
||||||
// cache is still empty) instead of a render-time snapshot, so an older
|
| ((prev: IVergeConfig | undefined) => IVergeConfig | undefined)
|
||||||
// render cannot clobber a newer cache write.
|
| undefined,
|
||||||
const mutateVerge = useCallback(
|
) => {
|
||||||
(
|
if (updaterOrData === undefined) {
|
||||||
updater?: (prev: IVergeConfig | undefined) => IVergeConfig | undefined,
|
void refetch()
|
||||||
) => {
|
return
|
||||||
if (updater === undefined) {
|
}
|
||||||
void revalidateQuery(['getVergeConfig'])
|
void setCacheData<IVergeConfig>(
|
||||||
return
|
['getVergeConfig'],
|
||||||
}
|
typeof updaterOrData === 'function'
|
||||||
void setCacheData<IVergeConfig>(['getVergeConfig'], (current) =>
|
? (current) => updaterOrData(current ?? verge)
|
||||||
updater(current ?? getPreloadConfig() ?? undefined),
|
: updaterOrData,
|
||||||
)
|
)
|
||||||
},
|
}
|
||||||
[],
|
|
||||||
)
|
|
||||||
|
|
||||||
// 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.
|
||||||
|
|||||||
+20
-46
@@ -462,12 +462,9 @@ const ProfilePage = () => {
|
|||||||
[runProfileSwitchQueue],
|
[runProfileSwitchQueue],
|
||||||
)
|
)
|
||||||
|
|
||||||
const onSelect = useCallback(
|
const onSelect = async (profile: string, force: boolean) => {
|
||||||
async (profile: string, force: boolean) => {
|
await activateProfile(profile, true, force)
|
||||||
await activateProfile(profile, true, force)
|
}
|
||||||
},
|
|
||||||
[activateProfile],
|
|
||||||
)
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let cancelled = false
|
let cancelled = false
|
||||||
@@ -597,7 +594,7 @@ const ProfilePage = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const toggleProfileSelection = useCallback((uid: string) => {
|
const toggleProfileSelection = (uid: string) => {
|
||||||
setSelectedProfiles((prev) => {
|
setSelectedProfiles((prev) => {
|
||||||
const newSet = new Set(prev)
|
const newSet = new Set(prev)
|
||||||
if (newSet.has(uid)) {
|
if (newSet.has(uid)) {
|
||||||
@@ -607,40 +604,7 @@ 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!)))
|
||||||
@@ -944,13 +908,23 @@ const ProfilePage = () => {
|
|||||||
completedUpdateRevisions.get(item.uid!) ?? 0
|
completedUpdateRevisions.get(item.uid!) ?? 0
|
||||||
}
|
}
|
||||||
mutateProfiles={mutateProfiles}
|
mutateProfiles={mutateProfiles}
|
||||||
onSelect={onSelect}
|
onSelect={(f) => onSelect(item.uid!, f)}
|
||||||
onEdit={handleItemEdit}
|
onEdit={() => viewerRef.current?.edit(item)}
|
||||||
onSave={handleItemSave}
|
onSave={async (prev, curr) => {
|
||||||
onDelete={handleItemDelete}
|
if (prev !== curr && profiles.current === item.uid) {
|
||||||
|
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}
|
onSelectionChange={() => toggleProfileSelection(item.uid!)}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</Box>
|
</Box>
|
||||||
|
|||||||
@@ -237,9 +237,7 @@ class DelayManager {
|
|||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
// Entries are replaced, never mutated, so the cached object is shared
|
return { ...entry }
|
||||||
// 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 = (
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export const sameSource = (
|
const sameSource = (
|
||||||
left: ProxyNodeView['source'],
|
left: ProxyNodeView['source'],
|
||||||
right: ProxyNodeView['source'],
|
right: ProxyNodeView['source'],
|
||||||
) =>
|
) =>
|
||||||
|
|||||||
@@ -124,10 +124,10 @@ export class TrafficDataSampler {
|
|||||||
) {
|
) {
|
||||||
rawStart++
|
rawStart++
|
||||||
}
|
}
|
||||||
const rawCount = this.rawBuffer.length - rawStart
|
const rawData = this.rawBuffer.slice(rawStart)
|
||||||
|
|
||||||
if (minutes <= this.config.rawDataMinutes) {
|
if (minutes <= this.config.rawDataMinutes) {
|
||||||
return this.rawBuffer.slice(rawStart)
|
return rawData
|
||||||
}
|
}
|
||||||
|
|
||||||
const compressedCutoffUpper =
|
const compressedCutoffUpper =
|
||||||
@@ -140,40 +140,19 @@ export class TrafficDataSampler {
|
|||||||
) {
|
) {
|
||||||
compressedStart++
|
compressedStart++
|
||||||
}
|
}
|
||||||
let compressedEnd = compressedStart
|
|
||||||
while (
|
|
||||||
compressedEnd < this.compressedBuffer.length &&
|
|
||||||
this.compressedBuffer[compressedEnd].timestamp <= compressedCutoffUpper
|
|
||||||
) {
|
|
||||||
compressedEnd++
|
|
||||||
}
|
|
||||||
|
|
||||||
// Single preallocated result; raw entries keep their stored identity.
|
const compressedData = this.compressedBuffer
|
||||||
const compressedCount = compressedEnd - compressedStart
|
.slice(compressedStart)
|
||||||
const result: ITrafficDataPoint[] = new Array(compressedCount + rawCount)
|
.filter((p) => p.timestamp <= compressedCutoffUpper)
|
||||||
for (let i = 0; i < compressedCount; i++) {
|
.map((p) => ({
|
||||||
const point = this.compressedBuffer[compressedStart + i]
|
up: p.up,
|
||||||
result[i] = {
|
down: p.down,
|
||||||
up: point.up,
|
timestamp: p.timestamp,
|
||||||
down: point.down,
|
}))
|
||||||
timestamp: point.timestamp,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (let i = 0; i < rawCount; i++) {
|
|
||||||
result[compressedCount + i] = this.rawBuffer[rawStart + i]
|
|
||||||
}
|
|
||||||
|
|
||||||
// Compressed points precede raw ones except across the trim boundary;
|
return [...compressedData, ...rawData].sort(
|
||||||
// sort only when the two ranges actually interleave.
|
(a, b) => a.timestamp - b.timestamp,
|
||||||
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