mirror of
https://github.com/movie-web/native-app.git
synced 2025-09-13 14:53:24 +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 Markdown from "react-native-markdown-display";
|
||||||
import * as Application from "expo-application";
|
import * as Application from "expo-application";
|
||||||
import * as Brightness from "expo-brightness";
|
import * as Brightness from "expo-brightness";
|
||||||
|
import * as FileSystem from "expo-file-system";
|
||||||
import * as WebBrowser from "expo-web-browser";
|
import * as WebBrowser from "expo-web-browser";
|
||||||
import {
|
import {
|
||||||
FontAwesome,
|
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 (
|
return (
|
||||||
<ScreenLayout>
|
<ScreenLayout>
|
||||||
<View padding={4}>
|
<View padding={4}>
|
||||||
@@ -142,7 +165,7 @@ export default function SettingsScreen() {
|
|||||||
<YStack gap="$2">
|
<YStack gap="$2">
|
||||||
<XStack gap="$4" alignItems="center">
|
<XStack gap="$4" alignItems="center">
|
||||||
<Text fontWeight="$semibold" flexGrow={1}>
|
<Text fontWeight="$semibold" flexGrow={1}>
|
||||||
Version v{Application.nativeApplicationVersion}
|
Version {Application.nativeApplicationVersion}
|
||||||
</Text>
|
</Text>
|
||||||
<MWButton
|
<MWButton
|
||||||
type="secondary"
|
type="secondary"
|
||||||
@@ -166,6 +189,25 @@ export default function SettingsScreen() {
|
|||||||
Update
|
Update
|
||||||
</MWButton>
|
</MWButton>
|
||||||
</XStack>
|
</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>
|
</YStack>
|
||||||
</YStack>
|
</YStack>
|
||||||
|
@@ -223,9 +223,10 @@ export const DownloadManagerProvider: React.FC<{ children: ReactNode }> = ({
|
|||||||
lastTimestamp = currentTime;
|
lastTimestamp = currentTime;
|
||||||
};
|
};
|
||||||
|
|
||||||
const fileUri = FileSystem.cacheDirectory
|
const fileUri =
|
||||||
? FileSystem.cacheDirectory + url.split("/").pop()
|
FileSystem.cacheDirectory + "movie-web"
|
||||||
: null;
|
? FileSystem.cacheDirectory + "movie-web" + url.split("/").pop()
|
||||||
|
: null;
|
||||||
if (!fileUri) {
|
if (!fileUri) {
|
||||||
console.error("Cache directory is unavailable");
|
console.error("Cache directory is unavailable");
|
||||||
reject(new 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;
|
const totalSegments = segments.length;
|
||||||
let segmentsDownloaded = 0;
|
let segmentsDownloaded = 0;
|
||||||
|
|
||||||
const segmentDir = FileSystem.cacheDirectory + "segments/";
|
const segmentDir = FileSystem.cacheDirectory + "movie-web/segments/";
|
||||||
await ensureDirExists(segmentDir);
|
await ensureDirExists(segmentDir);
|
||||||
|
|
||||||
const updateProgress = () => {
|
const updateProgress = () => {
|
||||||
@@ -326,7 +327,7 @@ export const DownloadManagerProvider: React.FC<{ children: ReactNode }> = ({
|
|||||||
updateDownloadItem(downloadId, { statusText: "Merging" });
|
updateDownloadItem(downloadId, { statusText: "Merging" });
|
||||||
const uri = await VideoManager.mergeVideos(
|
const uri = await VideoManager.mergeVideos(
|
||||||
localSegmentPaths,
|
localSegmentPaths,
|
||||||
`${FileSystem.cacheDirectory}output.mp4`,
|
`${FileSystem.cacheDirectory}movie-web/output.mp4`,
|
||||||
);
|
);
|
||||||
const asset = await saveFileToMediaLibraryAndDeleteOriginal(
|
const asset = await saveFileToMediaLibraryAndDeleteOriginal(
|
||||||
uri,
|
uri,
|
||||||
|
Reference in New Issue
Block a user