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 (
点击「下载全部」时,将按下方勾选项的顺序依次尝试。若选中的模式均不可用或全部失败,会弹出提示。
{canDirectWrite ? '解密完成后直接保存到本机,无需再手动下载。' : '当前环境无法直接保存到本机,请使用上方的批量下载。此项设置会保留,在桌面客户端中生效。'}