mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-11-20 02:42:12 +08:00
refactor(ui): share the switch adapter and drop dead memos
Three settings files each defined the same boolean switch-format adapter; it is exported once from the Switch module. The update dialog memoized trivial arithmetic, the profile-more reset callback keyed on a per-render document object instead of its stable setter, and the profile viewer's imperative handle had no dependency array.
This commit is contained in:
@@ -17,7 +17,13 @@ import { exists } from '@tauri-apps/plugin-fs'
|
||||
import { forwardRef, useEffect, useState } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
|
||||
import { BaseDialog, DialogRef, Switch, TooltipIcon } from '@/components/base'
|
||||
import {
|
||||
BaseDialog,
|
||||
DialogRef,
|
||||
Switch,
|
||||
TooltipIcon,
|
||||
switchChangeValue,
|
||||
} from '@/components/base'
|
||||
import { DEFAULT_HOVER_DELAY } from '@/components/proxy/proxy-group-navigator'
|
||||
import { useVerge } from '@/hooks/use-verge'
|
||||
import { useWindowDecorations } from '@/hooks/use-window'
|
||||
@@ -104,7 +110,6 @@ export const LayoutViewer = forwardRef<DialogRef>((_, ref) => {
|
||||
close: () => setOpen(false),
|
||||
}))
|
||||
|
||||
const onSwitchFormat = (_e: any, value: boolean) => value
|
||||
const onError = (err: any) => {
|
||||
showNotice.error(err)
|
||||
}
|
||||
@@ -134,7 +139,7 @@ export const LayoutViewer = forwardRef<DialogRef>((_, ref) => {
|
||||
value={decorated}
|
||||
valueProps="checked"
|
||||
onCatch={onError}
|
||||
onFormat={onSwitchFormat}
|
||||
onFormat={switchChangeValue}
|
||||
onChange={async () => {
|
||||
await toggleDecorations()
|
||||
}}
|
||||
@@ -151,7 +156,7 @@ export const LayoutViewer = forwardRef<DialogRef>((_, ref) => {
|
||||
value={verge?.traffic_graph ?? true}
|
||||
valueProps="checked"
|
||||
onCatch={onError}
|
||||
onFormat={onSwitchFormat}
|
||||
onFormat={switchChangeValue}
|
||||
onChange={(e) => onChangeData({ traffic_graph: e })}
|
||||
onGuard={(e) => patchVerge({ traffic_graph: e })}
|
||||
>
|
||||
@@ -167,7 +172,7 @@ export const LayoutViewer = forwardRef<DialogRef>((_, ref) => {
|
||||
value={verge?.enable_memory_usage ?? true}
|
||||
valueProps="checked"
|
||||
onCatch={onError}
|
||||
onFormat={onSwitchFormat}
|
||||
onFormat={switchChangeValue}
|
||||
onChange={(e) => onChangeData({ enable_memory_usage: e })}
|
||||
onGuard={(e) => patchVerge({ enable_memory_usage: e })}
|
||||
>
|
||||
@@ -185,7 +190,7 @@ export const LayoutViewer = forwardRef<DialogRef>((_, ref) => {
|
||||
value={verge?.enable_group_icon ?? true}
|
||||
valueProps="checked"
|
||||
onCatch={onError}
|
||||
onFormat={onSwitchFormat}
|
||||
onFormat={switchChangeValue}
|
||||
onChange={(e) => onChangeData({ enable_group_icon: e })}
|
||||
onGuard={(e) => patchVerge({ enable_group_icon: e })}
|
||||
>
|
||||
@@ -203,7 +208,7 @@ export const LayoutViewer = forwardRef<DialogRef>((_, ref) => {
|
||||
value={verge?.pause_render_traffic_stats_on_blur ?? true}
|
||||
valueProps="checked"
|
||||
onCatch={onError}
|
||||
onFormat={onSwitchFormat}
|
||||
onFormat={switchChangeValue}
|
||||
onChange={(e) =>
|
||||
onChangeData({ pause_render_traffic_stats_on_blur: e })
|
||||
}
|
||||
@@ -271,7 +276,7 @@ export const LayoutViewer = forwardRef<DialogRef>((_, ref) => {
|
||||
value={verge?.enable_hover_jump_navigator ?? true}
|
||||
valueProps="checked"
|
||||
onCatch={onError}
|
||||
onFormat={onSwitchFormat}
|
||||
onFormat={switchChangeValue}
|
||||
onChange={(e) => onChangeData({ enable_hover_jump_navigator: e })}
|
||||
onGuard={(e) => patchVerge({ enable_hover_jump_navigator: e })}
|
||||
>
|
||||
@@ -373,7 +378,7 @@ export const LayoutViewer = forwardRef<DialogRef>((_, ref) => {
|
||||
value={verge?.collapse_navbar ?? false}
|
||||
valueProps="checked"
|
||||
onCatch={onError}
|
||||
onFormat={onSwitchFormat}
|
||||
onFormat={switchChangeValue}
|
||||
onChange={(e) => onChangeData({ collapse_navbar: e })}
|
||||
onGuard={(e) => patchVerge({ collapse_navbar: e })}
|
||||
>
|
||||
@@ -420,7 +425,7 @@ export const LayoutViewer = forwardRef<DialogRef>((_, ref) => {
|
||||
value={verge?.enable_tray_speed ?? false}
|
||||
valueProps="checked"
|
||||
onCatch={onError}
|
||||
onFormat={onSwitchFormat}
|
||||
onFormat={switchChangeValue}
|
||||
onChange={(e) => onChangeData({ enable_tray_speed: e })}
|
||||
onGuard={(e) => patchVerge({ enable_tray_speed: e })}
|
||||
>
|
||||
@@ -440,7 +445,7 @@ export const LayoutViewer = forwardRef<DialogRef>((_, ref) => {
|
||||
}
|
||||
valueProps="checked"
|
||||
onCatch={onError}
|
||||
onFormat={onSwitchFormat}
|
||||
onFormat={switchChangeValue}
|
||||
onChange={(e) => onChangeData({ enable_tray_icon: e })}
|
||||
onGuard={(e) => patchVerge({ enable_tray_icon: e })}
|
||||
>
|
||||
@@ -494,7 +499,7 @@ export const LayoutViewer = forwardRef<DialogRef>((_, ref) => {
|
||||
value={verge?.tray_inline_outbound_modes ?? false}
|
||||
valueProps="checked"
|
||||
onCatch={onError}
|
||||
onFormat={onSwitchFormat}
|
||||
onFormat={switchChangeValue}
|
||||
onChange={(e) => onChangeData({ tray_inline_outbound_modes: e })}
|
||||
onGuard={(e) => patchVerge({ tray_inline_outbound_modes: e })}
|
||||
>
|
||||
|
||||
@@ -189,10 +189,7 @@ export function UpdateViewer({ ref }: { ref?: Ref<DialogRef> }) {
|
||||
void openExternalUrl(url).catch(showNotice.error)
|
||||
}
|
||||
|
||||
const progress = useMemo(() => {
|
||||
if (total <= 0) return 0
|
||||
return Math.min((downloaded / total) * 100, 100)
|
||||
}, [downloaded, total])
|
||||
const progress = total <= 0 ? 0 : Math.min((downloaded / total) * 100, 100)
|
||||
|
||||
useImperativeHandle(ref, () => ({
|
||||
open: () => {
|
||||
|
||||
Reference in New Issue
Block a user