Stabilize iOS/watchOS/tvOS apps and add cross-platform audit remediation
This commit is contained in:
@@ -19,7 +19,7 @@ struct AllWorkoutsListView: View {
|
||||
@Binding var uniqueWorkoutUsers: [RegisteredUser]?
|
||||
@State private var filteredRegisterdUser: RegisteredUser?
|
||||
|
||||
@State var workouts: [Workout]
|
||||
let workouts: [Workout]
|
||||
let selectedWorkout: ((Workout) -> Void)
|
||||
@State var filteredWorkouts = [Workout]()
|
||||
var refresh: (() -> Void)
|
||||
@@ -38,19 +38,23 @@ struct AllWorkoutsListView: View {
|
||||
uniqueWorkoutUsers: $uniqueWorkoutUsers,
|
||||
filteredRegisterdUser: $filteredRegisterdUser,
|
||||
filteredWorkouts: $filteredWorkouts,
|
||||
workouts: $workouts,
|
||||
workouts: .constant(workouts),
|
||||
currentSort: $currentSort)
|
||||
}
|
||||
|
||||
ScrollView {
|
||||
LazyVStack(spacing: 10) {
|
||||
ForEach(filteredWorkouts, id:\.id) { workout in
|
||||
WorkoutOverviewView(workout: workout)
|
||||
.padding([.leading, .trailing], 4)
|
||||
.contentShape(Rectangle())
|
||||
.onTapGesture {
|
||||
selectedWorkout(workout)
|
||||
}
|
||||
Button(action: {
|
||||
selectedWorkout(workout)
|
||||
}, label: {
|
||||
WorkoutOverviewView(workout: workout)
|
||||
.padding([.leading, .trailing], 4)
|
||||
.contentShape(Rectangle())
|
||||
})
|
||||
.buttonStyle(.plain)
|
||||
.accessibilityLabel("Open \(workout.name)")
|
||||
.accessibilityHint("Shows workout details")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -71,6 +75,9 @@ struct AllWorkoutsListView: View {
|
||||
.onAppear{
|
||||
filterWorkouts()
|
||||
}
|
||||
.onChange(of: workouts) { _ in
|
||||
filterWorkouts()
|
||||
}
|
||||
}
|
||||
|
||||
func filterWorkouts() {
|
||||
|
||||
@@ -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"]
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user