Skip to content

Commit

Permalink
Reduce unecessary background pressure on fetch event
Browse files Browse the repository at this point in the history
  • Loading branch information
bgoncal committed Feb 24, 2025
1 parent b1ce696 commit 2694f82
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 14 deletions.
15 changes: 1 addition & 14 deletions Sources/App/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -206,20 +206,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
_ application: UIApplication,
performFetchWithCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void
) {
let timestamp = DateFormatter.localizedString(from: Date(), dateStyle: .medium, timeStyle: .full)
Current.Log.verbose("Background fetch activated at \(timestamp)!")

DataWidgetsUpdater.update()

#if !targetEnvironment(macCatalyst)
if UIDevice.current.userInterfaceIdiom == .phone, case .paired = Communicator.shared.currentWatchState {
Current.Log.verbose("Requesting watch sync from background fetch")
Communicator.shared.send(GuaranteedMessage(identifier: GuaranteedMessages.sync.rawValue)) { error in
Current.Log.error("Failed to request watch sync from background fetch: \(error)")
}
}
#endif

Current.clientEventStore.addEvent(ClientEvent(text: "Background fetch activated", type: .backgroundOperation))
Current.backgroundTask(withName: "background-fetch") { remaining in
let updatePromise: Promise<Void>
if Current.settingsStore.isLocationEnabled(for: UIApplication.shared.applicationState),
Expand Down
1 change: 1 addition & 0 deletions Sources/Shared/ClientEvents/Model/ClientEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public struct ClientEvent: Codable, FetchableRecord, PersistableRecord {
case networkRequest
case settings
case database
case backgroundOperation
case unknown
}

Expand Down

0 comments on commit 2694f82

Please sign in to comment.