A gear on the feed opens a status overview that leads with what is wrong: offline hosts, hosts on a fallback route, tokens expiring within 7 days, and push problems, with healthy hosts folded into one row. Each host opens its route ladder with Reconnect. The notifications page shows registration, the last push, Send test and Unpair. Demo mode gains a Laptop on its VPN fallback, and snapshot tests render the three screens.
67 lines
2.1 KiB
Swift
67 lines
2.1 KiB
Swift
// App entry. Notification setup and APNs registration go through the WatchKit app delegate.
|
|
|
|
import SwiftUI
|
|
import WatchKit
|
|
|
|
@main
|
|
struct WristCodeApp: App {
|
|
@WKApplicationDelegateAdaptor(AppDelegate.self) private var delegate
|
|
@State private var model = AppModel.shared
|
|
|
|
var body: some Scene {
|
|
WindowGroup {
|
|
RootView()
|
|
.environment(model)
|
|
}
|
|
}
|
|
}
|
|
|
|
struct RootView: View {
|
|
@Environment(AppModel.self) private var model
|
|
|
|
var body: some View {
|
|
@Bindable var model = model
|
|
Group {
|
|
if model.mode == .unpaired {
|
|
PairView()
|
|
} else {
|
|
NavigationStack(path: $model.path) {
|
|
FeedView()
|
|
.navigationDestination(for: Route.self) { route in
|
|
switch route {
|
|
case let .thread(hostId, threadId):
|
|
ThreadView(hostId: hostId, threadId: threadId)
|
|
case .newThread:
|
|
NewThreadView()
|
|
case .status:
|
|
StatusView()
|
|
case let .host(id):
|
|
HostStatusView(hostId: id)
|
|
case .notifications:
|
|
NotificationsView()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
.fontDesign(.rounded)
|
|
.tint(Theme.work)
|
|
.onOpenURL { model.open(url: $0) }
|
|
}
|
|
}
|
|
|
|
final class AppDelegate: NSObject, WKApplicationDelegate {
|
|
func applicationDidFinishLaunching() {
|
|
NotificationHandler.shared.install()
|
|
Task { await AppModel.shared.enableNotifications() }
|
|
}
|
|
|
|
func didRegisterForRemoteNotifications(withDeviceToken deviceToken: Data) {
|
|
AppModel.shared.didRegister(apnsToken: deviceToken)
|
|
}
|
|
|
|
func didFailToRegisterForRemoteNotificationsWithError(_ error: any Error) {
|
|
print("APNs registration failed: \(error.localizedDescription)")
|
|
}
|
|
}
|