From 44867fc99274c80864782fc59f2f90e32ccca80a Mon Sep 17 00:00:00 2001 From: PalmDevs Date: Sun, 25 Feb 2024 21:05:09 +0700 Subject: [PATCH] feat: add workaround for corrupted storage --- src/lib/storage/backends.ts | 7 +++++- src/ui/settings/pages/General.tsx | 37 ++++++++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/src/lib/storage/backends.ts b/src/lib/storage/backends.ts index 8a544c12..73c29586 100644 --- a/src/lib/storage/backends.ts +++ b/src/lib/storage/backends.ts @@ -60,6 +60,11 @@ export const createMMKVBackend = (store: string) => { })()); } +export const removeMMKVBackend = (store: string) => { + const mmkvPath = getMMKVPath(store); + return FileManager.removeFile('documents', filePathFixer(mmkvPath)) +} + export const createFileBackend = (file: string, migratePromise?: Promise): StorageBackend => { let created: boolean; return { @@ -74,4 +79,4 @@ export const createFileBackend = (file: string, migratePromise?: Promise): await FileManager.writeFile("documents", filePathFixer(file), JSON.stringify(data), "utf8"); } }; -}; +}; \ No newline at end of file diff --git a/src/ui/settings/pages/General.tsx b/src/ui/settings/pages/General.tsx index 5c9bec31..1cf5d240 100644 --- a/src/ui/settings/pages/General.tsx +++ b/src/ui/settings/pages/General.tsx @@ -1,12 +1,14 @@ import { ReactNative as RN, url } from "@metro/common"; import { DISCORD_SERVER, GITHUB } from "@lib/constants"; import { getDebugInfo, toggleSafeMode } from "@lib/debug"; -import { useProxy } from "@lib/storage"; +import { removeMMKVBackend, useProxy } from "@lib/storage"; import { BundleUpdaterManager } from "@lib/native"; import { getAssetIDByName } from "@ui/assets"; import { Forms, Summary, ErrorBoundary } from "@ui/components"; import settings from "@lib/settings"; import Version from "@ui/settings/components/Version"; +import { showConfirmationAlert } from '@ui/alerts' +import { ButtonColors } from '@types' const { FormRow, FormSwitchRow, FormSection, FormDivider } = Forms; const debugInfo = getDebugInfo(); @@ -140,6 +142,39 @@ export default function General() { ))} + + } + onPress={() => showConfirmationAlert({ + title: "Clear plugin storage?", + content: "All installed plugins will be removed and the app will be reloaded. Plugin settings will still be retained. This is only neccessary if you have a corrupted storage.", + confirmText: "Yes, I have a corrupted storage", + cancelText: "Cancel", + confirmColor: ButtonColors.RED, + onConfirm: () => { + removeMMKVBackend('VENDETTA_PLUGINS') + BundleUpdaterManager.reload() + }, + })} + /> + + } + onPress={() => showConfirmationAlert({ + title: "Clear theme storage?", + content: "All installed themes will be removed and the app will be reloaded. This is only neccessary if you have a corrupted storage.", + confirmText: "Yes, I have a corrupted storage", + cancelText: "Cancel", + confirmColor: ButtonColors.RED, + onConfirm: () => { + removeMMKVBackend('VENDETTA_THEMES') + BundleUpdaterManager.reload() + }, + })} + /> + )