This commit is contained in:
fmodf 2024-10-04 17:58:04 +02:00
parent 5fe8762e1f
commit 50d64cf96b
4 changed files with 44 additions and 5 deletions

View file

@ -10,6 +10,7 @@ typealias DBStorable = Codable & FetchableRecord & Identifiable & PersistableRec
final class Database {
static let shared = Database()
let dbQueue: DatabaseQueue
private var dbPath: String
private init() {
do {
@ -25,6 +26,7 @@ final class Database {
// Open or create the database
let databaseURL = directoryURL.appendingPathComponent("db.sqlite")
dbQueue = try DatabaseQueue(path: databaseURL.path, configuration: Database.config)
dbPath = databaseURL.path
// Some debug info
#if DEBUG
@ -53,3 +55,17 @@ private extension Database {
return config
}()
}
// MARK: - flush all data for debug
#if DEBUG
extension Database {
func flushAllData() {
// nullable queue and remove db file
do {
try FileManager.default.removeItem(atPath: dbPath)
} catch {
print("Error: \(error)")
}
}
}
#endif

View file

@ -193,3 +193,16 @@ private extension ClientsStore {
}
}
}
// MARK: - Remove all data for debug
#if DEBUG
extension ClientsStore {
func flushAllData() {
clients.forEach { $0.disconnect() }
clients.removeAll()
actualRosters.removeAll()
actualChats.removeAll()
ready = false
}
}
#endif

View file

@ -59,7 +59,7 @@ struct ChatsCreateScreenMain: View {
print("Tapped findChannel")
}
// for contacts list
// for contacts list (later)
// let rosters = store.state.rostersState.rosters.filter { !$0.locallyDeleted }
// if rosters.isEmpty {
// ChatsCreateRowSeparator()

View file

@ -1,16 +1,26 @@
import SwiftUI
struct SettingsScreen: View {
@EnvironmentObject var clientsStore: ClientsStore
var body: some View {
ZStack {
// bg
Color.Material.Background.light
.ignoresSafeArea()
// content
Text("Soon!")
.font(.head1l)
// debug buttons
#if DEBUG
// clean all data
Button {
clientsStore.flushAllData()
Database.shared.flushAllData()
} label: {
Text("Clean all (for test)")
.font(.title)
.foregroundColor(.Material.Elements.active)
}
#endif
}
}
}