Skip to content

Commit

Permalink
Reduce unecessary background pressure on fetch event (#3456)
Browse files Browse the repository at this point in the history
  • Loading branch information
bgoncal authored Feb 24, 2025
1 parent 7ab6fda commit a39a2de
Show file tree
Hide file tree
Showing 4 changed files with 7 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/App/Resources/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@
"client_events.event_type.service_call" = "Service Call";
"client_events.event_type.settings" = "Settings";
"client_events.event_type.unknown" = "Unknown";
"client_events.event_type.background_operation" = "Background operation";
"client_events.no_events" = "No events";
"client_events.view.clear" = "Clear";
"client_events.view.clear_confirm.message" = "This cannot be undone.";
Expand Down
3 changes: 3 additions & 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 Expand Up @@ -137,6 +138,8 @@ public extension ClientEvent.EventType {
return L10n.ClientEvents.EventType.settings
case .database:
return L10n.ClientEvents.EventType.database
case .backgroundOperation:
return L10n.ClientEvents.EventType.backgroundOperation
}
}
}
2 changes: 2 additions & 0 deletions Sources/Shared/Resources/Swiftgen/Strings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,8 @@ public enum L10n {
public enum EventType {
/// All
public static var all: String { return L10n.tr("Localizable", "client_events.event_type.all") }
/// Background operation
public static var backgroundOperation: String { return L10n.tr("Localizable", "client_events.event_type.background_operation") }
/// Database
public static var database: String { return L10n.tr("Localizable", "client_events.event_type.database") }
/// Location Update
Expand Down

0 comments on commit a39a2de

Please sign in to comment.