Skip to content

Commit

Permalink
Refactor AppDelegate (milestone 1) (#3727)
Browse files Browse the repository at this point in the history
Task/Issue URL: https://app.asana.com/0/0/1208832732122403/f
Tech Design URL: https://app.asana.com/0/481882893211075/1208859623176995/f
CC: @bwaresiak 

**Description**:
- Migrate the app’s startup flow into a state machine with clearly
defined states, each specifying its dependencies to ensure the necessary
resources are available before execution.
- Keep the flow primarily synchronous as it currently is, with some
exceptions for existing async code.
- Define explicit state dependencies to avoid optional objects, ensuring
clarity about what exists in each state.
  • Loading branch information
jaceklyp authored Dec 28, 2024
1 parent 42228ca commit c3ae384
Show file tree
Hide file tree
Showing 27 changed files with 3,164 additions and 1,354 deletions.
10 changes: 0 additions & 10 deletions Core/Pixel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -165,16 +165,6 @@ 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
4 changes: 1 addition & 3 deletions Core/PixelEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,6 @@ extension Pixel {

// MARK: Lifecycle
case appDidTransitionToUnexpectedState
case appDidConsecutivelyBackground
}

}
Expand Down Expand Up @@ -1939,8 +1938,7 @@ extension Pixel.Event {
case .openAIChatFromAddressBar: return "m_aichat_addressbar_icon"

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

}
}
Expand Down
72 changes: 54 additions & 18 deletions DuckDuckGo.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

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

static var didStartBackgroundTaskTimestamp: Date?

enum BackgroundRefreshCompletionStatus {

case expired
Expand Down Expand Up @@ -134,7 +132,6 @@ 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
2 changes: 1 addition & 1 deletion DuckDuckGo/AppDelegate+AppDeepLinks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import UIKit
import Core

extension AppDelegate {
extension OldAppDelegate {

func handleAppDeepLink(_ app: UIApplication, _ mainViewController: MainViewController?, _ url: URL) -> Bool {
guard let mainViewController else { return false }
Expand Down
Loading

0 comments on commit c3ae384

Please sign in to comment.