diff --git a/src/renderer/src/App.tsx b/src/renderer/src/App.tsx index ccc919d3..fe697b18 100644 --- a/src/renderer/src/App.tsx +++ b/src/renderer/src/App.tsx @@ -2181,21 +2181,23 @@ function App() { }, [currentSegIndexSafe, onEditSegmentTags]); const promptDownloadMediaUrlWrapper = useCallback(async () => { - if (customOutDir == null) { - errorToast(i18n.t('Please select a working directory first')); - return; - } - const outPath = getDownloadMediaOutPath(customOutDir, `downloaded-media-${Date.now()}.mkv`); try { - setWorking(true); + setWorking({ text: t('Downloading URL') }); + const newCustomOutDir = await ensureWritableOutDir({ outDir: customOutDir }); + if (newCustomOutDir == null) { + errorToast(i18n.t('Please select a working directory first')); + return; + } + const outPath = getDownloadMediaOutPath(newCustomOutDir, `downloaded-media-${Date.now()}.mkv`); const downloaded = await promptDownloadMediaUrl(outPath); if (downloaded) await loadMedia({ filePath: outPath }); } catch (err) { + if (err instanceof DirectoryAccessDeclinedError) return; handleError(err); } finally { setWorking(); } - }, [customOutDir, loadMedia, setWorking]); + }, [customOutDir, ensureWritableOutDir, loadMedia, setWorking, t]); type MainKeyboardAction = Exclude; diff --git a/src/renderer/src/hooks/useDirectoryAccess.ts b/src/renderer/src/hooks/useDirectoryAccess.ts index 754b293f..27c1284f 100644 --- a/src/renderer/src/hooks/useDirectoryAccess.ts +++ b/src/renderer/src/hooks/useDirectoryAccess.ts @@ -56,7 +56,7 @@ export default ({ setCustomOutDir }: { setCustomOutDir: (a: string | undefined) } }, []); - const ensureWritableOutDir = useCallback(async ({ inputPath, outDir }: { inputPath: string | undefined, outDir: string | undefined }) => { + const ensureWritableOutDir = useCallback(async ({ inputPath, outDir }: { inputPath?: string | undefined, outDir: string | undefined }) => { // we might need to change the output directory if the user chooses to give us a different one. let newCustomOutDir = outDir; @@ -69,6 +69,7 @@ export default ({ setCustomOutDir }: { setCustomOutDir: (a: string | undefined) } } + // if we don't (no longer) have a working dir, and not an main file path, then there's nothing we can do, just return the dir if (!newCustomOutDir && !inputPath) return newCustomOutDir; const effectiveOutDirPath = getOutDir(newCustomOutDir, inputPath);