diff --git a/src/components/setting/mods/controller-viewer.tsx b/src/components/setting/mods/controller-viewer.tsx index 306c0f915..9ebece9f3 100644 --- a/src/components/setting/mods/controller-viewer.tsx +++ b/src/components/setting/mods/controller-viewer.tsx @@ -12,7 +12,7 @@ import { Tooltip, } from '@mui/material' import { useLockFn } from 'ahooks' -import { useState, type Ref } from 'react' +import { useRef, useState, type Ref } from 'react' import { useTranslation } from 'react-i18next' import { BaseDialog, DialogRef, Switch } from '@/components/base' @@ -26,6 +26,10 @@ export function ControllerViewer({ ref }: { ref?: Ref }) { const { t } = useTranslation() const [open, setOpen] = useState(false) const [copySuccess, setCopySuccess] = useState(null) + // A second copy within the window must not be hidden by the first timer. + const copySuccessTimerRef = useRef | undefined>( + undefined, + ) const [isSaving, setIsSaving] = useState(false) const { clashInfo, patchInfo } = useClashInfo() @@ -96,7 +100,11 @@ export function ControllerViewer({ ref }: { ref?: Ref }) { try { await navigator.clipboard.writeText(text) setCopySuccess(type) - setTimeout(() => setCopySuccess(null)) + clearTimeout(copySuccessTimerRef.current) + copySuccessTimerRef.current = setTimeout( + () => setCopySuccess(null), + 2000, + ) } catch (err) { console.warn('[ControllerViewer] copy to clipboard failed:', err) showNotice.error(