diff --git a/src/components/ExecuteBtn.tsx b/src/components/ExecuteBtn.tsx index f599c76..b7b1356 100644 --- a/src/components/ExecuteBtn.tsx +++ b/src/components/ExecuteBtn.tsx @@ -83,7 +83,7 @@ function ExecuteBtn({ outputFormat === undefined ? getFileExt(inputFile.uri) : outputFormat; const outputFileName = fileName - ? encodeURI(fileName.replace(" ", "-")) + ? fileName.trim().replace(" ", "-") : `${getFileName(inputFile.uri)}_${outputFileDate}`; const outputFilePath = `${FileSystem.cacheDirectory}output/${outputFileName}.${outputFileFormat}`; @@ -96,7 +96,7 @@ function ExecuteBtn({ setShareFilePath(outputFilePath); setCmdRunning(false); setCmdStatus("success"); - await MediaLibrary.saveToLibraryAsync(outputFilePath); + await MediaLibrary.saveToLibraryAsync(encodeURI(outputFilePath)); await Haptics.notificationAsync(); } else { setCmdStatus("error"); diff --git a/src/locales/en.json b/src/locales/en.json index 28535bb..a68a68f 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -6,7 +6,7 @@ "fileInputLabel": "File name (optional)", "fileInputPlaceholder": "Enter file name...", "onboard": { - "header": "As-salamu alaykum...\nBasset is a free open source utility, its goals are:\nSimplicity and ease [Basset means simple in Arabic :)] ✨\nSpeed ⚡️\nPrivacy 🔏", + "header": "As-salamu alaykum...\nBasset is a free open source utility, its goals are:\n• Simplicity and ease [Basset means simple in Arabic :)] ✨\n• Speed ⚡️\n• Privacy 🔏", "features": "Basset lets you trim, convert, compress, downgrade quality of your Audio/Video file. moreover you can convert Audio files to Video files using a still Image you choose", "steps": "steps: choose your Video/Audio file --> choose your wanted operation" }, diff --git a/src/screens/FileUploadScreen.tsx b/src/screens/FileUploadScreen.tsx index 0beec15..1143b31 100644 --- a/src/screens/FileUploadScreen.tsx +++ b/src/screens/FileUploadScreen.tsx @@ -9,6 +9,8 @@ import { G, Path, Svg } from "react-native-svg"; import Seperator from "../components/Seperator"; import { useFilePathStore } from "../stores/filePathStore"; +const WHITELISTED_FOLDERS = ["WebView", "image_cache", "http-cache"]; + const logo = require("../assets/appIcon.png"); function FileUploadScreen() { @@ -16,30 +18,50 @@ function FileUploadScreen() { const colors = useTheme().colors; const navigation = useNavigation(); const { setInputFile } = useFilePathStore(); - const { hasShareIntent, shareIntent } = useShareIntentContext(); + const { hasShareIntent, shareIntent, isReady } = useShareIntentContext(); useEffect(() => { - if (hasShareIntent && shareIntent.files) { - setInputFile({ - uri: shareIntent?.files?.[0].path, - mimeType: shareIntent?.files?.[0].mimeType, - }); + async function getShareIntentFile() { + if (hasShareIntent && shareIntent.files && isReady) { + setInputFile({ + uri: shareIntent.files[0].path, + mimeType: shareIntent?.files?.[0].mimeType, + }); - // @ts-ignore - navigation.navigate("Home"); + // @ts-ignore + navigation.navigate("Home"); + } } - }, [hasShareIntent, setInputFile, navigation.navigate, shareIntent?.files]); + getShareIntentFile(); + }, [ + hasShareIntent, + setInputFile, + navigation.navigate, + shareIntent?.files, + isReady, + ]); async function onFileUploadPress() { - //Delete Document picker cache - await FileSystem.deleteAsync(`${FileSystem.cacheDirectory}DocumentPicker`, { - idempotent: true, - }); + //Sorry for this very annoying nested ifs :) + if (FileSystem.cacheDirectory) { + const cacheDirContent = await FileSystem.readDirectoryAsync( + FileSystem.cacheDirectory, + ); - //Delete ffmpeg process outputs picker cache - await FileSystem.deleteAsync(`${FileSystem.cacheDirectory}output`, { - idempotent: true, - }); + //Delete unused cache + if (cacheDirContent) { + for (const file of cacheDirContent) { + //Only delete files/folders beside Whitelisted ones + if (!WHITELISTED_FOLDERS.includes(file)) + await FileSystem.deleteAsync( + `${FileSystem.cacheDirectory}${file}`, + { + idempotent: true, + }, + ); + } + } + } //Make output directory for ffmpeg process await FileSystem.makeDirectoryAsync(`${FileSystem.cacheDirectory}output`, {