diff --git a/Pocket Poster/Controllers/PosterBoardManager.swift b/Pocket Poster/Controllers/PosterBoardManager.swift index 9e7dcf9..5931c5b 100644 --- a/Pocket Poster/Controllers/PosterBoardManager.swift +++ b/Pocket Poster/Controllers/PosterBoardManager.swift @@ -150,4 +150,11 @@ class PosterBoardManager { 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) + } + } } diff --git a/Pocket Poster/Views/SettingsView.swift b/Pocket Poster/Views/SettingsView.swift index 09a8b6c..f354051 100644 --- a/Pocket Poster/Views/SettingsView.swift +++ b/Pocket Poster/Views/SettingsView.swift @@ -11,6 +11,10 @@ struct SettingsView: View { // Prefs @AppStorage("pbHash") var pbHash: String = "" + @State var showErrorAlert = false + @State var errorAlertTitle: String? + @State var errorAlertDescr: String? + var body: some View { ScrollView { Section { @@ -33,8 +37,29 @@ struct SettingsView: View { Text("Replay Tutorial") } .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() + .alert(errorAlertTitle ?? "Error", isPresented: $showErrorAlert) { + Button("OK") {} + } message: { + Text(errorAlertDescr ?? "???") + } } }