|
|
|
|
@ -19,6 +19,8 @@ struct PadelClubApp: App { |
|
|
|
|
@State private var importObserverViewModel = ImportObserver() |
|
|
|
|
@Environment(\.horizontalSizeClass) var horizontalSizeClass |
|
|
|
|
|
|
|
|
|
@State var blockApp = false |
|
|
|
|
|
|
|
|
|
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate |
|
|
|
|
|
|
|
|
|
var presentError: Binding<Bool> { |
|
|
|
|
@ -62,54 +64,79 @@ struct PadelClubApp: App { |
|
|
|
|
|
|
|
|
|
var body: some Scene { |
|
|
|
|
WindowGroup { |
|
|
|
|
MainView() |
|
|
|
|
.environment(\.horizontalSizeClass, .compact) |
|
|
|
|
.alert(isPresented: presentError, error: registrationError) { |
|
|
|
|
Button("Contactez-nous") { |
|
|
|
|
_openMail() |
|
|
|
|
} |
|
|
|
|
Button("Annuler", role: .cancel) { |
|
|
|
|
registrationError = nil |
|
|
|
|
|
|
|
|
|
if self.blockApp { |
|
|
|
|
DownloadNewVersionView() |
|
|
|
|
} else { |
|
|
|
|
MainView() |
|
|
|
|
.environment(\.horizontalSizeClass, .compact) |
|
|
|
|
.alert(isPresented: presentError, error: registrationError) { |
|
|
|
|
Button("Contactez-nous") { |
|
|
|
|
_openMail() |
|
|
|
|
} |
|
|
|
|
Button("Annuler", role: .cancel) { |
|
|
|
|
registrationError = nil |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
.onOpenURL { url in |
|
|
|
|
.onOpenURL { url in |
|
|
|
|
#if targetEnvironment(simulator) |
|
|
|
|
#else |
|
|
|
|
_handleIncomingURL(url) |
|
|
|
|
_handleIncomingURL(url) |
|
|
|
|
#endif |
|
|
|
|
} |
|
|
|
|
.environmentObject(networkMonitor) |
|
|
|
|
.environmentObject(dataStore) |
|
|
|
|
.environment(importObserverViewModel) |
|
|
|
|
.environment(navigationViewModel) |
|
|
|
|
.accentColor(.master) |
|
|
|
|
.onAppear { |
|
|
|
|
} |
|
|
|
|
.environmentObject(networkMonitor) |
|
|
|
|
.environmentObject(dataStore) |
|
|
|
|
.environment(importObserverViewModel) |
|
|
|
|
.environment(navigationViewModel) |
|
|
|
|
.accentColor(.master) |
|
|
|
|
.onAppear { |
|
|
|
|
self._checkVersion() |
|
|
|
|
#if DEBUG |
|
|
|
|
print("Running in Debug mode") |
|
|
|
|
print("Running in Debug mode") |
|
|
|
|
#elseif TESTFLIGHT |
|
|
|
|
print("Running in TestFlight mode") |
|
|
|
|
print("Running in TestFlight mode") |
|
|
|
|
#elseif PRODTEST |
|
|
|
|
print("Running in ProdTest mode") |
|
|
|
|
print("Running in ProdTest mode") |
|
|
|
|
#else |
|
|
|
|
print("Running in Release mode") |
|
|
|
|
print("Running in Release mode") |
|
|
|
|
#endif |
|
|
|
|
networkMonitor.checkConnection() |
|
|
|
|
self._onAppear() |
|
|
|
|
print(PersistenceController.getModelVersion()) |
|
|
|
|
} |
|
|
|
|
.task { |
|
|
|
|
networkMonitor.checkConnection() |
|
|
|
|
self._onAppear() |
|
|
|
|
print(PersistenceController.getModelVersion()) |
|
|
|
|
} |
|
|
|
|
.task { |
|
|
|
|
|
|
|
|
|
try? Tips.resetDatastore() |
|
|
|
|
|
|
|
|
|
try? Tips.resetDatastore() |
|
|
|
|
try? Tips.configure([ |
|
|
|
|
.displayFrequency(.immediate), |
|
|
|
|
.datastoreLocation(.applicationDefault) |
|
|
|
|
]) |
|
|
|
|
} |
|
|
|
|
.environment(\.managedObjectContext, persistenceController.localContainer.viewContext) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
try? Tips.configure([ |
|
|
|
|
.displayFrequency(.immediate), |
|
|
|
|
.datastoreLocation(.applicationDefault) |
|
|
|
|
]) |
|
|
|
|
fileprivate func _checkVersion() { |
|
|
|
|
Task.detached(priority: .high) { |
|
|
|
|
if let requiredVersion = await self._retrieveRequiredVersion() { |
|
|
|
|
let cleanedRequired = requiredVersion.replacingOccurrences(of: "\n", with: "") |
|
|
|
|
Logger.log(">>> VERSION = \(requiredVersion)") |
|
|
|
|
if let currentVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String { |
|
|
|
|
await MainActor.run { |
|
|
|
|
self.blockApp = VersionComparator.compare(cleanedRequired, currentVersion) == 1 |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
.environment(\.managedObjectContext, persistenceController.localContainer.viewContext) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fileprivate func _retrieveRequiredVersion() async -> String? { |
|
|
|
|
let requiredVersionURL = URLs.main.extend(path: "static/misc/required-version.txt") |
|
|
|
|
return try? String(contentsOf: requiredVersionURL, encoding: .utf8) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private func _handleIncomingURL(_ url: URL) { |
|
|
|
|
// Parse the URL |
|
|
|
|
let pathComponents = url.pathComponents |
|
|
|
|
@ -173,3 +200,31 @@ print("Running in Release mode") |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct DownloadNewVersionView: View { |
|
|
|
|
|
|
|
|
|
var body: some View { |
|
|
|
|
|
|
|
|
|
VStack { |
|
|
|
|
// AngledStripesBackground() |
|
|
|
|
Spacer() |
|
|
|
|
Text("Veuillez télécharger la nouvelle version de Padel Club pour continuer à vous servir de l'app !") |
|
|
|
|
.padding(32.0) |
|
|
|
|
.background(.logoYellow) |
|
|
|
|
.clipShape(.buttonBorder) |
|
|
|
|
.foregroundStyle(.logoBackground) |
|
|
|
|
.fontWeight(.medium) |
|
|
|
|
.multilineTextAlignment(.center) |
|
|
|
|
.padding(.horizontal, 64.0) |
|
|
|
|
Image("logo").padding(.vertical, 50.0) |
|
|
|
|
Spacer() |
|
|
|
|
}.background(.logoBackground) |
|
|
|
|
.onTapGesture { |
|
|
|
|
UIApplication.shared.open(URLs.appStore.url) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|