import { useCallback, useEffect, useId, useState, type ReactNode } from 'react'; import { useAppDispatch, useAppSelector } from '~/hooks'; import { selectStagingBatchDownloadSettings, selectStagingDirectWriteSettings } from '../settingsSelector'; import { BatchDownloadSettings, DirectWriteOutputMode, updateBatchDownloadSetting, updateDirectWriteSetting, } from '../settingsSlice'; import { BatchDownloadType } from '~/platform/capabilities'; import { usePlatform } from '~/platform/PlatformContext'; import { clearRememberedDirectoryHandle, hasRememberedDirectoryHandle } from '~/util/downloadDirectoryHandle'; import { toast } from 'react-toastify'; export function PanelGeneral() { const dispatch = useAppDispatch(); const batch = useAppSelector(selectStagingBatchDownloadSettings); const directWrite = useAppSelector(selectStagingDirectWriteSettings); const { capabilities, download } = usePlatform(); const downloadTypes = new Set(capabilities.downloadTypes); const canDirectoryPicker = downloadTypes.has(BatchDownloadType.SelectDirectory); const canStreamingZip = downloadTypes.has(BatchDownloadType.StreamZip); const canBlobZip = downloadTypes.has(BatchDownloadType.PackZip); const canDirectWrite = capabilities.directFsAccess; const [hasRememberedDir, setHasRememberedDir] = useState(false); const [pickingDirectory, setPickingDirectory] = useState(false); const refreshRemembered = useCallback(() => { hasRememberedDirectoryHandle() .then(setHasRememberedDir) .catch(() => setHasRememberedDir(false)); }, []); useEffect(() => { refreshRemembered(); }, [refreshRemembered]); const setBatch = (key: keyof BatchDownloadSettings, value: boolean) => { dispatch(updateBatchDownloadSetting({ key, value })); }; const handleClearDirectory = async () => { await clearRememberedDirectoryHandle(); refreshRemembered(); toast.info('已清除记住的输出目录'); }; const handlePickDirectory = async () => { setPickingDirectory(true); try { const path = await download.pickDirectory(); if (path) { dispatch(updateDirectWriteSetting({ fixedDirectoryPath: path, outputMode: 'fixedDirectory' })); } } catch (e) { toast.error(`无法选择文件夹: ${e instanceof Error ? e.message : String(e)}`); } finally { setPickingDirectory(false); } }; const idDir = useId(); const idRemember = useId(); const idStreamZip = useId(); const idBlobZip = useId(); const idOutputMode = useId(); const idFixedPath = useId(); const idDeleteSource = useId(); return (

通用设置

批量下载

点击「下载全部」时,将按下方勾选项的顺序依次尝试。若选中的模式均不可用或全部失败,会弹出提示。

setBatch('directoryPicker', checked)} />
setBatch('rememberDirectory', checked)} />
{hasRememberedDir ? '已记住一个输出目录' : '尚未记住输出目录'}
setBatch('streamingZip', checked)} /> 在内存中生成 ZIP 后触发一次浏览器下载。兼容性最好;ZIP 需整包驻留内存,建议合计不超过约 500MB~1GB(视设备可用内存而定,过大可能失败或卡顿)。 ) : ( '当前环境不支持打包 ZIP 下载。' ) } onChange={(checked) => setBatch('blobZip', checked)} />

解密后自动保存

{canDirectWrite ? '解密完成后直接保存到本机,无需再手动下载。' : '当前环境无法直接保存到本机,请使用上方的批量下载。此项设置会保留,在桌面客户端中生效。'}

{directWrite.outputMode === 'besideSource' ? '解密后的文件保存在加密文件旁边。' : '解密后的文件保存到下方指定的文件夹。'}
dispatch( updateDirectWriteSetting({ fixedDirectoryPath: e.target.value === '' ? null : e.target.value }), ) } />
dispatch(updateDirectWriteSetting({ deleteSourceAfterDecrypt: checked }))} />
); } type BatchOptionProps = { id: string; checked: boolean; disabled?: boolean; dimmed?: boolean; title: string; description: ReactNode; onChange: (checked: boolean) => void; }; function BatchOption({ id, checked, disabled, dimmed, title, description, onChange }: BatchOptionProps) { return ( ); }