Skip to content

Commit

Permalink
feat: add workaround for corrupted storage
Browse files Browse the repository at this point in the history
  • Loading branch information
PalmDevs authored and PalmDevs committed Feb 25, 2024
1 parent d3a6a3c commit 44867fc
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/lib/storage/backends.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>): StorageBackend => {
let created: boolean;
return {
Expand All @@ -74,4 +79,4 @@ export const createFileBackend = (file: string, migratePromise?: Promise<void>):
await FileManager.writeFile("documents", filePathFixer(file), JSON.stringify(data), "utf8");
}
};
};
};
37 changes: 36 additions & 1 deletion src/ui/settings/pages/General.tsx
Original file line number Diff line number Diff line change
@@ -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();
Expand Down Expand Up @@ -140,6 +142,39 @@ export default function General() {
))}
</Summary>
</FormSection>
<FormSection title="Advanced">
<FormRow
label="Clear plugin storage"
leading={<FormRow.Icon source={getAssetIDByName("ic_message_delete")} />}
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()
},
})}
/>
<FormDivider />
<FormRow
label="Clear theme storage"
leading={<FormRow.Icon source={getAssetIDByName("ic_message_delete")} />}
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()
},
})}
/>
</FormSection>
</RN.ScrollView>
</ErrorBoundary>
)
Expand Down

0 comments on commit 44867fc

Please sign in to comment.