diff --git a/src/pages/Copy.tsx b/src/pages/Copy.tsx index 298cd93..4590f98 100644 --- a/src/pages/Copy.tsx +++ b/src/pages/Copy.tsx @@ -1,10 +1,11 @@ import { Accordion, AccordionItem, Avatar, Button } from '@nextui-org/react' -import { getCurrentWindow } from '@tauri-apps/api/window' import { message } from '@tauri-apps/plugin-dialog' +import { exists } from '@tauri-apps/plugin-fs' import { AlertOctagonIcon, CopyIcon, FilterIcon, FoldersIcon, PlayIcon } from 'lucide-react' import { useCallback, useEffect, useMemo, useState } from 'react' import { useSearchParams } from 'react-router-dom' import { getRemoteName } from '../../lib/format' +import { isRemotePath } from '../../lib/fs' import { getCopyFlags, getFilterFlags, getGlobalFlags, startCopy } from '../../lib/rclone/api' import { usePersistedStore } from '../../lib/store' import { openWindow } from '../../lib/window' @@ -99,10 +100,54 @@ export default function Copy() { const handleStartCopy = useCallback(async () => { setIsLoading(true) + if (!source || !dest) { + await message('Please select both a source and destination path', { + title: 'Error', + kind: 'error', + }) + return + } + + let sourceExists = false + let destExists = false + + try { + // check local paths exists + if (isRemotePath(source)) { + sourceExists = true + } else { + sourceExists = await exists(source) + } + + if (isRemotePath(dest)) { + destExists = true + } else { + destExists = await exists(dest) + } + } catch {} + + if (!sourceExists) { + await message('Source path does not exist', { + title: 'Error', + kind: 'error', + }) + setIsLoading(false) + return + } + + if (!destExists) { + await message('Destination path does not exist', { + title: 'Error', + kind: 'error', + }) + setIsLoading(false) + return + } + try { await startCopy({ - source: source!, - dest: dest!, + source, + dest, copyOptions, filterOptions, }) @@ -194,7 +239,7 @@ export default function Copy() { -
+
{isStarted ? ( <>
-
+
{isStarted ? ( <>