mirror of
https://github.com/movie-web/native-app.git
synced 2025-09-13 14:33:26 +00:00
feat: clear cache button
This commit is contained in:
@@ -4,6 +4,7 @@ import { Platform } from "react-native";
|
||||
import Markdown from "react-native-markdown-display";
|
||||
import * as Application from "expo-application";
|
||||
import * as Brightness from "expo-brightness";
|
||||
import * as FileSystem from "expo-file-system";
|
||||
import * as WebBrowser from "expo-web-browser";
|
||||
import {
|
||||
FontAwesome,
|
||||
@@ -87,6 +88,28 @@ export default function SettingsScreen() {
|
||||
}
|
||||
};
|
||||
|
||||
const clearCacheDirectory = async () => {
|
||||
const cacheDirectory = FileSystem.cacheDirectory + "movie-web";
|
||||
if (!cacheDirectory) return;
|
||||
|
||||
try {
|
||||
await FileSystem.deleteAsync(cacheDirectory, { idempotent: true });
|
||||
|
||||
toastController.show("Cache cleared", {
|
||||
burntOptions: { preset: "done" },
|
||||
native: true,
|
||||
duration: 500,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Error clearing cache directory:", error);
|
||||
toastController.show("Error clearing cache", {
|
||||
burntOptions: { preset: "error" },
|
||||
native: true,
|
||||
duration: 500,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<ScreenLayout>
|
||||
<View padding={4}>
|
||||
@@ -142,7 +165,7 @@ export default function SettingsScreen() {
|
||||
<YStack gap="$2">
|
||||
<XStack gap="$4" alignItems="center">
|
||||
<Text fontWeight="$semibold" flexGrow={1}>
|
||||
Version v{Application.nativeApplicationVersion}
|
||||
Version {Application.nativeApplicationVersion}
|
||||
</Text>
|
||||
<MWButton
|
||||
type="secondary"
|
||||
@@ -166,6 +189,25 @@ export default function SettingsScreen() {
|
||||
Update
|
||||
</MWButton>
|
||||
</XStack>
|
||||
<XStack gap="$4" alignItems="center">
|
||||
<Text fontWeight="$semibold" flexGrow={1}>
|
||||
Storage
|
||||
</Text>
|
||||
<MWButton
|
||||
type="secondary"
|
||||
backgroundColor="$sheetItemBackground"
|
||||
icon={
|
||||
<MaterialCommunityIcons
|
||||
name="broom"
|
||||
size={24}
|
||||
color={theme.buttonSecondaryText.val}
|
||||
/>
|
||||
}
|
||||
onPress={() => clearCacheDirectory()}
|
||||
>
|
||||
Clear Cache
|
||||
</MWButton>
|
||||
</XStack>
|
||||
</YStack>
|
||||
</YStack>
|
||||
</YStack>
|
||||
|
@@ -223,9 +223,10 @@ export const DownloadManagerProvider: React.FC<{ children: ReactNode }> = ({
|
||||
lastTimestamp = currentTime;
|
||||
};
|
||||
|
||||
const fileUri = FileSystem.cacheDirectory
|
||||
? FileSystem.cacheDirectory + url.split("/").pop()
|
||||
: null;
|
||||
const fileUri =
|
||||
FileSystem.cacheDirectory + "movie-web"
|
||||
? FileSystem.cacheDirectory + "movie-web" + url.split("/").pop()
|
||||
: null;
|
||||
if (!fileUri) {
|
||||
console.error("Cache directory is unavailable");
|
||||
reject(new Error("Cache directory is unavailable"));
|
||||
@@ -277,7 +278,7 @@ export const DownloadManagerProvider: React.FC<{ children: ReactNode }> = ({
|
||||
const totalSegments = segments.length;
|
||||
let segmentsDownloaded = 0;
|
||||
|
||||
const segmentDir = FileSystem.cacheDirectory + "segments/";
|
||||
const segmentDir = FileSystem.cacheDirectory + "movie-web/segments/";
|
||||
await ensureDirExists(segmentDir);
|
||||
|
||||
const updateProgress = () => {
|
||||
@@ -326,7 +327,7 @@ export const DownloadManagerProvider: React.FC<{ children: ReactNode }> = ({
|
||||
updateDownloadItem(downloadId, { statusText: "Merging" });
|
||||
const uri = await VideoManager.mergeVideos(
|
||||
localSegmentPaths,
|
||||
`${FileSystem.cacheDirectory}output.mp4`,
|
||||
`${FileSystem.cacheDirectory}movie-web/output.mp4`,
|
||||
);
|
||||
const asset = await saveFileToMediaLibraryAndDeleteOriginal(
|
||||
uri,
|
||||
|
Reference in New Issue
Block a user