Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

mobile: cleanup downloaded cache files on startup

Ammar Ahmeded5c84b069e8
diff --git a/apps/mobile/app/common/filesystem/io.ts b/apps/mobile/app/common/filesystem/io.ts
index 9551a24ed..2c6b84e64 100644
--- a/apps/mobile/app/common/filesystem/io.ts
+++ b/apps/mobile/app/common/filesystem/io.ts
@@ -222,15 +222,21 @@ export async function deleteCacheFileByName(name: string) {
}
export async function deleteDCacheFiles() {
- await createCacheDir();
- const files = await RNFetchBlob.fs.ls(cacheDir);
- for (const file of files) {
- if (file.includes("_dcache") || file.startsWith("NN_")) {
- await RNFetchBlob.fs.unlink(file).catch(() => {
- /* empty */
- });
+ try {
+ await createCacheDir();
+ const files = await RNFetchBlob.fs.ls(cacheDir);
+ for (const file of files) {
+ if (
+ file.includes("_dcache") ||
+ file.startsWith("NN_") ||
+ file.endsWith(".pdf")
+ ) {
+ await RNFetchBlob.fs.unlink(file).catch(() => {
+ /* empty */
+ });
+ }
}
- }
+ } catch (e) {}
}
export async function getCachePathForFile(filename: string) {
diff --git a/apps/mobile/app/hooks/use-app-events.tsx b/apps/mobile/app/hooks/use-app-events.tsx
index a1db09c94..b08964619 100644
--- a/apps/mobile/app/hooks/use-app-events.tsx
+++ b/apps/mobile/app/hooks/use-app-events.tsx
@@ -107,6 +107,7 @@ import { fluidTabsRef } from "../utils/global-refs";
import { NotesnookModule } from "../utils/notesnook-module";
import { sleep } from "../utils/time";
import useFeatureManager from "./use-feature-manager";
+import { deleteDCacheFiles } from "../common/filesystem/io";
const onCheckSyncStatus = async (type: SyncStatusEvent) => {
const { disableSync, disableAutoSync } = SettingsService.get();
@@ -457,6 +458,7 @@ const initializeDatabase = async (password?: string) => {
Notifications.setupReminders(true);
DatabaseLogger.info("Database initialized");
Notifications.restorePinnedNotes();
+ deleteDCacheFiles();
}
Walkthrough.init();
};