Stabilize iOS/watchOS/tvOS apps and add cross-platform audit remediation

This commit is contained in:
Trey t
2026-02-11 12:54:40 -06:00
parent e40275e694
commit acce712261
77 changed files with 2940 additions and 765 deletions

View File

@@ -8,6 +8,7 @@
import Foundation
import SwiftUI
import HealthKit
import SharedCore
enum MainViewTypes: Int, CaseIterable {
case AllWorkout = 0
@@ -33,6 +34,7 @@ struct AllWorkoutsView: View {
@State public var needsUpdating: Bool = true
@ObservedObject var dataStore = DataStore.shared
@ObservedObject var userStore = UserStore.shared
@State private var showWorkoutDetail = false
@State private var selectedWorkout: Workout? {
@@ -50,8 +52,9 @@ struct AllWorkoutsView: View {
@State private var showLoginView = false
@State private var selectedSegment: MainViewTypes = .AllWorkout
@State var selectedDate: Date = Date()
private let runtimeReporter = RuntimeReporter.shared
let pub = NotificationCenter.default.publisher(for: NSNotification.Name("CreatedNewWorkout"))
let pub = NotificationCenter.default.publisher(for: AppNotifications.createdNewWorkout)
var body: some View {
ZStack {
@@ -76,12 +79,12 @@ struct AllWorkoutsView: View {
selectedWorkout = workout
}, refresh: {
self.needsUpdating = true
maybeUpdateShit()
maybeRefreshData()
})
Divider()
case .MyWorkouts:
PlannedWorkoutView(workouts: UserStore.shared.plannedWorkouts,
PlannedWorkoutView(workouts: userStore.plannedWorkouts,
selectedPlannedWorkout: $selectedPlannedWorkout)
}
}
@@ -93,7 +96,7 @@ struct AllWorkoutsView: View {
.onAppear{
// UserStore.shared.logout()
authorizeHealthKit()
maybeUpdateShit()
maybeRefreshData()
}
.sheet(item: $selectedWorkout) { item in
let isPreview = item.id == bridgeModule.currentWorkoutInfo.workout?.id
@@ -107,20 +110,20 @@ struct AllWorkoutsView: View {
.sheet(isPresented: $showLoginView) {
LoginView(completion: {
self.needsUpdating = true
maybeUpdateShit()
maybeRefreshData()
})
.interactiveDismissDisabled()
}
.onReceive(pub) { (output) in
self.needsUpdating = true
maybeUpdateShit()
maybeRefreshData()
}
}
func maybeUpdateShit() {
if UserStore.shared.token != nil{
if UserStore.shared.plannedWorkouts.isEmpty {
UserStore.shared.fetchPlannedWorkouts()
func maybeRefreshData() {
if userStore.token != nil{
if userStore.plannedWorkouts.isEmpty {
userStore.fetchPlannedWorkouts()
}
if needsUpdating {
@@ -128,6 +131,7 @@ struct AllWorkoutsView: View {
dataStore.fetchAllData(completion: {
DispatchQueue.main.async {
guard let allWorkouts = dataStore.allWorkouts else {
self.isUpdating = false
return
}
self.workouts = allWorkouts.sorted(by: {
@@ -140,22 +144,31 @@ struct AllWorkoutsView: View {
})
}
} else {
isUpdating = false
showLoginView = true
}
}
func authorizeHealthKit() {
let healthKitTypes: Set = [
HKObjectType.quantityType(forIdentifier: .heartRate)!,
HKObjectType.quantityType(forIdentifier: .activeEnergyBurned)!,
HKObjectType.quantityType(forIdentifier: .oxygenSaturation)!,
HKObjectType.activitySummaryType(),
HKQuantityType.workoutType()
]
let quantityTypes = [
HKObjectType.quantityType(forIdentifier: .heartRate),
HKObjectType.quantityType(forIdentifier: .activeEnergyBurned),
HKObjectType.quantityType(forIdentifier: .oxygenSaturation)
].compactMap { $0 }
let healthKitTypes: Set<HKObjectType> = Set(
quantityTypes + [
HKObjectType.activitySummaryType(),
HKQuantityType.workoutType()
]
)
healthStore.requestAuthorization(toShare: nil, read: healthKitTypes) { (succ, error) in
if !succ {
// fatalError("Error requesting authorization from health store: \(String(describing: error)))")
healthStore.requestAuthorization(toShare: nil, read: healthKitTypes) { (success, error) in
if success == false {
runtimeReporter.recordWarning(
"HealthKit authorization request did not succeed",
metadata: ["error": error?.localizedDescription ?? "unknown"]
)
}
}
}