disconnect users + remove websocket connection

sync_v2
Laurent 8 months ago
parent f892a05851
commit 5708c9a9d8
  1. 2
      PadelClub/Data/DataStore.swift
  2. 14
      PadelClub/PadelClubApp.swift
  3. 40
      PadelClub/Utils/Patcher.swift

@ -134,7 +134,7 @@ class DataStore: ObservableObject {
} }
if Store.main.fileCollectionsAllLoaded() { if Store.main.fileCollectionsAllLoaded() {
Patcher.applyAllWhenApplicable() AutomaticPatcher.applyAllWhenApplicable()
} }
} }

@ -17,6 +17,7 @@ struct PadelClubApp: App {
@StateObject var dataStore = DataStore.shared @StateObject var dataStore = DataStore.shared
@State private var registrationError: RegistrationError? = nil @State private var registrationError: RegistrationError? = nil
@State private var importObserverViewModel = ImportObserver() @State private var importObserverViewModel = ImportObserver()
@State private var showDisconnectionAlert: Bool = false
@Environment(\.horizontalSizeClass) var horizontalSizeClass @Environment(\.horizontalSizeClass) var horizontalSizeClass
@State var requiredVersion: String? = nil @State var requiredVersion: String? = nil
@ -91,6 +92,10 @@ struct PadelClubApp: App {
.accentColor(.master) .accentColor(.master)
.onAppear { .onAppear {
self._checkVersion() self._checkVersion()
if ManualPatcher.patchIfPossible(.disconnect) == true {
self.showDisconnectionAlert = true
}
#if DEBUG #if DEBUG
print("Running in Debug mode") print("Running in Debug mode")
#elseif TESTFLIGHT #elseif TESTFLIGHT
@ -104,6 +109,9 @@ struct PadelClubApp: App {
self._onAppear() self._onAppear()
print(PersistenceController.getModelVersion()) print(PersistenceController.getModelVersion())
} }
.alert(isPresented: self.$showDisconnectionAlert, content: {
Alert(title: Text("Vous avez été déconnecté. Veuillez vous reconnecter pour récupérer vos données."))
})
.task { .task {
// try? Tips.resetDatastore() // try? Tips.resetDatastore()
@ -255,6 +263,12 @@ struct DownloadNewVersionView: View {
} }
struct DisconnectionAlertView: View {
var body: some View {
Text("Vous avez été déconnecté. Veuillez vous reconnecter pour récupérer vos données.").multilineTextAlignment(.center).padding()
}
}
#Preview { #Preview {
DownloadNewVersionView(version: "1.2") DownloadNewVersionView(version: "1.2")
} }

@ -8,6 +8,44 @@
import Foundation import Foundation
import LeStorage import LeStorage
enum ManualPatch: String {
case disconnect
var id: String {
return "padelclub.app.manual.patch.\(self.rawValue)"
}
}
class ManualPatcher {
static func patchIfPossible(_ patch: ManualPatch) -> Bool {
if UserDefaults.standard.value(forKey: patch.id) == nil {
do {
Logger.log(">>> Patches \(patch.rawValue)...")
let result = try self._applyPatch(patch)
UserDefaults.standard.setValue(true, forKey: patch.id)
return result
} catch {
Logger.error(error)
}
}
return false
}
fileprivate static func _applyPatch(_ patch: ManualPatch) throws -> Bool {
switch patch {
case .disconnect:
let rawToken = try? StoreCenter.main.rawTokenShouldNotBeUsed()
if StoreCenter.main.userName != nil || StoreCenter.main.userId != nil || rawToken != nil {
DataStore.shared.disconnect()
return true
} else {
return false
}
}
}
}
enum PatchError: Error { enum PatchError: Error {
case patchError(message: String) case patchError(message: String)
} }
@ -21,7 +59,7 @@ enum Patch: String, CaseIterable {
} }
} }
class Patcher { class AutomaticPatcher {
static func applyAllWhenApplicable() { static func applyAllWhenApplicable() {
for patch in Patch.allCases { for patch in Patch.allCases {

Loading…
Cancel
Save