Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VIT-7771: Fix deprioritized resources not making forward progress in some environments #253

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions Sources/VitalHealthKit/HealthKit/AppStateTracker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ final class AppStateTracker {

@objc
func appDidFinishLaunching() {
if UIApplication.shared.applicationState == .background {
transition(to: .background)
// UIApplication.applicationState is always `.background` in this moment.
// Schedule a check on the next runloop iteration.
DispatchQueue.main.async {
self.powerStateDidChange()
}
}

Expand All @@ -74,7 +76,8 @@ final class AppStateTracker {

@objc
func powerStateDidChange() {
transition(to: UIApplication.shared.applicationState == .background ? .background : .foreground)
let state = UIApplication.shared.applicationState
transition(to: state == .background ? .background : .foreground)
}

func transition(to newStatus: AppState.Status) {
Expand Down
4 changes: 3 additions & 1 deletion Sources/VitalHealthKit/HealthKit/VitalHealthKitClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,9 @@ extension VitalHealthKitClient {
// OR has no sync attempt
// OR has errored
let lastStatus = resourceProgress.latestSync?.lastStatus
return lastStatus == nil || lastStatus == .error || lastStatus == .cancelled || lastStatus == .timedOut

return lastStatus == nil || lastStatus == .error || lastStatus == .cancelled
|| lastStatus == .timedOut || lastStatus == .started || lastStatus == .deprioritized
}

// Rescue these resources
Expand Down