mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-11-20 02:42:12 +08:00
perf(ui): hoist static style, menu and OS identities
Dialog controls rebuilt static option arrays, style objects and label maps on every render; the sysproxy viewer also probed the OS and split the default bypass string per render. These are now module constants or single memos keyed on their real inputs (translation function, active stage).
This commit is contained in:
@@ -53,6 +53,15 @@ const StyledTextField = styled(TextField)(({ theme }) => ({
|
||||
},
|
||||
}))
|
||||
|
||||
const iconStyle = {
|
||||
style: {
|
||||
height: '24px',
|
||||
width: '24px',
|
||||
cursor: 'pointer',
|
||||
} as React.CSSProperties,
|
||||
inheritViewBox: true,
|
||||
}
|
||||
|
||||
const useControllableState = <T,>(options: {
|
||||
controlled: T | undefined
|
||||
defaultValue: T
|
||||
@@ -119,15 +128,6 @@ export const BaseSearchBox = ({
|
||||
defaultValue: defaultUseRegularExpression,
|
||||
})
|
||||
|
||||
const iconStyle = {
|
||||
style: {
|
||||
height: '24px',
|
||||
width: '24px',
|
||||
cursor: 'pointer',
|
||||
} as React.CSSProperties,
|
||||
inheritViewBox: true,
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
onSearchRef.current = onSearch
|
||||
}, [onSearch])
|
||||
|
||||
@@ -5,6 +5,8 @@ import { type PointerEvent, useCallback } from 'react'
|
||||
import { useWindowControls } from '@/hooks/use-window'
|
||||
import getSystem from '@/utils/get-system'
|
||||
|
||||
const OS = getSystem()
|
||||
|
||||
const RESIZE_HANDLES = [
|
||||
{ direction: 'North', position: 'north' },
|
||||
{ direction: 'NorthEast', position: 'north-east' },
|
||||
@@ -38,7 +40,7 @@ export const WindowResizeHandles = () => {
|
||||
[currentWindow],
|
||||
)
|
||||
|
||||
if (getSystem() !== 'linux' || maximized) return null
|
||||
if (OS !== 'linux' || maximized) return null
|
||||
|
||||
return (
|
||||
<div
|
||||
@@ -59,7 +61,6 @@ export const WindowResizeHandles = () => {
|
||||
}
|
||||
|
||||
export const WindowControls = () => {
|
||||
const OS = getSystem()
|
||||
const { maximized, minimize, close, toggleMaximize } = useWindowControls()
|
||||
|
||||
// 通过前端对 tauri 窗口进行翻转全屏时会短暂地与系统图标重叠渲染。
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Alert, Box, Typography } from '@mui/material'
|
||||
import { useMemo } from 'react'
|
||||
import { Trans, useTranslation } from 'react-i18next'
|
||||
|
||||
const stageHints = {
|
||||
@@ -14,26 +15,31 @@ interface Props {
|
||||
|
||||
export const EnhanceHint = ({ stage }: Props) => {
|
||||
const { t } = useTranslation()
|
||||
const orderComponents = Object.fromEntries(
|
||||
Object.keys(stageHints).map((key) => [
|
||||
key,
|
||||
<Box
|
||||
key={key}
|
||||
component={key === stage ? 'strong' : 'span'}
|
||||
sx={
|
||||
key === stage
|
||||
? {
|
||||
fontWeight: 'bold',
|
||||
color: 'primary.contrastText',
|
||||
bgcolor: 'primary.main',
|
||||
borderRadius: 0.5,
|
||||
px: 0.5,
|
||||
boxDecorationBreak: 'clone',
|
||||
}
|
||||
: undefined
|
||||
}
|
||||
/>,
|
||||
]),
|
||||
// The component map identity changes only when the active stage changes.
|
||||
const orderComponents = useMemo(
|
||||
() =>
|
||||
Object.fromEntries(
|
||||
Object.keys(stageHints).map((key) => [
|
||||
key,
|
||||
<Box
|
||||
key={key}
|
||||
component={key === stage ? 'strong' : 'span'}
|
||||
sx={
|
||||
key === stage
|
||||
? {
|
||||
fontWeight: 'bold',
|
||||
color: 'primary.contrastText',
|
||||
bgcolor: 'primary.main',
|
||||
borderRadius: 0.5,
|
||||
px: 0.5,
|
||||
boxDecorationBreak: 'clone',
|
||||
}
|
||||
: undefined
|
||||
}
|
||||
/>,
|
||||
]),
|
||||
),
|
||||
[stage],
|
||||
)
|
||||
|
||||
return (
|
||||
|
||||
@@ -42,6 +42,8 @@ const HOTKEY_FUNC_LABELS: Record<(typeof HOTKEY_FUNC)[number], string> = {
|
||||
reactivate_profiles: 'settings.modals.hotkey.functions.reactivateProfiles',
|
||||
}
|
||||
|
||||
const EMPTY_KEYS: string[] = []
|
||||
|
||||
export const HotkeyViewer = forwardRef<DialogRef>((props, ref) => {
|
||||
const { t } = useTranslation()
|
||||
const [open, setOpen] = useState(false)
|
||||
@@ -132,7 +134,7 @@ export const HotkeyViewer = forwardRef<DialogRef>((props, ref) => {
|
||||
<ItemWrapper key={func} data-setting-target={HOTKEY_FUNC_LABELS[func]}>
|
||||
<Typography>{t(HOTKEY_FUNC_LABELS[func])}</Typography>
|
||||
<HotkeyInput
|
||||
value={hotkeyMap[func] ?? []}
|
||||
value={hotkeyMap[func] ?? EMPTY_KEYS}
|
||||
onChange={(v) => setHotkeyMap((m) => ({ ...m, [func]: v }))}
|
||||
/>
|
||||
</ItemWrapper>
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
TextField,
|
||||
} from '@mui/material'
|
||||
import { useLockFn } from 'ahooks'
|
||||
import { forwardRef, useState } from 'react'
|
||||
import { forwardRef, useMemo, useState } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
|
||||
import { BaseDialog, DialogRef, Switch, TooltipIcon } from '@/components/base'
|
||||
@@ -17,6 +17,20 @@ import { showNotice } from '@/services/notice-service'
|
||||
|
||||
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) => ({
|
||||
appLogLevel: verge?.app_log_level ?? 'warn',
|
||||
appLogMaxSize: verge?.app_log_max_size ?? 128,
|
||||
@@ -38,6 +52,40 @@ export const MiscViewer = forwardRef<DialogRef>((props, ref) => {
|
||||
const { t } = useTranslation()
|
||||
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 [values, setValues] = useState(() => buildInitialValues(null))
|
||||
|
||||
@@ -104,9 +152,9 @@ export const MiscViewer = forwardRef<DialogRef>((props, ref) => {
|
||||
}))
|
||||
}
|
||||
>
|
||||
{['trace', 'debug', 'info', 'warn', 'error', 'silent'].map((i) => (
|
||||
<MenuItem value={i} key={i}>
|
||||
{i[0].toUpperCase() + i.slice(1).toLowerCase()}
|
||||
{APP_LOG_LEVEL_OPTIONS.map(({ value, label }) => (
|
||||
<MenuItem value={value} key={value}>
|
||||
{label}
|
||||
</MenuItem>
|
||||
))}
|
||||
</Select>
|
||||
@@ -285,7 +333,7 @@ export const MiscViewer = forwardRef<DialogRef>((props, ref) => {
|
||||
<MenuItem value={6} key={6}>
|
||||
{t('settings.modals.misc.options.proxyLayoutColumns.auto')}
|
||||
</MenuItem>
|
||||
{[1, 2, 3, 4, 5].map((i) => (
|
||||
{PROXY_LAYOUT_COLUMN_VALUES.map((i) => (
|
||||
<MenuItem value={i} key={i}>
|
||||
{i}
|
||||
</MenuItem>
|
||||
@@ -312,36 +360,7 @@ export const MiscViewer = forwardRef<DialogRef>((props, ref) => {
|
||||
}
|
||||
>
|
||||
{/* 1: 1天, 2: 7天, 3: 30天, 4: 90天*/}
|
||||
{[
|
||||
{
|
||||
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) => (
|
||||
{autoLogCleanOptions.map((i) => (
|
||||
<MenuItem key={i.value} value={i.value}>
|
||||
{i.key}
|
||||
</MenuItem>
|
||||
|
||||
@@ -84,6 +84,19 @@ const splitBypass = (value?: string) =>
|
||||
.map((item) => item.trim())
|
||||
.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) => ({
|
||||
guard: verge?.enable_proxy_guard,
|
||||
enable_bypass_check: verge?.enable_bypass_check ?? true,
|
||||
@@ -97,8 +110,7 @@ const buildInitialValues = (verge?: IVergeConfig | null) => ({
|
||||
|
||||
export const SysproxyViewer = forwardRef<DialogRef>((props, ref) => {
|
||||
const { t } = useTranslation()
|
||||
const systemName = getSystem()
|
||||
const isWindows = systemName === 'windows'
|
||||
const isWindows = OS === 'windows'
|
||||
const validReg = useMemo(() => getValidReg(isWindows), [isWindows])
|
||||
|
||||
const [open, setOpen] = useState(false)
|
||||
@@ -130,17 +142,7 @@ export const SysproxyViewer = forwardRef<DialogRef>((props, ref) => {
|
||||
queryFn: getEmbeddedServerPort,
|
||||
})
|
||||
|
||||
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 separator = BYPASS_SEPARATOR
|
||||
|
||||
const { systemProxyAddress } = useSystemData()
|
||||
const displayedMixedPort = useDisplayedMixedPort()
|
||||
@@ -503,7 +505,7 @@ export const SysproxyViewer = forwardRef<DialogRef>((props, ref) => {
|
||||
checked={value.use_default}
|
||||
onChange={(_, e) => {
|
||||
if (!e && !value.bypass) {
|
||||
const nextBypass = defaultBypass()
|
||||
const nextBypass = DEFAULT_BYPASS
|
||||
setValue((v) => ({
|
||||
...v,
|
||||
use_default: e,
|
||||
@@ -575,7 +577,7 @@ export const SysproxyViewer = forwardRef<DialogRef>((props, ref) => {
|
||||
/>
|
||||
<Box sx={{ padding: '0 2px 5px' }}>
|
||||
<Box sx={{ display: 'flex', flexWrap: 'wrap', gap: 1 }}>
|
||||
{splitBypass(defaultBypass()).map((item) => (
|
||||
{DEFAULT_BYPASS_CHIPS.map((item) => (
|
||||
<Chip key={item} label={item} size="small" />
|
||||
))}
|
||||
</Box>
|
||||
|
||||
@@ -20,6 +20,12 @@ import { showNotice } from '@/services/notice-service'
|
||||
|
||||
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> }) {
|
||||
const { ref } = props
|
||||
const { t } = useTranslation()
|
||||
@@ -45,12 +51,6 @@ export function ThemeViewer(props: { ref?: React.Ref<DialogRef> }) {
|
||||
close: () => setOpen(false),
|
||||
}))
|
||||
|
||||
const textProps = {
|
||||
size: 'small',
|
||||
autoComplete: 'off',
|
||||
sx: { width: 135 },
|
||||
} as const
|
||||
|
||||
const handleChange = (field: keyof typeof theme) => (e: any) => {
|
||||
setTheme((t) => ({ ...t, [field]: e.target.value }))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user