-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRavensApp.swift
132 lines (116 loc) · 4.97 KB
/
RavensApp.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
//
// RavensApp.swift
// Ravens
//
// Created by Eric de Quartel on 08/01/2024.
//
import SwiftUI
import SwiftyBeaver
import SwiftData
import BackgroundTasks
import UserNotifications
class URLHandler: ObservableObject {
@Published var urlString: String = ""
}
class AppDelegate: NSObject, UIApplicationDelegate {
let log = SwiftyBeaver.self
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
configureLogging()
return true
}
// Function to configure SwiftyBeaver logging
func configureLogging() {
// File logging destination
let file = FileDestination()
file.format = "$Dyyyy-MM-dd HH:mm:ss.SSS$d $C$L$c: $M" // full datetime, colored log level and message
file.minLevel = .warning
file.levelString.error = "Ravens"
file.logFileURL = URL(fileURLWithPath: "/Users/ericdequartel/Developer/_myApps/Ravens/ravens.log")
// Console logging destination
let console = ConsoleDestination()
console.levelString.error = "Ravens"
console.format = ">> $DHH:mm:ss.SSS$d $C$L$c: $M"
console.minLevel = .error
// Add both destinations to SwiftyBeaver
// log.addDestination(file)
log.addDestination(console)
}
}
@main
struct RavensApp: App {
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
@StateObject var locationManager = LocationManagerModel()
@StateObject var settings = Settings()
@StateObject var languagesViewModel = LanguagesViewModel()
@StateObject var speciesViewModel = SpeciesViewModel()
@StateObject var speciesGroupViewModel = SpeciesGroupsViewModel()
@StateObject var regionsViewModel = RegionsViewModel()
@StateObject var regionListViewModel = RegionListViewModel()
@StateObject private var observationsLocation = ObservationsViewModel()
@StateObject private var observationsSpeciesViewModel = ObservationsViewModel()
@StateObject private var observationsSpecies = ObservationsViewModel()
@StateObject private var observationsViewModel = ObservationsViewModel()
@StateObject private var observationsUser = ObservationsViewModel()
@StateObject var userViewModel = UserViewModel()
@StateObject var speciesDetailsViewModel = SpeciesDetailsViewModel()
@StateObject var poiViewModel = POIViewModel()
@StateObject var bookMarksViewModel = BookMarksViewModel(fileName: "bookmarks.json")
@StateObject var observersViewModel = ObserversViewModel() //??
@StateObject var areasViewModel = AreasViewModel() //??
@StateObject var geoJSONViewModel = GeoJSONViewModel()
@StateObject var locationViewModel = SearchLocationViewModel()
@StateObject var keychainViewModel = KeychainViewModel()
@StateObject private var accessibilityManager = AccessibilityManager()
@StateObject var player = Player()
@State private var showingAlert = false
@State private var parts: [String] = []
@State private var badgeCount: Int = 0
var body: some Scene {
WindowGroup {
ContentView(
observationUser: observationsUser,
observationsLocation : observationsLocation,
observationsSpecies: observationsSpecies
)
.environmentObject(keychainViewModel)
.environmentObject(locationManager)
.environmentObject(settings)
.environmentObject(languagesViewModel)
.environmentObject(speciesViewModel)
.environmentObject(speciesGroupViewModel)
.environmentObject(regionsViewModel)
.environmentObject(regionListViewModel)
.environmentObject(userViewModel)
.environmentObject(observationsSpeciesViewModel)
.environmentObject(poiViewModel)
.environmentObject(speciesDetailsViewModel)
.environmentObject(bookMarksViewModel)
.environmentObject(observersViewModel)
.environmentObject(areasViewModel)
.environmentObject(player)
.environmentObject(locationViewModel)
.environmentObject(accessibilityManager)
.environmentObject(geoJSONViewModel)
.onOpenURL { url in
// Handle the URL appropriately
let urlString = url.absoluteString.replacingOccurrences(of: "ravens://", with: "")
self.parts = urlString.split(separator: "/").map(String.init)
showingAlert = true
}
.alert(isPresented: $showingAlert) {
Alert(title: Text("Add Observer"),
message: Text("Do you want to append this \(parts[0].replacingOccurrences(of: "_", with: " ")) \(parts[1])?"),
primaryButton: .default(Text("Yes")) {
print("Appending \(parts[0]) \(parts[1])")
observersViewModel.appendRecord(name: self.parts[0], userID: Int(self.parts[1]) ?? 0)
},
secondaryButton: .cancel(Text("No")))
}
.onAppear {
// notificationsManager.requestNotificationPermission()
// timerManager.setNotificationsManager(notificationsManager)
// print("\(String(describing: locationManager.getCurrentLocation()))")
}
}
}
}