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 |
@@ -28,6 +28,8 @@
|
|||||||
<details>
|
<details>
|
||||||
<summary><strong> 🐞 修复问题 </strong></summary>
|
<summary><strong> 🐞 修复问题 </strong></summary>
|
||||||
|
|
||||||
|
- 修复「外部控制器」复制成功的提示一闪而过
|
||||||
|
- 修复订阅的规则、代理组、节点编辑器快速连续操作时条目可能重复或错位
|
||||||
- 修复检测更新后又发布新版时,应用内更新失败
|
- 修复检测更新后又发布新版时,应用内更新失败
|
||||||
- 修复订阅响应过大导致内存占用过高,限制单次下载为 4 MiB
|
- 修复订阅响应过大导致内存占用过高,限制单次下载为 4 MiB
|
||||||
- 修复全局模式默认停在 `DIRECT` 或 `REJECT` 导致流量未经代理,现自动切换到第一个策略组
|
- 修复全局模式默认停在 `DIRECT` 或 `REJECT` 导致流量未经代理,现自动切换到第一个策略组
|
||||||
@@ -63,6 +65,7 @@
|
|||||||
<details>
|
<details>
|
||||||
<summary><strong> 🚀 优化改进 </strong></summary>
|
<summary><strong> 🚀 优化改进 </strong></summary>
|
||||||
|
|
||||||
|
- 优化设置页打开时的开销:布局设置弹窗首次打开时才加载图标
|
||||||
- 优化连接、规则和日志筛选:切换页面后保留过滤条件
|
- 优化连接、规则和日志筛选:切换页面后保留过滤条件
|
||||||
- 优化全局模式代理列表:仅显示 `GLOBAL` 节点,选中其中的策略组时才显示该组
|
- 优化全局模式代理列表:仅显示 `GLOBAL` 节点,选中其中的策略组时才显示该组
|
||||||
- 优化设置页开关和选项所在行的鼠标悬停高亮,便于对应说明与控件
|
- 优化设置页开关和选项所在行的鼠标悬停高亮,便于对应说明与控件
|
||||||
|
|||||||
@@ -53,15 +53,6 @@ const StyledTextField = styled(TextField)(({ theme }) => ({
|
|||||||
},
|
},
|
||||||
}))
|
}))
|
||||||
|
|
||||||
const iconStyle = {
|
|
||||||
style: {
|
|
||||||
height: '24px',
|
|
||||||
width: '24px',
|
|
||||||
cursor: 'pointer',
|
|
||||||
} as React.CSSProperties,
|
|
||||||
inheritViewBox: true,
|
|
||||||
}
|
|
||||||
|
|
||||||
const useControllableState = <T,>(options: {
|
const useControllableState = <T,>(options: {
|
||||||
controlled: T | undefined
|
controlled: T | undefined
|
||||||
defaultValue: T
|
defaultValue: T
|
||||||
@@ -128,6 +119,15 @@ export const BaseSearchBox = ({
|
|||||||
defaultValue: defaultUseRegularExpression,
|
defaultValue: defaultUseRegularExpression,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const iconStyle = {
|
||||||
|
style: {
|
||||||
|
height: '24px',
|
||||||
|
width: '24px',
|
||||||
|
cursor: 'pointer',
|
||||||
|
} as React.CSSProperties,
|
||||||
|
inheritViewBox: true,
|
||||||
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
onSearchRef.current = onSearch
|
onSearchRef.current = onSearch
|
||||||
}, [onSearch])
|
}, [onSearch])
|
||||||
|
|||||||
@@ -1,13 +1,6 @@
|
|||||||
import { styled } from '@mui/material/styles'
|
import { styled } from '@mui/material/styles'
|
||||||
import { default as MuiSwitch, SwitchProps } from '@mui/material/Switch'
|
import { default as MuiSwitch, SwitchProps } from '@mui/material/Switch'
|
||||||
|
|
||||||
/**
|
|
||||||
* MUI Switch delivers the boolean as the second onChange argument, so
|
|
||||||
* switch handlers use this adapter to stay boolean-only.
|
|
||||||
*/
|
|
||||||
export const switchChangeValue = (_event: unknown, value: boolean): boolean =>
|
|
||||||
value
|
|
||||||
|
|
||||||
export const Switch = styled((props: SwitchProps) => (
|
export const Switch = styled((props: SwitchProps) => (
|
||||||
<MuiSwitch
|
<MuiSwitch
|
||||||
focusVisibleClassName=".Mui-focusVisible"
|
focusVisibleClassName=".Mui-focusVisible"
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ export { BaseSplitChipEditor } from './base-split-chip-editor'
|
|||||||
export { BaseStyledSelect } from './base-styled-select'
|
export { BaseStyledSelect } from './base-styled-select'
|
||||||
export { BaseStyledTextField } from './base-styled-text-field'
|
export { BaseStyledTextField } from './base-styled-text-field'
|
||||||
export { MonacoEditor } from './monaco-editor'
|
export { MonacoEditor } from './monaco-editor'
|
||||||
export { Switch, switchChangeValue } from './base-switch'
|
export { Switch } from './base-switch'
|
||||||
export { TooltipIcon } from './base-tooltip-icon'
|
export { TooltipIcon } from './base-tooltip-icon'
|
||||||
export { VirtualList, type VirtualListHandle } from './virtual-list'
|
export { VirtualList, type VirtualListHandle } from './virtual-list'
|
||||||
export {
|
export {
|
||||||
|
|||||||
@@ -23,8 +23,6 @@ import { emitTestAll } from '@/services/bus'
|
|||||||
|
|
||||||
import { EnhancedCard } from './enhanced-card'
|
import { EnhancedCard } from './enhanced-card'
|
||||||
|
|
||||||
const TEST_LIST_SENSORS = [PointerSensor]
|
|
||||||
|
|
||||||
// 自定义滚动条样式
|
// 自定义滚动条样式
|
||||||
const ScrollBox = styled(Box)(({ theme }) => ({
|
const ScrollBox = styled(Box)(({ theme }) => ({
|
||||||
maxHeight: '180px',
|
maxHeight: '180px',
|
||||||
@@ -207,7 +205,7 @@ export const TestCard = () => {
|
|||||||
}
|
}
|
||||||
>
|
>
|
||||||
<ScrollBox>
|
<ScrollBox>
|
||||||
<DragDropProvider sensors={TEST_LIST_SENSORS} onDragEnd={onDragEnd}>
|
<DragDropProvider sensors={[PointerSensor]} onDragEnd={onDragEnd}>
|
||||||
{renderTestItems}
|
{renderTestItems}
|
||||||
</DragDropProvider>
|
</DragDropProvider>
|
||||||
</ScrollBox>
|
</ScrollBox>
|
||||||
|
|||||||
@@ -5,8 +5,6 @@ import { type PointerEvent, useCallback } from 'react'
|
|||||||
import { useWindowControls } from '@/hooks/use-window'
|
import { useWindowControls } from '@/hooks/use-window'
|
||||||
import getSystem from '@/utils/get-system'
|
import getSystem from '@/utils/get-system'
|
||||||
|
|
||||||
const OS = getSystem()
|
|
||||||
|
|
||||||
const RESIZE_HANDLES = [
|
const RESIZE_HANDLES = [
|
||||||
{ direction: 'North', position: 'north' },
|
{ direction: 'North', position: 'north' },
|
||||||
{ direction: 'NorthEast', position: 'north-east' },
|
{ direction: 'NorthEast', position: 'north-east' },
|
||||||
@@ -40,7 +38,7 @@ export const WindowResizeHandles = () => {
|
|||||||
[currentWindow],
|
[currentWindow],
|
||||||
)
|
)
|
||||||
|
|
||||||
if (OS !== 'linux' || maximized) return null
|
if (getSystem() !== 'linux' || maximized) return null
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
@@ -61,6 +59,7 @@ export const WindowResizeHandles = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const WindowControls = () => {
|
export const WindowControls = () => {
|
||||||
|
const OS = getSystem()
|
||||||
const { maximized, minimize, close, toggleMaximize } = useWindowControls()
|
const { maximized, minimize, close, toggleMaximize } = useWindowControls()
|
||||||
|
|
||||||
// 通过前端对 tauri 窗口进行翻转全屏时会短暂地与系统图标重叠渲染。
|
// 通过前端对 tauri 窗口进行翻转全屏时会短暂地与系统图标重叠渲染。
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import { Alert, Box, Typography } from '@mui/material'
|
import { Alert, Box, Typography } from '@mui/material'
|
||||||
import { useMemo } from 'react'
|
|
||||||
import { Trans, useTranslation } from 'react-i18next'
|
import { Trans, useTranslation } from 'react-i18next'
|
||||||
|
|
||||||
const stageHints = {
|
const stageHints = {
|
||||||
@@ -15,31 +14,26 @@ interface Props {
|
|||||||
|
|
||||||
export const EnhanceHint = ({ stage }: Props) => {
|
export const EnhanceHint = ({ stage }: Props) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
// The component map identity changes only when the active stage changes.
|
const orderComponents = Object.fromEntries(
|
||||||
const orderComponents = useMemo(
|
Object.keys(stageHints).map((key) => [
|
||||||
() =>
|
key,
|
||||||
Object.fromEntries(
|
<Box
|
||||||
Object.keys(stageHints).map((key) => [
|
key={key}
|
||||||
key,
|
component={key === stage ? 'strong' : 'span'}
|
||||||
<Box
|
sx={
|
||||||
key={key}
|
key === stage
|
||||||
component={key === stage ? 'strong' : 'span'}
|
? {
|
||||||
sx={
|
fontWeight: 'bold',
|
||||||
key === stage
|
color: 'primary.contrastText',
|
||||||
? {
|
bgcolor: 'primary.main',
|
||||||
fontWeight: 'bold',
|
borderRadius: 0.5,
|
||||||
color: 'primary.contrastText',
|
px: 0.5,
|
||||||
bgcolor: 'primary.main',
|
boxDecorationBreak: 'clone',
|
||||||
borderRadius: 0.5,
|
}
|
||||||
px: 0.5,
|
: undefined
|
||||||
boxDecorationBreak: 'clone',
|
}
|
||||||
}
|
/>,
|
||||||
: undefined
|
]),
|
||||||
}
|
|
||||||
/>,
|
|
||||||
]),
|
|
||||||
),
|
|
||||||
[stage],
|
|
||||||
)
|
)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -56,8 +56,6 @@ interface GroupedVirtualListProps<T> {
|
|||||||
style?: CSSProperties
|
style?: CSSProperties
|
||||||
}
|
}
|
||||||
|
|
||||||
const GROUPED_LIST_SENSORS = [PointerSensor, KeyboardSensor]
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用于编辑规则/节点/代理组功能的 prepend/original/append 分组虚拟化列表
|
* 用于编辑规则/节点/代理组功能的 prepend/original/append 分组虚拟化列表
|
||||||
*/
|
*/
|
||||||
@@ -143,7 +141,7 @@ export function GroupedVirtualList<T>(props: GroupedVirtualListProps<T>) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<DragDropProvider
|
<DragDropProvider
|
||||||
sensors={GROUPED_LIST_SENSORS}
|
sensors={[PointerSensor, KeyboardSensor]}
|
||||||
onDragStart={onDragStart}
|
onDragStart={onDragStart}
|
||||||
onDragOver={onDragOver}
|
onDragOver={onDragOver}
|
||||||
onDragEnd={onDragEnd}
|
onDragEnd={onDragEnd}
|
||||||
|
|||||||
@@ -218,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])
|
||||||
}
|
}
|
||||||
@@ -233,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))
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
@@ -244,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))
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
@@ -255,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 () => {
|
||||||
@@ -1019,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)
|
||||||
}
|
}
|
||||||
@@ -1043,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)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -112,12 +112,9 @@ export const ProfileMore = (props: Props) => {
|
|||||||
document.markSaved(currentValue)
|
document.markSaved(currentValue)
|
||||||
})
|
})
|
||||||
|
|
||||||
// document gets a fresh identity every render; setValue is the stable
|
|
||||||
// useState setter, so the callback keys on it instead.
|
|
||||||
const { setValue } = document
|
|
||||||
const handleResetToDefault = useCallback(() => {
|
const handleResetToDefault = useCallback(() => {
|
||||||
setValue(DEFAULT_SCRIPT)
|
document.setValue(DEFAULT_SCRIPT)
|
||||||
}, [setValue])
|
}, [document])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|||||||
@@ -61,26 +61,21 @@ export function ProfileViewer({ onChange, ref }: ProfileViewerProps) {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
// The handle only closes over stable form/state setters.
|
useImperativeHandle(ref, () => ({
|
||||||
useImperativeHandle(
|
create: () => {
|
||||||
ref,
|
setOpenType('new')
|
||||||
() => ({
|
setOpen(true)
|
||||||
create: () => {
|
},
|
||||||
setOpenType('new')
|
edit: (item: IProfileItem) => {
|
||||||
setOpen(true)
|
if (item) {
|
||||||
},
|
Object.entries(item).forEach(([key, value]) => {
|
||||||
edit: (item: IProfileItem) => {
|
setValue(key as any, value)
|
||||||
if (item) {
|
})
|
||||||
Object.entries(item).forEach(([key, value]) => {
|
}
|
||||||
setValue(key as any, value)
|
setOpenType('edit')
|
||||||
})
|
setOpen(true)
|
||||||
}
|
},
|
||||||
setOpenType('edit')
|
}))
|
||||||
setOpen(true)
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
[setValue],
|
|
||||||
)
|
|
||||||
|
|
||||||
const handleOk = useLockFn(
|
const handleOk = useLockFn(
|
||||||
handleSubmit(async (form) => {
|
handleSubmit(async (form) => {
|
||||||
|
|||||||
@@ -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,21 +160,22 @@ 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
|
||||||
|
|||||||
@@ -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)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,8 +57,6 @@ const chainPointerSensor = PointerSensor.configure({
|
|||||||
activationConstraints: () => undefined,
|
activationConstraints: () => undefined,
|
||||||
})
|
})
|
||||||
|
|
||||||
const CHAIN_SENSORS = [chainPointerSensor, KeyboardSensor]
|
|
||||||
|
|
||||||
type RuntimeConfigWithProxySequence = IConfigData & { proxies?: unknown }
|
type RuntimeConfigWithProxySequence = IConfigData & { proxies?: unknown }
|
||||||
|
|
||||||
interface ProxyChainProps {
|
interface ProxyChainProps {
|
||||||
@@ -667,7 +665,10 @@ export const ProxyChain = ({
|
|||||||
</Button>
|
</Button>
|
||||||
</Box>
|
</Box>
|
||||||
) : (
|
) : (
|
||||||
<DragDropProvider sensors={CHAIN_SENSORS} onDragEnd={handleDragEnd}>
|
<DragDropProvider
|
||||||
|
sensors={[chainPointerSensor, KeyboardSensor]}
|
||||||
|
onDragEnd={handleDragEnd}
|
||||||
|
>
|
||||||
<Box sx={{ borderRadius: 1, minHeight: 60, p: 1 }}>
|
<Box sx={{ borderRadius: 1, minHeight: 60, p: 1 }}>
|
||||||
{currentProxyChain.map((proxy, index) => (
|
{currentProxyChain.map((proxy, index) => (
|
||||||
<SortableProxyChainItem
|
<SortableProxyChainItem
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import {
|
|||||||
} from '@mui/material'
|
} from '@mui/material'
|
||||||
import { useLockFn } from 'ahooks'
|
import { useLockFn } from 'ahooks'
|
||||||
import dayjs from 'dayjs'
|
import dayjs from 'dayjs'
|
||||||
import { useMemo, useState } from 'react'
|
import { useState } from 'react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import { updateRuleProvider } from 'tauri-plugin-mihomo-api'
|
import { updateRuleProvider } from 'tauri-plugin-mihomo-api'
|
||||||
|
|
||||||
@@ -42,11 +42,6 @@ export const ProviderButton = () => {
|
|||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const [open, setOpen] = useState(false)
|
const [open, setOpen] = useState(false)
|
||||||
const { ruleProviders } = useRulesData()
|
const { ruleProviders } = useRulesData()
|
||||||
|
|
||||||
const sortedProviderEntries = useMemo(
|
|
||||||
() => Object.entries(ruleProviders || {}).sort(),
|
|
||||||
[ruleProviders],
|
|
||||||
)
|
|
||||||
const { refreshRules, refreshRuleProviders } = useAppRefreshers()
|
const { refreshRules, refreshRuleProviders } = useAppRefreshers()
|
||||||
const [updating, setUpdating] = useState<Record<string, boolean>>({})
|
const [updating, setUpdating] = useState<Record<string, boolean>>({})
|
||||||
|
|
||||||
@@ -171,119 +166,121 @@ export const ProviderButton = () => {
|
|||||||
|
|
||||||
<DialogContent>
|
<DialogContent>
|
||||||
<List sx={{ py: 0, minHeight: 250 }}>
|
<List sx={{ py: 0, minHeight: 250 }}>
|
||||||
{sortedProviderEntries.map(([key, item]) => {
|
{Object.entries(ruleProviders || {})
|
||||||
const provider = item
|
.sort()
|
||||||
const time = dayjs(provider.updatedAt)
|
.map(([key, item]) => {
|
||||||
const isUpdating = updating[key]
|
const provider = item
|
||||||
|
const time = dayjs(provider.updatedAt)
|
||||||
|
const isUpdating = updating[key]
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ListItem
|
<ListItem
|
||||||
key={key}
|
key={key}
|
||||||
sx={[
|
sx={[
|
||||||
{
|
{
|
||||||
p: 0,
|
p: 0,
|
||||||
mb: '8px',
|
mb: '8px',
|
||||||
borderRadius: 2,
|
borderRadius: 2,
|
||||||
overflow: 'hidden',
|
overflow: 'hidden',
|
||||||
transition: 'all 0.2s',
|
transition: 'all 0.2s',
|
||||||
},
|
},
|
||||||
({ palette: { mode, primary } }) => {
|
({ palette: { mode, primary } }) => {
|
||||||
const bgcolor = mode === 'light' ? '#ffffff' : '#24252f'
|
const bgcolor = mode === 'light' ? '#ffffff' : '#24252f'
|
||||||
const hoverColor =
|
const hoverColor =
|
||||||
mode === 'light'
|
mode === 'light'
|
||||||
? alpha(primary.main, 0.1)
|
? alpha(primary.main, 0.1)
|
||||||
: alpha(primary.main, 0.2)
|
: alpha(primary.main, 0.2)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
backgroundColor: bgcolor,
|
backgroundColor: bgcolor,
|
||||||
'&:hover': {
|
'&:hover': {
|
||||||
backgroundColor: hoverColor,
|
backgroundColor: hoverColor,
|
||||||
borderColor: alpha(primary.main, 0.3),
|
borderColor: alpha(primary.main, 0.3),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
>
|
|
||||||
<ListItemText
|
|
||||||
sx={{ px: 2, py: 1 }}
|
|
||||||
primary={
|
|
||||||
<Box
|
|
||||||
sx={{
|
|
||||||
display: 'flex',
|
|
||||||
justifyContent: 'space-between',
|
|
||||||
alignItems: 'center',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Typography
|
|
||||||
variant="subtitle1"
|
|
||||||
component="div"
|
|
||||||
noWrap
|
|
||||||
title={key}
|
|
||||||
sx={{ display: 'flex', alignItems: 'center' }}
|
|
||||||
>
|
|
||||||
<span style={{ marginRight: '8px' }}>{key}</span>
|
|
||||||
<TypeBox component="span">
|
|
||||||
{provider.ruleCount}
|
|
||||||
</TypeBox>
|
|
||||||
</Typography>
|
|
||||||
|
|
||||||
<Typography
|
|
||||||
variant="body2"
|
|
||||||
color="text.secondary"
|
|
||||||
noWrap
|
|
||||||
>
|
|
||||||
<small>{t('shared.labels.updateAt')}: </small>
|
|
||||||
{time.fromNow()}
|
|
||||||
</Typography>
|
|
||||||
</Box>
|
|
||||||
}
|
|
||||||
secondary={
|
|
||||||
<Box sx={{ display: 'flex' }}>
|
|
||||||
<TypeBox component="span">
|
|
||||||
{typeof provider.vehicleType === 'string'
|
|
||||||
? provider.vehicleType
|
|
||||||
: provider.vehicleType.Unknown}
|
|
||||||
</TypeBox>
|
|
||||||
<TypeBox component="span">
|
|
||||||
{typeof provider.behavior === 'string'
|
|
||||||
? provider.behavior
|
|
||||||
: provider.behavior.Unknown}
|
|
||||||
</TypeBox>
|
|
||||||
</Box>
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
<Divider orientation="vertical" flexItem />
|
|
||||||
<Box
|
|
||||||
sx={{
|
|
||||||
width: 40,
|
|
||||||
display: 'flex',
|
|
||||||
justifyContent: 'center',
|
|
||||||
alignItems: 'center',
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
<IconButton
|
<ListItemText
|
||||||
size="small"
|
sx={{ px: 2, py: 1 }}
|
||||||
color="primary"
|
primary={
|
||||||
onClick={() => updateProvider(key)}
|
<Box
|
||||||
disabled={isUpdating}
|
sx={{
|
||||||
aria-label={t('rules.page.provider.actions.update')}
|
display: 'flex',
|
||||||
|
justifyContent: 'space-between',
|
||||||
|
alignItems: 'center',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Typography
|
||||||
|
variant="subtitle1"
|
||||||
|
component="div"
|
||||||
|
noWrap
|
||||||
|
title={key}
|
||||||
|
sx={{ display: 'flex', alignItems: 'center' }}
|
||||||
|
>
|
||||||
|
<span style={{ marginRight: '8px' }}>{key}</span>
|
||||||
|
<TypeBox component="span">
|
||||||
|
{provider.ruleCount}
|
||||||
|
</TypeBox>
|
||||||
|
</Typography>
|
||||||
|
|
||||||
|
<Typography
|
||||||
|
variant="body2"
|
||||||
|
color="text.secondary"
|
||||||
|
noWrap
|
||||||
|
>
|
||||||
|
<small>{t('shared.labels.updateAt')}: </small>
|
||||||
|
{time.fromNow()}
|
||||||
|
</Typography>
|
||||||
|
</Box>
|
||||||
|
}
|
||||||
|
secondary={
|
||||||
|
<Box sx={{ display: 'flex' }}>
|
||||||
|
<TypeBox component="span">
|
||||||
|
{typeof provider.vehicleType === 'string'
|
||||||
|
? provider.vehicleType
|
||||||
|
: provider.vehicleType.Unknown}
|
||||||
|
</TypeBox>
|
||||||
|
<TypeBox component="span">
|
||||||
|
{typeof provider.behavior === 'string'
|
||||||
|
? provider.behavior
|
||||||
|
: provider.behavior.Unknown}
|
||||||
|
</TypeBox>
|
||||||
|
</Box>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<Divider orientation="vertical" flexItem />
|
||||||
|
<Box
|
||||||
sx={{
|
sx={{
|
||||||
animation: isUpdating
|
width: 40,
|
||||||
? 'spin 1s linear infinite'
|
display: 'flex',
|
||||||
: 'none',
|
justifyContent: 'center',
|
||||||
'@keyframes spin': {
|
alignItems: 'center',
|
||||||
'0%': { transform: 'rotate(0deg)' },
|
|
||||||
'100%': { transform: 'rotate(360deg)' },
|
|
||||||
},
|
|
||||||
}}
|
}}
|
||||||
title={t('rules.page.provider.actions.update')}
|
|
||||||
>
|
>
|
||||||
<RefreshRounded />
|
<IconButton
|
||||||
</IconButton>
|
size="small"
|
||||||
</Box>
|
color="primary"
|
||||||
</ListItem>
|
onClick={() => updateProvider(key)}
|
||||||
)
|
disabled={isUpdating}
|
||||||
})}
|
aria-label={t('rules.page.provider.actions.update')}
|
||||||
|
sx={{
|
||||||
|
animation: isUpdating
|
||||||
|
? 'spin 1s linear infinite'
|
||||||
|
: 'none',
|
||||||
|
'@keyframes spin': {
|
||||||
|
'0%': { transform: 'rotate(0deg)' },
|
||||||
|
'100%': { transform: 'rotate(360deg)' },
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
title={t('rules.page.provider.actions.update')}
|
||||||
|
>
|
||||||
|
<RefreshRounded />
|
||||||
|
</IconButton>
|
||||||
|
</Box>
|
||||||
|
</ListItem>
|
||||||
|
)
|
||||||
|
})}
|
||||||
</List>
|
</List>
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
|
|
||||||
|
|||||||
@@ -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(
|
||||||
|
|||||||
@@ -42,8 +42,6 @@ const HOTKEY_FUNC_LABELS: Record<(typeof HOTKEY_FUNC)[number], string> = {
|
|||||||
reactivate_profiles: 'settings.modals.hotkey.functions.reactivateProfiles',
|
reactivate_profiles: 'settings.modals.hotkey.functions.reactivateProfiles',
|
||||||
}
|
}
|
||||||
|
|
||||||
const EMPTY_KEYS: string[] = []
|
|
||||||
|
|
||||||
export const HotkeyViewer = forwardRef<DialogRef>((props, ref) => {
|
export const HotkeyViewer = forwardRef<DialogRef>((props, ref) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const [open, setOpen] = useState(false)
|
const [open, setOpen] = useState(false)
|
||||||
@@ -134,7 +132,7 @@ export const HotkeyViewer = forwardRef<DialogRef>((props, ref) => {
|
|||||||
<ItemWrapper key={func} data-setting-target={HOTKEY_FUNC_LABELS[func]}>
|
<ItemWrapper key={func} data-setting-target={HOTKEY_FUNC_LABELS[func]}>
|
||||||
<Typography>{t(HOTKEY_FUNC_LABELS[func])}</Typography>
|
<Typography>{t(HOTKEY_FUNC_LABELS[func])}</Typography>
|
||||||
<HotkeyInput
|
<HotkeyInput
|
||||||
value={hotkeyMap[func] ?? EMPTY_KEYS}
|
value={hotkeyMap[func] ?? []}
|
||||||
onChange={(v) => setHotkeyMap((m) => ({ ...m, [func]: v }))}
|
onChange={(v) => setHotkeyMap((m) => ({ ...m, [func]: v }))}
|
||||||
/>
|
/>
|
||||||
</ItemWrapper>
|
</ItemWrapper>
|
||||||
|
|||||||
@@ -14,16 +14,10 @@ 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 {
|
import { BaseDialog, DialogRef, Switch, TooltipIcon } from '@/components/base'
|
||||||
BaseDialog,
|
|
||||||
DialogRef,
|
|
||||||
Switch,
|
|
||||||
TooltipIcon,
|
|
||||||
switchChangeValue,
|
|
||||||
} from '@/components/base'
|
|
||||||
import { DEFAULT_HOVER_DELAY } from '@/components/proxy/proxy-group-navigator'
|
import { DEFAULT_HOVER_DELAY } from '@/components/proxy/proxy-group-navigator'
|
||||||
import { useVerge } from '@/hooks/use-verge'
|
import { useVerge } from '@/hooks/use-verge'
|
||||||
import { useWindowDecorations } from '@/hooks/use-window'
|
import { useWindowDecorations } from '@/hooks/use-window'
|
||||||
@@ -68,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()
|
||||||
@@ -110,6 +111,7 @@ export const LayoutViewer = forwardRef<DialogRef>((_, ref) => {
|
|||||||
close: () => setOpen(false),
|
close: () => setOpen(false),
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
const onSwitchFormat = (_e: any, value: boolean) => value
|
||||||
const onError = (err: any) => {
|
const onError = (err: any) => {
|
||||||
showNotice.error(err)
|
showNotice.error(err)
|
||||||
}
|
}
|
||||||
@@ -139,7 +141,7 @@ export const LayoutViewer = forwardRef<DialogRef>((_, ref) => {
|
|||||||
value={decorated}
|
value={decorated}
|
||||||
valueProps="checked"
|
valueProps="checked"
|
||||||
onCatch={onError}
|
onCatch={onError}
|
||||||
onFormat={switchChangeValue}
|
onFormat={onSwitchFormat}
|
||||||
onChange={async () => {
|
onChange={async () => {
|
||||||
await toggleDecorations()
|
await toggleDecorations()
|
||||||
}}
|
}}
|
||||||
@@ -156,7 +158,7 @@ export const LayoutViewer = forwardRef<DialogRef>((_, ref) => {
|
|||||||
value={verge?.traffic_graph ?? true}
|
value={verge?.traffic_graph ?? true}
|
||||||
valueProps="checked"
|
valueProps="checked"
|
||||||
onCatch={onError}
|
onCatch={onError}
|
||||||
onFormat={switchChangeValue}
|
onFormat={onSwitchFormat}
|
||||||
onChange={(e) => onChangeData({ traffic_graph: e })}
|
onChange={(e) => onChangeData({ traffic_graph: e })}
|
||||||
onGuard={(e) => patchVerge({ traffic_graph: e })}
|
onGuard={(e) => patchVerge({ traffic_graph: e })}
|
||||||
>
|
>
|
||||||
@@ -172,7 +174,7 @@ export const LayoutViewer = forwardRef<DialogRef>((_, ref) => {
|
|||||||
value={verge?.enable_memory_usage ?? true}
|
value={verge?.enable_memory_usage ?? true}
|
||||||
valueProps="checked"
|
valueProps="checked"
|
||||||
onCatch={onError}
|
onCatch={onError}
|
||||||
onFormat={switchChangeValue}
|
onFormat={onSwitchFormat}
|
||||||
onChange={(e) => onChangeData({ enable_memory_usage: e })}
|
onChange={(e) => onChangeData({ enable_memory_usage: e })}
|
||||||
onGuard={(e) => patchVerge({ enable_memory_usage: e })}
|
onGuard={(e) => patchVerge({ enable_memory_usage: e })}
|
||||||
>
|
>
|
||||||
@@ -190,7 +192,7 @@ export const LayoutViewer = forwardRef<DialogRef>((_, ref) => {
|
|||||||
value={verge?.enable_group_icon ?? true}
|
value={verge?.enable_group_icon ?? true}
|
||||||
valueProps="checked"
|
valueProps="checked"
|
||||||
onCatch={onError}
|
onCatch={onError}
|
||||||
onFormat={switchChangeValue}
|
onFormat={onSwitchFormat}
|
||||||
onChange={(e) => onChangeData({ enable_group_icon: e })}
|
onChange={(e) => onChangeData({ enable_group_icon: e })}
|
||||||
onGuard={(e) => patchVerge({ enable_group_icon: e })}
|
onGuard={(e) => patchVerge({ enable_group_icon: e })}
|
||||||
>
|
>
|
||||||
@@ -208,7 +210,7 @@ export const LayoutViewer = forwardRef<DialogRef>((_, ref) => {
|
|||||||
value={verge?.pause_render_traffic_stats_on_blur ?? true}
|
value={verge?.pause_render_traffic_stats_on_blur ?? true}
|
||||||
valueProps="checked"
|
valueProps="checked"
|
||||||
onCatch={onError}
|
onCatch={onError}
|
||||||
onFormat={switchChangeValue}
|
onFormat={onSwitchFormat}
|
||||||
onChange={(e) =>
|
onChange={(e) =>
|
||||||
onChangeData({ pause_render_traffic_stats_on_blur: e })
|
onChangeData({ pause_render_traffic_stats_on_blur: e })
|
||||||
}
|
}
|
||||||
@@ -276,7 +278,7 @@ export const LayoutViewer = forwardRef<DialogRef>((_, ref) => {
|
|||||||
value={verge?.enable_hover_jump_navigator ?? true}
|
value={verge?.enable_hover_jump_navigator ?? true}
|
||||||
valueProps="checked"
|
valueProps="checked"
|
||||||
onCatch={onError}
|
onCatch={onError}
|
||||||
onFormat={switchChangeValue}
|
onFormat={onSwitchFormat}
|
||||||
onChange={(e) => onChangeData({ enable_hover_jump_navigator: e })}
|
onChange={(e) => onChangeData({ enable_hover_jump_navigator: e })}
|
||||||
onGuard={(e) => patchVerge({ enable_hover_jump_navigator: e })}
|
onGuard={(e) => patchVerge({ enable_hover_jump_navigator: e })}
|
||||||
>
|
>
|
||||||
@@ -378,7 +380,7 @@ export const LayoutViewer = forwardRef<DialogRef>((_, ref) => {
|
|||||||
value={verge?.collapse_navbar ?? false}
|
value={verge?.collapse_navbar ?? false}
|
||||||
valueProps="checked"
|
valueProps="checked"
|
||||||
onCatch={onError}
|
onCatch={onError}
|
||||||
onFormat={switchChangeValue}
|
onFormat={onSwitchFormat}
|
||||||
onChange={(e) => onChangeData({ collapse_navbar: e })}
|
onChange={(e) => onChangeData({ collapse_navbar: e })}
|
||||||
onGuard={(e) => patchVerge({ collapse_navbar: e })}
|
onGuard={(e) => patchVerge({ collapse_navbar: e })}
|
||||||
>
|
>
|
||||||
@@ -425,7 +427,7 @@ export const LayoutViewer = forwardRef<DialogRef>((_, ref) => {
|
|||||||
value={verge?.enable_tray_speed ?? false}
|
value={verge?.enable_tray_speed ?? false}
|
||||||
valueProps="checked"
|
valueProps="checked"
|
||||||
onCatch={onError}
|
onCatch={onError}
|
||||||
onFormat={switchChangeValue}
|
onFormat={onSwitchFormat}
|
||||||
onChange={(e) => onChangeData({ enable_tray_speed: e })}
|
onChange={(e) => onChangeData({ enable_tray_speed: e })}
|
||||||
onGuard={(e) => patchVerge({ enable_tray_speed: e })}
|
onGuard={(e) => patchVerge({ enable_tray_speed: e })}
|
||||||
>
|
>
|
||||||
@@ -445,7 +447,7 @@ export const LayoutViewer = forwardRef<DialogRef>((_, ref) => {
|
|||||||
}
|
}
|
||||||
valueProps="checked"
|
valueProps="checked"
|
||||||
onCatch={onError}
|
onCatch={onError}
|
||||||
onFormat={switchChangeValue}
|
onFormat={onSwitchFormat}
|
||||||
onChange={(e) => onChangeData({ enable_tray_icon: e })}
|
onChange={(e) => onChangeData({ enable_tray_icon: e })}
|
||||||
onGuard={(e) => patchVerge({ enable_tray_icon: e })}
|
onGuard={(e) => patchVerge({ enable_tray_icon: e })}
|
||||||
>
|
>
|
||||||
@@ -499,7 +501,7 @@ export const LayoutViewer = forwardRef<DialogRef>((_, ref) => {
|
|||||||
value={verge?.tray_inline_outbound_modes ?? false}
|
value={verge?.tray_inline_outbound_modes ?? false}
|
||||||
valueProps="checked"
|
valueProps="checked"
|
||||||
onCatch={onError}
|
onCatch={onError}
|
||||||
onFormat={switchChangeValue}
|
onFormat={onSwitchFormat}
|
||||||
onChange={(e) => onChangeData({ tray_inline_outbound_modes: e })}
|
onChange={(e) => onChangeData({ tray_inline_outbound_modes: e })}
|
||||||
onGuard={(e) => patchVerge({ tray_inline_outbound_modes: e })}
|
onGuard={(e) => patchVerge({ tray_inline_outbound_modes: e })}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import {
|
|||||||
TextField,
|
TextField,
|
||||||
} from '@mui/material'
|
} from '@mui/material'
|
||||||
import { useLockFn } from 'ahooks'
|
import { useLockFn } from 'ahooks'
|
||||||
import { forwardRef, useMemo, useState } from 'react'
|
import { forwardRef, 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'
|
||||||
@@ -17,20 +17,6 @@ import { showNotice } from '@/services/notice-service'
|
|||||||
|
|
||||||
import { useSettingDialog } from '../settings-search-context'
|
import { useSettingDialog } from '../settings-search-context'
|
||||||
|
|
||||||
const APP_LOG_LEVEL_OPTIONS = [
|
|
||||||
'trace',
|
|
||||||
'debug',
|
|
||||||
'info',
|
|
||||||
'warn',
|
|
||||||
'error',
|
|
||||||
'silent',
|
|
||||||
].map((level) => ({
|
|
||||||
value: level,
|
|
||||||
label: level[0].toUpperCase() + level.slice(1).toLowerCase(),
|
|
||||||
}))
|
|
||||||
|
|
||||||
const PROXY_LAYOUT_COLUMN_VALUES = [1, 2, 3, 4, 5]
|
|
||||||
|
|
||||||
const buildInitialValues = (verge?: IVergeConfig | null) => ({
|
const buildInitialValues = (verge?: IVergeConfig | null) => ({
|
||||||
appLogLevel: verge?.app_log_level ?? 'warn',
|
appLogLevel: verge?.app_log_level ?? 'warn',
|
||||||
appLogMaxSize: verge?.app_log_max_size ?? 128,
|
appLogMaxSize: verge?.app_log_max_size ?? 128,
|
||||||
@@ -52,40 +38,6 @@ export const MiscViewer = forwardRef<DialogRef>((props, ref) => {
|
|||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const { verge, patchVerge } = useVerge()
|
const { verge, patchVerge } = useVerge()
|
||||||
|
|
||||||
const autoLogCleanOptions = useMemo(
|
|
||||||
() => [
|
|
||||||
{
|
|
||||||
key: t('settings.modals.misc.options.autoLogClean.never'),
|
|
||||||
value: 0,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
key: t('settings.modals.misc.options.autoLogClean.retainDays', {
|
|
||||||
n: 1,
|
|
||||||
}),
|
|
||||||
value: 1,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
key: t('settings.modals.misc.options.autoLogClean.retainDays', {
|
|
||||||
n: 7,
|
|
||||||
}),
|
|
||||||
value: 2,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
key: t('settings.modals.misc.options.autoLogClean.retainDays', {
|
|
||||||
n: 30,
|
|
||||||
}),
|
|
||||||
value: 3,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
key: t('settings.modals.misc.options.autoLogClean.retainDays', {
|
|
||||||
n: 90,
|
|
||||||
}),
|
|
||||||
value: 4,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
[t],
|
|
||||||
)
|
|
||||||
|
|
||||||
const [open, setOpen] = useState(false)
|
const [open, setOpen] = useState(false)
|
||||||
const [values, setValues] = useState(() => buildInitialValues(null))
|
const [values, setValues] = useState(() => buildInitialValues(null))
|
||||||
|
|
||||||
@@ -152,9 +104,9 @@ export const MiscViewer = forwardRef<DialogRef>((props, ref) => {
|
|||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
{APP_LOG_LEVEL_OPTIONS.map(({ value, label }) => (
|
{['trace', 'debug', 'info', 'warn', 'error', 'silent'].map((i) => (
|
||||||
<MenuItem value={value} key={value}>
|
<MenuItem value={i} key={i}>
|
||||||
{label}
|
{i[0].toUpperCase() + i.slice(1).toLowerCase()}
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
))}
|
))}
|
||||||
</Select>
|
</Select>
|
||||||
@@ -333,7 +285,7 @@ export const MiscViewer = forwardRef<DialogRef>((props, ref) => {
|
|||||||
<MenuItem value={6} key={6}>
|
<MenuItem value={6} key={6}>
|
||||||
{t('settings.modals.misc.options.proxyLayoutColumns.auto')}
|
{t('settings.modals.misc.options.proxyLayoutColumns.auto')}
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
{PROXY_LAYOUT_COLUMN_VALUES.map((i) => (
|
{[1, 2, 3, 4, 5].map((i) => (
|
||||||
<MenuItem value={i} key={i}>
|
<MenuItem value={i} key={i}>
|
||||||
{i}
|
{i}
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
@@ -360,7 +312,36 @@ export const MiscViewer = forwardRef<DialogRef>((props, ref) => {
|
|||||||
}
|
}
|
||||||
>
|
>
|
||||||
{/* 1: 1天, 2: 7天, 3: 30天, 4: 90天*/}
|
{/* 1: 1天, 2: 7天, 3: 30天, 4: 90天*/}
|
||||||
{autoLogCleanOptions.map((i) => (
|
{[
|
||||||
|
{
|
||||||
|
key: t('settings.modals.misc.options.autoLogClean.never'),
|
||||||
|
value: 0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: t('settings.modals.misc.options.autoLogClean.retainDays', {
|
||||||
|
n: 1,
|
||||||
|
}),
|
||||||
|
value: 1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: t('settings.modals.misc.options.autoLogClean.retainDays', {
|
||||||
|
n: 7,
|
||||||
|
}),
|
||||||
|
value: 2,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: t('settings.modals.misc.options.autoLogClean.retainDays', {
|
||||||
|
n: 30,
|
||||||
|
}),
|
||||||
|
value: 3,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: t('settings.modals.misc.options.autoLogClean.retainDays', {
|
||||||
|
n: 90,
|
||||||
|
}),
|
||||||
|
value: 4,
|
||||||
|
},
|
||||||
|
].map((i) => (
|
||||||
<MenuItem key={i.value} value={i.value}>
|
<MenuItem key={i.value} value={i.value}>
|
||||||
{i.key}
|
{i.key}
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
|
|||||||
@@ -84,19 +84,6 @@ const splitBypass = (value?: string) =>
|
|||||||
.map((item) => item.trim())
|
.map((item) => item.trim())
|
||||||
.filter(Boolean)
|
.filter(Boolean)
|
||||||
|
|
||||||
const OS = getSystem()
|
|
||||||
|
|
||||||
const DEFAULT_BYPASS =
|
|
||||||
OS === 'windows'
|
|
||||||
? 'localhost;127.*;192.168.*;10.*;172.16.*;172.17.*;172.18.*;172.19.*;172.20.*;172.21.*;172.22.*;172.23.*;172.24.*;172.25.*;172.26.*;172.27.*;172.28.*;172.29.*;172.30.*;172.31.*;*.local;<local>'
|
|
||||||
: OS === 'linux'
|
|
||||||
? 'localhost,127.0.0.1,192.168.0.0/16,10.0.0.0/8,172.16.0.0/12,::1'
|
|
||||||
: '127.0.0.1,192.168.0.0/16,10.0.0.0/8,172.16.0.0/12,localhost,*.local,*.crashlytics.com,<local>'
|
|
||||||
|
|
||||||
const DEFAULT_BYPASS_CHIPS = splitBypass(DEFAULT_BYPASS)
|
|
||||||
|
|
||||||
const BYPASS_SEPARATOR = OS === 'windows' ? ';' : ','
|
|
||||||
|
|
||||||
const buildInitialValues = (verge?: IVergeConfig | null) => ({
|
const buildInitialValues = (verge?: IVergeConfig | null) => ({
|
||||||
guard: verge?.enable_proxy_guard,
|
guard: verge?.enable_proxy_guard,
|
||||||
enable_bypass_check: verge?.enable_bypass_check ?? true,
|
enable_bypass_check: verge?.enable_bypass_check ?? true,
|
||||||
@@ -110,7 +97,8 @@ const buildInitialValues = (verge?: IVergeConfig | null) => ({
|
|||||||
|
|
||||||
export const SysproxyViewer = forwardRef<DialogRef>((props, ref) => {
|
export const SysproxyViewer = forwardRef<DialogRef>((props, ref) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const isWindows = OS === 'windows'
|
const systemName = getSystem()
|
||||||
|
const isWindows = systemName === 'windows'
|
||||||
const validReg = useMemo(() => getValidReg(isWindows), [isWindows])
|
const validReg = useMemo(() => getValidReg(isWindows), [isWindows])
|
||||||
|
|
||||||
const [open, setOpen] = useState(false)
|
const [open, setOpen] = useState(false)
|
||||||
@@ -142,7 +130,17 @@ export const SysproxyViewer = forwardRef<DialogRef>((props, ref) => {
|
|||||||
queryFn: getEmbeddedServerPort,
|
queryFn: getEmbeddedServerPort,
|
||||||
})
|
})
|
||||||
|
|
||||||
const separator = BYPASS_SEPARATOR
|
const separator = useMemo(() => (isWindows ? ';' : ','), [isWindows])
|
||||||
|
|
||||||
|
const defaultBypass = () => {
|
||||||
|
if (isWindows) {
|
||||||
|
return 'localhost;127.*;192.168.*;10.*;172.16.*;172.17.*;172.18.*;172.19.*;172.20.*;172.21.*;172.22.*;172.23.*;172.24.*;172.25.*;172.26.*;172.27.*;172.28.*;172.29.*;172.30.*;172.31.*;*.local;<local>'
|
||||||
|
}
|
||||||
|
if (systemName === 'linux') {
|
||||||
|
return 'localhost,127.0.0.1,192.168.0.0/16,10.0.0.0/8,172.16.0.0/12,::1'
|
||||||
|
}
|
||||||
|
return '127.0.0.1,192.168.0.0/16,10.0.0.0/8,172.16.0.0/12,localhost,*.local,*.crashlytics.com,<local>'
|
||||||
|
}
|
||||||
|
|
||||||
const { systemProxyAddress } = useSystemData()
|
const { systemProxyAddress } = useSystemData()
|
||||||
const displayedMixedPort = useDisplayedMixedPort()
|
const displayedMixedPort = useDisplayedMixedPort()
|
||||||
@@ -505,7 +503,7 @@ export const SysproxyViewer = forwardRef<DialogRef>((props, ref) => {
|
|||||||
checked={value.use_default}
|
checked={value.use_default}
|
||||||
onChange={(_, e) => {
|
onChange={(_, e) => {
|
||||||
if (!e && !value.bypass) {
|
if (!e && !value.bypass) {
|
||||||
const nextBypass = DEFAULT_BYPASS
|
const nextBypass = defaultBypass()
|
||||||
setValue((v) => ({
|
setValue((v) => ({
|
||||||
...v,
|
...v,
|
||||||
use_default: e,
|
use_default: e,
|
||||||
@@ -577,7 +575,7 @@ export const SysproxyViewer = forwardRef<DialogRef>((props, ref) => {
|
|||||||
/>
|
/>
|
||||||
<Box sx={{ padding: '0 2px 5px' }}>
|
<Box sx={{ padding: '0 2px 5px' }}>
|
||||||
<Box sx={{ display: 'flex', flexWrap: 'wrap', gap: 1 }}>
|
<Box sx={{ display: 'flex', flexWrap: 'wrap', gap: 1 }}>
|
||||||
{DEFAULT_BYPASS_CHIPS.map((item) => (
|
{splitBypass(defaultBypass()).map((item) => (
|
||||||
<Chip key={item} label={item} size="small" />
|
<Chip key={item} label={item} size="small" />
|
||||||
))}
|
))}
|
||||||
</Box>
|
</Box>
|
||||||
|
|||||||
@@ -20,12 +20,6 @@ import { showNotice } from '@/services/notice-service'
|
|||||||
|
|
||||||
import { useSettingDialog } from '../settings-search-context'
|
import { useSettingDialog } from '../settings-search-context'
|
||||||
|
|
||||||
const textProps = {
|
|
||||||
size: 'small',
|
|
||||||
autoComplete: 'off',
|
|
||||||
sx: { width: 135 },
|
|
||||||
} as const
|
|
||||||
|
|
||||||
export function ThemeViewer(props: { ref?: React.Ref<DialogRef> }) {
|
export function ThemeViewer(props: { ref?: React.Ref<DialogRef> }) {
|
||||||
const { ref } = props
|
const { ref } = props
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
@@ -51,6 +45,12 @@ export function ThemeViewer(props: { ref?: React.Ref<DialogRef> }) {
|
|||||||
close: () => setOpen(false),
|
close: () => setOpen(false),
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
const textProps = {
|
||||||
|
size: 'small',
|
||||||
|
autoComplete: 'off',
|
||||||
|
sx: { width: 135 },
|
||||||
|
} as const
|
||||||
|
|
||||||
const handleChange = (field: keyof typeof theme) => (e: any) => {
|
const handleChange = (field: keyof typeof theme) => (e: any) => {
|
||||||
setTheme((t) => ({ ...t, [field]: e.target.value }))
|
setTheme((t) => ({ ...t, [field]: e.target.value }))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import {
|
|||||||
} from '@mui/material'
|
} from '@mui/material'
|
||||||
import { useLockFn } from 'ahooks'
|
import { useLockFn } from 'ahooks'
|
||||||
import type { Ref } from 'react'
|
import type { Ref } from 'react'
|
||||||
import { useMemo, useState } from 'react'
|
import { useState } from 'react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@@ -58,9 +58,8 @@ export function TunViewer({ ref }: { ref?: Ref<DialogRef> }) {
|
|||||||
dnsMode: '',
|
dnsMode: '',
|
||||||
})
|
})
|
||||||
|
|
||||||
const routeExcludeAddressItems = useMemo(
|
const routeExcludeAddressItems = splitRouteExcludeAddress(
|
||||||
() => splitRouteExcludeAddress(values.routeExcludeAddress),
|
values.routeExcludeAddress,
|
||||||
[values.routeExcludeAddress],
|
|
||||||
)
|
)
|
||||||
const routeExcludeAddressError =
|
const routeExcludeAddressError =
|
||||||
values.autoRoute &&
|
values.autoRoute &&
|
||||||
|
|||||||
@@ -189,7 +189,10 @@ export function UpdateViewer({ ref }: { ref?: Ref<DialogRef> }) {
|
|||||||
void openExternalUrl(url).catch(showNotice.error)
|
void openExternalUrl(url).catch(showNotice.error)
|
||||||
}
|
}
|
||||||
|
|
||||||
const progress = total <= 0 ? 0 : Math.min((downloaded / total) * 100, 100)
|
const progress = useMemo(() => {
|
||||||
|
if (total <= 0) return 0
|
||||||
|
return Math.min((downloaded / total) * 100, 100)
|
||||||
|
}, [downloaded, total])
|
||||||
|
|
||||||
useImperativeHandle(ref, () => ({
|
useImperativeHandle(ref, () => ({
|
||||||
open: () => {
|
open: () => {
|
||||||
|
|||||||
@@ -5,13 +5,7 @@ import { useRef, useState } from 'react'
|
|||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import { updateGeo, type LogLevel } from 'tauri-plugin-mihomo-api'
|
import { updateGeo, type LogLevel } from 'tauri-plugin-mihomo-api'
|
||||||
|
|
||||||
import {
|
import { BaseDialog, DialogRef, Switch, TooltipIcon } from '@/components/base'
|
||||||
BaseDialog,
|
|
||||||
DialogRef,
|
|
||||||
Switch,
|
|
||||||
TooltipIcon,
|
|
||||||
switchChangeValue,
|
|
||||||
} from '@/components/base'
|
|
||||||
import { useClash } from '@/hooks/use-clash'
|
import { useClash } from '@/hooks/use-clash'
|
||||||
import { useClashLog } from '@/hooks/use-clash-log'
|
import { useClashLog } from '@/hooks/use-clash-log'
|
||||||
import { useDisplayedMixedPort } from '@/hooks/use-displayed-mixed-port'
|
import { useDisplayedMixedPort } from '@/hooks/use-displayed-mixed-port'
|
||||||
@@ -75,6 +69,7 @@ const SettingClash = ({ onError }: Props) => {
|
|||||||
const corsRef = useRef<DialogRef>(null)
|
const corsRef = useRef<DialogRef>(null)
|
||||||
const tunnelRef = useRef<DialogRef>(null)
|
const tunnelRef = useRef<DialogRef>(null)
|
||||||
|
|
||||||
|
const onSwitchFormat = (_e: any, value: boolean) => value
|
||||||
const onChangeData = (patch: Partial<IConfigData>) => {
|
const onChangeData = (patch: Partial<IConfigData>) => {
|
||||||
mutateClash((old) => ({ ...old!, ...patch }), false)
|
mutateClash((old) => ({ ...old!, ...patch }), false)
|
||||||
}
|
}
|
||||||
@@ -178,7 +173,7 @@ const SettingClash = ({ onError }: Props) => {
|
|||||||
value={allowLan ?? false}
|
value={allowLan ?? false}
|
||||||
valueProps="checked"
|
valueProps="checked"
|
||||||
onCatch={onError}
|
onCatch={onError}
|
||||||
onFormat={switchChangeValue}
|
onFormat={onSwitchFormat}
|
||||||
onChange={(e) => onChangeData({ 'allow-lan': e })}
|
onChange={(e) => onChangeData({ 'allow-lan': e })}
|
||||||
onGuard={(e) => patchClash({ 'allow-lan': e })}
|
onGuard={(e) => patchClash({ 'allow-lan': e })}
|
||||||
>
|
>
|
||||||
@@ -218,7 +213,7 @@ const SettingClash = ({ onError }: Props) => {
|
|||||||
value={ipv6 ?? false}
|
value={ipv6 ?? false}
|
||||||
valueProps="checked"
|
valueProps="checked"
|
||||||
onCatch={onError}
|
onCatch={onError}
|
||||||
onFormat={switchChangeValue}
|
onFormat={onSwitchFormat}
|
||||||
onChange={(e) => onChangeData({ ipv6: e })}
|
onChange={(e) => onChangeData({ ipv6: e })}
|
||||||
onGuard={(e) => patchClash({ ipv6: e })}
|
onGuard={(e) => patchClash({ ipv6: e })}
|
||||||
>
|
>
|
||||||
@@ -240,7 +235,7 @@ const SettingClash = ({ onError }: Props) => {
|
|||||||
value={unifiedDelay ?? false}
|
value={unifiedDelay ?? false}
|
||||||
valueProps="checked"
|
valueProps="checked"
|
||||||
onCatch={onError}
|
onCatch={onError}
|
||||||
onFormat={switchChangeValue}
|
onFormat={onSwitchFormat}
|
||||||
onChange={(e) => onChangeData({ 'unified-delay': e })}
|
onChange={(e) => onChangeData({ 'unified-delay': e })}
|
||||||
onGuard={(e) => patchClash({ 'unified-delay': e })}
|
onGuard={(e) => patchClash({ 'unified-delay': e })}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import { Box } from '@mui/material'
|
import { Box } from '@mui/material'
|
||||||
|
import React from 'react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
|
|
||||||
import { Switch, TooltipIcon, switchChangeValue } from '@/components/base'
|
import { Switch, TooltipIcon } from '@/components/base'
|
||||||
import ProxyControlSwitches from '@/components/shared/proxy-control-switches'
|
import ProxyControlSwitches from '@/components/shared/proxy-control-switches'
|
||||||
import { useVerge } from '@/hooks/use-verge'
|
import { useVerge } from '@/hooks/use-verge'
|
||||||
|
|
||||||
@@ -19,6 +20,10 @@ const SettingSystem = ({ onError }: Props) => {
|
|||||||
|
|
||||||
const { enable_auto_launch, enable_silent_start } = verge ?? {}
|
const { enable_auto_launch, enable_silent_start } = verge ?? {}
|
||||||
|
|
||||||
|
const onSwitchFormat = (
|
||||||
|
_e: React.ChangeEvent<HTMLInputElement>,
|
||||||
|
value: boolean,
|
||||||
|
) => value
|
||||||
const onChangeData = (patch: Partial<IVergeConfig>) => {
|
const onChangeData = (patch: Partial<IVergeConfig>) => {
|
||||||
mutateVerge({ ...verge, ...patch })
|
mutateVerge({ ...verge, ...patch })
|
||||||
}
|
}
|
||||||
@@ -47,7 +52,7 @@ const SettingSystem = ({ onError }: Props) => {
|
|||||||
value={enable_auto_launch ?? false}
|
value={enable_auto_launch ?? false}
|
||||||
valueProps="checked"
|
valueProps="checked"
|
||||||
onCatch={onError}
|
onCatch={onError}
|
||||||
onFormat={switchChangeValue}
|
onFormat={onSwitchFormat}
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
onChangeData({ enable_auto_launch: e })
|
onChangeData({ enable_auto_launch: e })
|
||||||
}}
|
}}
|
||||||
@@ -80,7 +85,7 @@ const SettingSystem = ({ onError }: Props) => {
|
|||||||
value={enable_silent_start ?? false}
|
value={enable_silent_start ?? false}
|
||||||
valueProps="checked"
|
valueProps="checked"
|
||||||
onCatch={onError}
|
onCatch={onError}
|
||||||
onFormat={switchChangeValue}
|
onFormat={onSwitchFormat}
|
||||||
onChange={(e) => onChangeData({ enable_silent_start: e })}
|
onChange={(e) => onChangeData({ enable_silent_start: e })}
|
||||||
onGuard={(e) => patchVerge({ enable_silent_start: e })}
|
onGuard={(e) => patchVerge({ enable_silent_start: e })}
|
||||||
>
|
>
|
||||||
|
|||||||
+12
-22
@@ -1,6 +1,5 @@
|
|||||||
import { useLockFn } from 'ahooks'
|
import { useLockFn } from 'ahooks'
|
||||||
import i18n from 'i18next'
|
import i18n from 'i18next'
|
||||||
import { useCallback } from 'react'
|
|
||||||
import { getVersion } from 'tauri-plugin-mihomo-api'
|
import { getVersion } from 'tauri-plugin-mihomo-api'
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@@ -87,29 +86,23 @@ export const useClashMode = (shouldFetch: boolean = true) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const useClash = () => {
|
export const useClash = () => {
|
||||||
const { data: clash } = useRuntimeConfig()
|
const { data: clash, refetch } = useRuntimeConfig()
|
||||||
|
|
||||||
const { data: versionData, refetch: mutateVersion } = useQuery({
|
const { data: versionData, refetch: mutateVersion } = useQuery({
|
||||||
queryKey: ['getVersion'],
|
queryKey: ['getVersion'],
|
||||||
queryFn: getVersion,
|
queryFn: getVersion,
|
||||||
})
|
})
|
||||||
|
|
||||||
// Stable identity: consumers pass mutateClash into their own callbacks.
|
const mutateClash = (updater?: MutateClashUpdater, revalidate?: boolean) => {
|
||||||
// revalidateQuery hits the same cache key refetch would, without capturing
|
if (updater === undefined) {
|
||||||
// the per-render refetch closure.
|
return refetch()
|
||||||
const mutateClash = useCallback(
|
}
|
||||||
(updater?: MutateClashUpdater, revalidate?: boolean) => {
|
void setCacheData<IConfigData>(['getRuntimeConfig'], updater)
|
||||||
if (updater === undefined) {
|
if (revalidate !== false) {
|
||||||
return revalidateQuery(['getRuntimeConfig'])
|
return refetch()
|
||||||
}
|
}
|
||||||
void setCacheData<IConfigData>(['getRuntimeConfig'], updater)
|
return Promise.resolve()
|
||||||
if (revalidate !== false) {
|
}
|
||||||
return revalidateQuery(['getRuntimeConfig'])
|
|
||||||
}
|
|
||||||
return Promise.resolve()
|
|
||||||
},
|
|
||||||
[],
|
|
||||||
)
|
|
||||||
|
|
||||||
const patchClash = useLockFn(async (patch: Partial<IConfigData>) => {
|
const patchClash = useLockFn(async (patch: Partial<IConfigData>) => {
|
||||||
await mutate(() => patchClashConfig(patch), {
|
await mutate(() => patchClashConfig(patch), {
|
||||||
@@ -150,10 +143,7 @@ export const useClashInfo = () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
const invalidateClashConfig = useCallback(
|
const invalidateClashConfig = () => revalidateQuery(['getClashConfig'])
|
||||||
() => revalidateQuery(['getClashConfig']),
|
|
||||||
[],
|
|
||||||
)
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
clashInfo,
|
clashInfo,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { useCallback, useMemo, useSyncExternalStore } from 'react'
|
import { useCallback, useSyncExternalStore } from 'react'
|
||||||
|
|
||||||
import delayManager, { type DelaySnapshot } from '@/services/delay'
|
import delayManager, { type DelaySnapshot } from '@/services/delay'
|
||||||
import type { ResolvedProxyMember } from '@/types/proxy-view'
|
import type { ResolvedProxyMember } from '@/types/proxy-view'
|
||||||
@@ -32,7 +32,7 @@ export const useGroupsDelays = (
|
|||||||
groups: readonly string[],
|
groups: readonly string[],
|
||||||
): ReadonlyMap<string, DelaySnapshot> => {
|
): ReadonlyMap<string, DelaySnapshot> => {
|
||||||
// Group membership must remain unambiguous when names contain spaces.
|
// Group membership must remain unambiguous when names contain spaces.
|
||||||
const groupKey = useMemo(() => JSON.stringify(groups), [groups])
|
const groupKey = JSON.stringify(groups)
|
||||||
|
|
||||||
const subscribe = useCallback(
|
const subscribe = useCallback(
|
||||||
(onSettle: () => void) => {
|
(onSettle: () => void) => {
|
||||||
|
|||||||
@@ -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,
|
||||||
|
|||||||
@@ -177,15 +177,13 @@ export async function getProxyView(): Promise<ProxyViewV1> {
|
|||||||
return view
|
return view
|
||||||
}
|
}
|
||||||
|
|
||||||
// getClashLogs matches both patterns against every log line.
|
|
||||||
const CLASH_LOG_REGEX = /time="(.+?)"\s+level=(.+?)\s+msg="(.+?)"/
|
|
||||||
const CLASH_LOG_NEW_REGEX = /(.+?)\s+(.+?)\s+(.+)/
|
|
||||||
|
|
||||||
export async function getClashLogs() {
|
export async function getClashLogs() {
|
||||||
|
const regex = /time="(.+?)"\s+level=(.+?)\s+msg="(.+?)"/
|
||||||
|
const newRegex = /(.+?)\s+(.+?)\s+(.+)/
|
||||||
const logs = await commands.getClashLogs()
|
const logs = await commands.getClashLogs()
|
||||||
|
|
||||||
return logs.reduce<ILogItem[]>((acc, log) => {
|
return logs.reduce<ILogItem[]>((acc, log) => {
|
||||||
const result = log.match(CLASH_LOG_REGEX)
|
const result = log.match(regex)
|
||||||
if (result) {
|
if (result) {
|
||||||
const [_, _time, type, payload] = result
|
const [_, _time, type, payload] = result
|
||||||
const time = dayjs(_time).format('MM-DD HH:mm:ss')
|
const time = dayjs(_time).format('MM-DD HH:mm:ss')
|
||||||
@@ -193,7 +191,7 @@ export async function getClashLogs() {
|
|||||||
return acc
|
return acc
|
||||||
}
|
}
|
||||||
|
|
||||||
const result2 = log.match(CLASH_LOG_NEW_REGEX)
|
const result2 = log.match(newRegex)
|
||||||
if (result2) {
|
if (result2) {
|
||||||
const [_, time, type, payload] = result2
|
const [_, time, type, payload] = result2
|
||||||
acc.push({ time, type, payload })
|
acc.push({ time, type, payload })
|
||||||
|
|||||||
@@ -514,21 +514,9 @@ export function hideNotice(id: number) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function hideNoticesByCode(code: string) {
|
function hideNoticesByCode(code: string) {
|
||||||
// One subscriber notification for the whole batch; per-notice removal
|
notices
|
||||||
// would notify once per item.
|
.filter((notice) => notice.code === code)
|
||||||
const remaining: NoticeItem[] = []
|
.forEach(({ id }) => hideNotice(id))
|
||||||
let removed = false
|
|
||||||
for (const notice of notices) {
|
|
||||||
if (notice.code === code) {
|
|
||||||
removed = true
|
|
||||||
if (notice.timerId) clearTimeout(notice.timerId)
|
|
||||||
} else {
|
|
||||||
remaining.push(notice)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!removed) return
|
|
||||||
notices = remaining
|
|
||||||
notifySubscribers()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function syncSidecarFailure(snapshot: SidecarFailureSnapshot) {
|
export function syncSidecarFailure(snapshot: SidecarFailureSnapshot) {
|
||||||
|
|||||||
@@ -241,17 +241,17 @@ export function parseUrlLike(
|
|||||||
: result
|
: result
|
||||||
}
|
}
|
||||||
|
|
||||||
// Both predicates run per parsed proxy URI.
|
|
||||||
const IPV4_REGEX = /^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$/
|
|
||||||
const IPV6_REGEX =
|
|
||||||
/^([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$|^::$|^::1$|^([0-9a-fA-F]{1,4}:)*::([0-9a-fA-F]{1,4}:)*[0-9a-fA-F]{1,4}$/
|
|
||||||
|
|
||||||
export function isIPv4(address: string): boolean {
|
export function isIPv4(address: string): boolean {
|
||||||
return IPV4_REGEX.test(address)
|
// Check if the address is IPv4
|
||||||
|
const ipv4Regex = /^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$/
|
||||||
|
return ipv4Regex.test(address)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isIPv6(address: string): boolean {
|
export function isIPv6(address: string): boolean {
|
||||||
return IPV6_REGEX.test(address)
|
// Check if the address is IPv6 - simplified regex to avoid backreference issues
|
||||||
|
const ipv6Regex =
|
||||||
|
/^([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$|^::$|^::1$|^([0-9a-fA-F]{1,4}:)*::([0-9a-fA-F]{1,4}:)*[0-9a-fA-F]{1,4}$/
|
||||||
|
return ipv6Regex.test(address)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function decodeBase64OrOriginal(str: string): string {
|
export function decodeBase64OrOriginal(str: string): string {
|
||||||
|
|||||||
Reference in New Issue
Block a user