button to clear app cached files

This commit is contained in:
leminlimez committed 2025-06-01 06:55:10 -04:00
1 parent 67c3fdb36a
commit 7c0cb386a7
2 files changed
+32

No files matched your search

@@ -150,4 +150,11 @@ class PosterBoardManager {
try? FileManager.default.removeItem(at: descriptors) try? FileManager.default.removeItem(at: descriptors)
} }
} }
static func clearCache() throws {
let docDir = SymHandler.getDocumentsDirectory()
for file in try FileManager.default.contentsOfDirectory(at: docDir, includingPropertiesForKeys: nil) {
try FileManager.default.removeItem(at: file)
}
}
} }
+25
View File
@@ -11,6 +11,10 @@ struct SettingsView: View {
// Prefs // Prefs
@AppStorage("pbHash") var pbHash: String = "" @AppStorage("pbHash") var pbHash: String = ""
@State var showErrorAlert = false
@State var errorAlertTitle: String?
@State var errorAlertDescr: String?
var body: some View { var body: some View {
ScrollView { ScrollView {
Section { Section {
@@ -33,8 +37,29 @@ struct SettingsView: View {
Text("Replay Tutorial") Text("Replay Tutorial")
} }
.buttonStyle(TintedButton(color: .blue, fullwidth: true)) .buttonStyle(TintedButton(color: .blue, fullwidth: true))
Button(action: {
do {
try PosterBoardManager.clearCache()
errorAlertTitle = "App Cache Successfully Cleared!"
errorAlertDescr = ""
showErrorAlert = true
} catch {
errorAlertTitle = "Error"
errorAlertDescr = error.localizedDescription
showErrorAlert = true
}
}) {
Text("Clear App Cache")
}
.buttonStyle(TintedButton(color: .red, fullwidth: true))
} }
} }
.padding() .padding()
.alert(errorAlertTitle ?? "Error", isPresented: $showErrorAlert) {
Button("OK") {}
} message: {
Text(errorAlertDescr ?? "???")
}
} }
} }