Skip to content

Commit

Permalink
Merge branch 'main' into jacek/refactor-app-delegate-m1
Browse files Browse the repository at this point in the history
  • Loading branch information
jaceklyp committed Dec 20, 2024
2 parents ff80734 + c4ac58d commit d5663f3
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
10 changes: 10 additions & 0 deletions Core/Pixel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,16 @@ public struct PixelParameters {

public static let appState = "state"
public static let appEvent = "event"

public static let firstBackgroundTimestamp = "firstBackgroundTimestamp"
public static let secondBackgroundTimestamp = "secondBackgroundTimestamp"
public static let didReceiveMemoryWarningTimestamp = "didReceiveMemoryWarningTimestamp"
public static let didReceiveMXPayloadTimestamp = "didReceiveMXPayloadTimestamp"
public static let didReceiveUNNotification = "didReceiveUNNotification"
public static let didStartRemoteMessagingClientBackgroundTask = "didStartRemoteMessagingClientBackgroundTask"
public static let didStartAppConfigurationFetchBackgroundTask = "didStartAppConfigurationFetchBackgroundTask"
public static let didPerformFetchTimestamp = "didPerformFetchTimestamp"
public static let numberOfBackgrounds = "numberOfBackgrounds"
}

public struct PixelValues {
Expand Down
2 changes: 2 additions & 0 deletions Core/PixelEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,7 @@ extension Pixel {

// MARK: Lifecycle
case appDidTransitionToUnexpectedState
case appDidConsecutivelyBackground
}

}
Expand Down Expand Up @@ -1891,6 +1892,7 @@ extension Pixel.Event {

// MARK: Lifecycle
case .appDidTransitionToUnexpectedState: return "m_debug_app-did-transition-to-unexpected-state-2"
case .appDidConsecutivelyBackground: return "m_debug_app-did-consecutively-background"

}
}
Expand Down
3 changes: 3 additions & 0 deletions DuckDuckGo/AppConfigurationFetch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ class AppConfigurationFetch {
return Date().timeIntervalSince(Self.lastConfigurationRefreshDate) > Constants.minimumConfigurationRefreshInterval
}

static var didStartBackgroundTaskTimestamp: Date?

enum BackgroundRefreshCompletionStatus {

case expired
Expand Down Expand Up @@ -132,6 +134,7 @@ class AppConfigurationFetch {

static func registerBackgroundRefreshTaskHandler() {
BGTaskScheduler.shared.register(forTaskWithIdentifier: Constants.backgroundProcessingTaskIdentifier, using: nil) { (task) in
didStartBackgroundTaskTimestamp = Date()
guard shouldRefresh else {
task.setTaskCompleted(success: true)
scheduleBackgroundRefreshTask()
Expand Down
5 changes: 4 additions & 1 deletion DuckDuckGo/RemoteMessagingClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ final class RemoteMessagingClient: RemoteMessagingProcessing {
let store: RemoteMessagingStoring
let remoteMessagingAvailabilityProvider: RemoteMessagingAvailabilityProviding

var didStartBackgroundTaskTimestamp: Date?

convenience init(
bookmarksDatabase: CoreDataDatabase,
appSettings: AppSettings,
Expand Down Expand Up @@ -113,7 +115,8 @@ extension RemoteMessagingClient {
let remoteMessagingAvailabilityProvider = remoteMessagingAvailabilityProvider
let store = store

BGTaskScheduler.shared.register(forTaskWithIdentifier: Constants.backgroundRefreshTaskIdentifier, using: nil) { task in
BGTaskScheduler.shared.register(forTaskWithIdentifier: Constants.backgroundRefreshTaskIdentifier, using: nil) { [weak self] task in
self?.didStartBackgroundTaskTimestamp = Date()
guard Self.shouldRefresh else {
task.setTaskCompleted(success: true)
Self.scheduleBackgroundRefreshTask()
Expand Down

0 comments on commit d5663f3

Please sign in to comment.