-
Notifications
You must be signed in to change notification settings - Fork 432
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
Remove old app delegate, rename states and introduce Resuming (a.k.a willEnterForeground) #3809
Changes from 6 commits
7defe3a
b3ed395
11c9080
a7a8025
8d88041
f2860f9
d5ac91c
2b2c488
9483c31
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,22 +20,6 @@ | |
import UIKit | ||
import Core | ||
|
||
enum AppBehavior: String { | ||
|
||
case old | ||
case new | ||
|
||
} | ||
|
||
protocol DDGApp { | ||
|
||
var privacyProDataReporter: PrivacyProDataReporting? { get } | ||
|
||
func initialize() | ||
func refreshRemoteMessages() | ||
|
||
} | ||
|
||
@UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { | ||
|
||
static let ShowKeyboardOnLaunchThreshold = TimeInterval(20) | ||
|
@@ -45,65 +29,50 @@ protocol DDGApp { | |
static let openVPNSettings = "com.duckduckgo.mobile.ios.vpn.open-settings" | ||
} | ||
|
||
private let appStateMachine: AppStateMachine = AppStateMachine() | ||
|
||
var window: UIWindow? | ||
|
||
var privacyProDataReporter: PrivacyProDataReporting? { | ||
realDelegate.privacyProDataReporter | ||
} | ||
|
||
func forceOldAppDelegate() { | ||
BoolFileMarker(name: .forceOldAppDelegate)?.mark() | ||
} | ||
|
||
private let appBehavior: AppBehavior = { | ||
BoolFileMarker(name: .forceOldAppDelegate)?.isPresent == true ? .old : .new | ||
}() | ||
|
||
private lazy var realDelegate: UIApplicationDelegate & DDGApp = { | ||
if appBehavior == .old { | ||
return OldAppDelegate(with: self) | ||
} else { | ||
return NewAppDelegate() | ||
} | ||
}() | ||
|
||
var didCallWillEnterForeground: Bool = false | ||
|
||
override init() { | ||
super.init() | ||
realDelegate.initialize() | ||
(appStateMachine.currentState as? Foreground)?.appDependencies.privacyProDataReporter // just for now, we have to get rid of this anti pattern | ||
} | ||
|
||
/// See: Launching.swift | ||
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { | ||
realDelegate.application?(application, didFinishLaunchingWithOptions: launchOptions) ?? false | ||
let isTesting: Bool = ProcessInfo().arguments.contains("testing") | ||
appStateMachine.handle(.didFinishLaunching(application, isTesting: isTesting)) | ||
return true | ||
} | ||
|
||
/// See: Foreground.swift | ||
func applicationDidBecomeActive(_ application: UIApplication) { | ||
didCallWillEnterForeground = false | ||
realDelegate.applicationDidBecomeActive?(application) | ||
appStateMachine.handle(.didBecomeActive) | ||
} | ||
|
||
/// See: Suspending.swift | ||
func applicationWillResignActive(_ application: UIApplication) { | ||
realDelegate.applicationWillResignActive?(application) | ||
appStateMachine.handle(.willResignActive) | ||
} | ||
|
||
/// See: Resuming.swift | ||
func applicationWillEnterForeground(_ application: UIApplication) { | ||
didCallWillEnterForeground = true | ||
realDelegate.applicationWillEnterForeground?(application) | ||
appStateMachine.handle(.willEnterForeground) | ||
} | ||
|
||
/// See: Background.swift | ||
func applicationDidEnterBackground(_ application: UIApplication) { | ||
realDelegate.applicationDidEnterBackground?(application) | ||
appStateMachine.handle(.didEnterBackground) | ||
} | ||
|
||
func application(_ application: UIApplication, | ||
performActionFor shortcutItem: UIApplicationShortcutItem, | ||
completionHandler: @escaping (Bool) -> Void) { | ||
realDelegate.application?(application, performActionFor: shortcutItem, completionHandler: completionHandler) | ||
appStateMachine.handle(.handleShortcutItem(shortcutItem)) | ||
} | ||
|
||
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool { | ||
realDelegate.application?(app, open: url, options: options) ?? false | ||
appStateMachine.handle(.openURL(url)) | ||
return true | ||
} | ||
|
||
func application(_ application: UIApplication, performFetchWithCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) { | ||
|
@@ -121,12 +90,12 @@ protocol DDGApp { | |
} | ||
|
||
func application(_ application: UIApplication, willContinueUserActivityWithType userActivityType: String) -> Bool { | ||
return true | ||
true | ||
} | ||
|
||
/// It's public in order to allow refreshing on demand via Debug menu. Otherwise it shouldn't be called from outside. | ||
func refreshRemoteMessages() { | ||
realDelegate.refreshRemoteMessages() | ||
// part of debug menu, let's not support it in the first iteration | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we'll need this now, won't we? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it doesn't work now, as we already use new app delegate by default, but you are correct, this should be brought back, I'll make it work in next PR There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I fixed it in this PR! |
||
} | ||
|
||
} | ||
|
@@ -153,19 +122,10 @@ extension Error { | |
let nsError = self as NSError | ||
if let underlyingError = nsError.userInfo["NSUnderlyingError"] as? NSError, underlyingError.code == 13 { | ||
return true | ||
} | ||
|
||
if nsError.userInfo["NSSQLiteErrorDomain"] as? Int == 13 { | ||
} else if nsError.userInfo["NSSQLiteErrorDomain"] as? Int == 13 { | ||
return true | ||
} | ||
|
||
return false | ||
} | ||
|
||
} | ||
|
||
private extension BoolFileMarker.Name { | ||
|
||
static let forceOldAppDelegate = BoolFileMarker.Name(rawValue: "force-old-app-delegate") | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we ok with always returning
true
here? I saw there'sfalse
supposed to be returned when onboarding is present (based on the Old Delegate).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I saw this and AFAIU the documentation correctly we can always return true, just like we do inside didFInishLaunching but we do not necessarily have to handle the opening url logic, hence the code inside Foreground state:
guard mainViewController.needsToShowOnboardingIntro() == false else {
return
}