Skip to content

Commit

Permalink
fix: Fixed some bugs produced from share-intent + other fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mohammadmansour200 committed Sep 7, 2024
1 parent 4c9564d commit 44b60ca
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/components/ExecuteBtn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
Expand All @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
56 changes: 39 additions & 17 deletions src/screens/FileUploadScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,59 @@ 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() {
const { t } = useTranslation();
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`, {
Expand Down

0 comments on commit 44b60ca

Please sign in to comment.