You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
151 lines
4.6 KiB
151 lines
4.6 KiB
//
|
|
// DebugSettingsView.swift
|
|
// PadelClub
|
|
//
|
|
// Created by Laurent Morvillier on 28/05/2024.
|
|
//
|
|
|
|
import SwiftUI
|
|
import LeStorage
|
|
import PadelClubData
|
|
|
|
struct DebugSettingsView: View {
|
|
@State private var errorMessage: String?
|
|
@State private var showingError = false
|
|
@State private var isSynchronizing = false
|
|
|
|
var body: some View {
|
|
List {
|
|
|
|
Section("Status") {
|
|
LabeledContent("Has Websocket Manager", value: self._hasWebSocketManager)
|
|
LabeledContent("Websocket ping", value: self._wsPingStatus)
|
|
LabeledContent("Websocket failure", value: self._wsFailure)
|
|
if let error = self._wsError {
|
|
LabeledContent("Websocket error", value: error)
|
|
LabeledContent("Reconnect attempts", value: StoreCenter.main.websocketReconnectAttempts.formatted())
|
|
}
|
|
LabeledContent("Last synced object date", value: self._lastSyncDate)
|
|
if isSynchronizing {
|
|
HStack {
|
|
ProgressView()
|
|
.scaleEffect(0.8)
|
|
Text("Synchronizing...")
|
|
.foregroundColor(.secondary)
|
|
}
|
|
} else {
|
|
Button("Synchronize") {
|
|
self._synchronize()
|
|
}
|
|
}
|
|
}
|
|
|
|
Section("Settings") {
|
|
LabeledContent("UUID", value: self._userId)
|
|
LabeledContent("User Name", value: self._userName)
|
|
LabeledContent("Token", value: self._token)
|
|
LabeledContent("Server", value: self._apiURL)
|
|
LabeledContent("Synchronized", value: self._synchronized)
|
|
LabeledContent("Plan", value: Guard.main.currentPlan?.id ?? "None")
|
|
|
|
NavigationLink {
|
|
List {
|
|
ForEach(DataStore.shared.purchases) { purchase in
|
|
DebugPurchaseView(purchase: purchase)
|
|
}
|
|
}
|
|
} label: {
|
|
LabeledContent("Purchases", value: DataStore.shared.purchases.count.formatted())
|
|
}
|
|
|
|
}
|
|
}
|
|
.alert("Synchronization Error", isPresented: $showingError) {
|
|
Button("OK") { }
|
|
} message: {
|
|
Text(errorMessage ?? "An unknown error occurred")
|
|
}
|
|
}
|
|
|
|
fileprivate var _userId: String {
|
|
return StoreCenter.main.userId ?? ""
|
|
}
|
|
|
|
fileprivate var _userName: String {
|
|
return StoreCenter.main.userName ?? ""
|
|
}
|
|
|
|
fileprivate var _token: String {
|
|
let token = try? StoreCenter.main.token()
|
|
return token ?? ""
|
|
}
|
|
|
|
fileprivate var _apiURL: String {
|
|
return StoreCenter.main.apiURL ?? "not configured"
|
|
}
|
|
|
|
fileprivate var _synchronized: String {
|
|
if let synchronized = PListReader.readBool(plist: "local", key: "synchronized") {
|
|
return "\(synchronized)"
|
|
} else {
|
|
return "not specified"
|
|
}
|
|
}
|
|
|
|
fileprivate var _wsPingStatus: String {
|
|
return "\(StoreCenter.main.websocketPingStatus)"
|
|
}
|
|
fileprivate var _wsFailure: String {
|
|
return "\(StoreCenter.main.websocketFailure)"
|
|
}
|
|
fileprivate var _wsError: String? {
|
|
if let error = StoreCenter.main.websocketError {
|
|
return error.localizedDescription
|
|
}
|
|
return nil
|
|
}
|
|
fileprivate var _hasWebSocketManager: String {
|
|
return "\(StoreCenter.main.hasWebSocketManager)"
|
|
}
|
|
fileprivate var _lastSyncDate: String {
|
|
return "\(StoreCenter.main.lastSyncDate)"
|
|
}
|
|
|
|
fileprivate func _synchronize() {
|
|
Logger.log("launch sync...")
|
|
Task {
|
|
await MainActor.run {
|
|
isSynchronizing = true
|
|
}
|
|
|
|
let error = await StoreCenter.main.synchronizeLastUpdates()
|
|
if let error {
|
|
await MainActor.run {
|
|
errorMessage = error.localizedDescription
|
|
showingError = true
|
|
}
|
|
}
|
|
|
|
await MainActor.run {
|
|
isSynchronizing = false
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
struct DebugPurchaseView: View {
|
|
|
|
var purchase: Purchase
|
|
|
|
var body: some View {
|
|
VStack {
|
|
Text(purchase.productId)
|
|
LabeledContent(purchase.purchaseDate.formatted(), value: purchase.expirationDate?.formatted() ?? "")
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
//#Preview {
|
|
// DebugSettingsView()
|
|
//}
|
|
|