diff --git a/src/components/base/base-search-box.tsx b/src/components/base/base-search-box.tsx index 9f12fc997..97d310f31 100644 --- a/src/components/base/base-search-box.tsx +++ b/src/components/base/base-search-box.tsx @@ -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 = (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]) diff --git a/src/components/layout/window-controller.tsx b/src/components/layout/window-controller.tsx index d6797790e..373fd101a 100644 --- a/src/components/layout/window-controller.tsx +++ b/src/components/layout/window-controller.tsx @@ -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 (
{ } export const WindowControls = () => { - const OS = getSystem() const { maximized, minimize, close, toggleMaximize } = useWindowControls() // 通过前端对 tauri 窗口进行翻转全屏时会短暂地与系统图标重叠渲染。 diff --git a/src/components/profile/enhance-hint.tsx b/src/components/profile/enhance-hint.tsx index da0200af7..eb1a63a55 100644 --- a/src/components/profile/enhance-hint.tsx +++ b/src/components/profile/enhance-hint.tsx @@ -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, - , - ]), + // The component map identity changes only when the active stage changes. + const orderComponents = useMemo( + () => + Object.fromEntries( + Object.keys(stageHints).map((key) => [ + key, + , + ]), + ), + [stage], ) return ( diff --git a/src/components/setting/mods/hotkey-viewer.tsx b/src/components/setting/mods/hotkey-viewer.tsx index 4a449ad96..4bfce0ab9 100644 --- a/src/components/setting/mods/hotkey-viewer.tsx +++ b/src/components/setting/mods/hotkey-viewer.tsx @@ -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((props, ref) => { const { t } = useTranslation() const [open, setOpen] = useState(false) @@ -132,7 +134,7 @@ export const HotkeyViewer = forwardRef((props, ref) => { {t(HOTKEY_FUNC_LABELS[func])} setHotkeyMap((m) => ({ ...m, [func]: v }))} /> diff --git a/src/components/setting/mods/misc-viewer.tsx b/src/components/setting/mods/misc-viewer.tsx index c7365c621..59636acc8 100644 --- a/src/components/setting/mods/misc-viewer.tsx +++ b/src/components/setting/mods/misc-viewer.tsx @@ -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((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((props, ref) => { })) } > - {['trace', 'debug', 'info', 'warn', 'error', 'silent'].map((i) => ( - - {i[0].toUpperCase() + i.slice(1).toLowerCase()} + {APP_LOG_LEVEL_OPTIONS.map(({ value, label }) => ( + + {label} ))} @@ -285,7 +333,7 @@ export const MiscViewer = forwardRef((props, ref) => { {t('settings.modals.misc.options.proxyLayoutColumns.auto')} - {[1, 2, 3, 4, 5].map((i) => ( + {PROXY_LAYOUT_COLUMN_VALUES.map((i) => ( {i} @@ -312,36 +360,7 @@ export const MiscViewer = forwardRef((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) => ( {i.key} diff --git a/src/components/setting/mods/sysproxy-viewer.tsx b/src/components/setting/mods/sysproxy-viewer.tsx index 3b5162bb7..3ea4f3bc8 100644 --- a/src/components/setting/mods/sysproxy-viewer.tsx +++ b/src/components/setting/mods/sysproxy-viewer.tsx @@ -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;' + : 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,' + +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((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((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;' - } - 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,' - } + const separator = BYPASS_SEPARATOR const { systemProxyAddress } = useSystemData() const displayedMixedPort = useDisplayedMixedPort() @@ -503,7 +505,7 @@ export const SysproxyViewer = forwardRef((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((props, ref) => { /> - {splitBypass(defaultBypass()).map((item) => ( + {DEFAULT_BYPASS_CHIPS.map((item) => ( ))} diff --git a/src/components/setting/mods/theme-viewer.tsx b/src/components/setting/mods/theme-viewer.tsx index 867c5572b..4f300bb7f 100644 --- a/src/components/setting/mods/theme-viewer.tsx +++ b/src/components/setting/mods/theme-viewer.tsx @@ -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 }) { const { ref } = props const { t } = useTranslation() @@ -45,12 +51,6 @@ export function ThemeViewer(props: { ref?: React.Ref }) { 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 })) }