Skip to content
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

Avoid AppTP DB initialization when disabled #2090

Merged
merged 3 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions DuckDuckGo/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

private lazy var privacyStore = PrivacyUserDefaults()
private var bookmarksDatabase: CoreDataDatabase = BookmarksDatabase.make()

#if APP_TRACKING_PROTECTION
private var appTrackingProtectionDatabase: CoreDataDatabase = AppTrackingProtectionDatabase.make()
#endif

private var autoClear: AutoClear?
private var showKeyboardIfSettingOn = true
private var lastBackgroundDate: Date?
Expand Down Expand Up @@ -183,6 +187,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
WidgetCenter.shared.reloadAllTimelines()
}

#if APP_TRACKING_PROTECTION
appTrackingProtectionDatabase.loadStore { context, error in
guard context != nil else {
if let error = error {
Expand All @@ -199,6 +204,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}
}
}
#endif

Favicons.shared.migrateFavicons(to: Favicons.Constants.maxFaviconSize) {
WidgetCenter.shared.reloadAllTimelines()
Expand Down Expand Up @@ -234,12 +240,20 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
syncService.initializeIfNeeded()
self.syncService = syncService

#if APP_TRACKING_PROTECTION
let main = MainViewController(bookmarksDatabase: bookmarksDatabase,
bookmarksDatabaseCleaner: syncDataProviders.bookmarksAdapter.databaseCleaner,
appTrackingProtectionDatabase: appTrackingProtectionDatabase,
syncService: syncService,
syncDataProviders: syncDataProviders,
appSettings: AppDependencyProvider.shared.appSettings)
#else
let main = MainViewController(bookmarksDatabase: bookmarksDatabase,
bookmarksDatabaseCleaner: syncDataProviders.bookmarksAdapter.databaseCleaner,
syncService: syncService,
syncDataProviders: syncDataProviders,
appSettings: AppDependencyProvider.shared.appSettings)
#endif
main.loadViewIfNeeded()

window = UIWindow(frame: UIScreen.main.bounds)
Expand Down
26 changes: 21 additions & 5 deletions DuckDuckGo/HomeViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,25 +69,41 @@ class HomeViewController: UIViewController {
private let appTPHomeViewModel: AppTPHomeViewModel
#endif

#if APP_TRACKING_PROTECTION
static func loadFromStoryboard(model: Tab, favoritesViewModel: FavoritesListInteracting, appTPDatabase: CoreDataDatabase) -> HomeViewController {
let storyboard = UIStoryboard(name: "Home", bundle: nil)
let controller = storyboard.instantiateViewController(identifier: "HomeViewController", creator: { coder in
HomeViewController(coder: coder, tabModel: model, favoritesViewModel: favoritesViewModel, appTPDatabase: appTPDatabase)
})
return controller
}

#else
static func loadFromStoryboard(model: Tab, favoritesViewModel: FavoritesListInteracting) -> HomeViewController {
let storyboard = UIStoryboard(name: "Home", bundle: nil)
let controller = storyboard.instantiateViewController(identifier: "HomeViewController", creator: { coder in
HomeViewController(coder: coder, tabModel: model, favoritesViewModel: favoritesViewModel)
})
return controller
}
#endif

#if APP_TRACKING_PROTECTION
required init?(coder: NSCoder, tabModel: Tab, favoritesViewModel: FavoritesListInteracting, appTPDatabase: CoreDataDatabase) {
self.tabModel = tabModel
self.favoritesViewModel = favoritesViewModel

#if APP_TRACKING_PROTECTION
self.appTPHomeViewModel = AppTPHomeViewModel(appTrackingProtectionDatabase: appTPDatabase)
#endif

super.init(coder: coder)
}

#else
required init?(coder: NSCoder, tabModel: Tab, favoritesViewModel: FavoritesListInteracting) {
self.tabModel = tabModel
self.favoritesViewModel = favoritesViewModel

super.init(coder: coder)
}
#endif

required init?(coder: NSCoder) {
fatalError("Not implemented")
}
Expand Down
34 changes: 32 additions & 2 deletions DuckDuckGo/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,11 @@ class MainViewController: UIViewController {
let previewsSource = TabPreviewsSource()
let appSettings: AppSettings
private var launchTabObserver: LaunchTabNotification.Observer?


#if APP_TRACKING_PROTECTION
private let appTrackingProtectionDatabase: CoreDataDatabase
#endif

let bookmarksDatabase: CoreDataDatabase
private weak var bookmarksDatabaseCleaner: BookmarkDatabaseCleaner?
private let favoritesViewModel: FavoritesListInteracting
Expand Down Expand Up @@ -128,6 +131,7 @@ class MainViewController: UIViewController {

var viewCoordinator: MainViewCoordinator!

#if APP_TRACKING_PROTECTION
init(
bookmarksDatabase: CoreDataDatabase,
bookmarksDatabaseCleaner: BookmarkDatabaseCleaner,
Expand All @@ -149,6 +153,27 @@ class MainViewController: UIViewController {

bindSyncService()
}
#else
init(
bookmarksDatabase: CoreDataDatabase,
bookmarksDatabaseCleaner: BookmarkDatabaseCleaner,
syncService: DDGSyncing,
syncDataProviders: SyncDataProviders,
appSettings: AppSettings
) {
self.bookmarksDatabase = bookmarksDatabase
self.bookmarksDatabaseCleaner = bookmarksDatabaseCleaner
self.syncService = syncService
self.syncDataProviders = syncDataProviders
self.favoritesViewModel = FavoritesListViewModel(bookmarksDatabase: bookmarksDatabase)
self.bookmarksCachingSearch = BookmarksCachingSearch(bookmarksStore: CoreDataBookmarksSearchStore(bookmarksStore: bookmarksDatabase))
self.appSettings = appSettings

super.init(nibName: nil, bundle: nil)

bindSyncService()
}
#endif

fileprivate var tabCountInfo: TabCountInfo?

Expand Down Expand Up @@ -554,10 +579,15 @@ class MainViewController: UIViewController {
AppDependencyProvider.shared.homePageConfiguration.refresh()

let tabModel = currentTab?.tabModel

#if APP_TRACKING_PROTECTION
let controller = HomeViewController.loadFromStoryboard(model: tabModel!,
favoritesViewModel: favoritesViewModel,
appTPDatabase: appTrackingProtectionDatabase)

#else
let controller = HomeViewController.loadFromStoryboard(model: tabModel!, favoritesViewModel: favoritesViewModel)
#endif

homeController = controller

controller.chromeDelegate = self
Expand Down
Loading