Skip to content

Commit

Permalink
Simplify compilation for both build types.
Browse files Browse the repository at this point in the history
  • Loading branch information
samsymons committed Jan 17, 2024
1 parent a785cd6 commit 91f876c
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 59 deletions.
92 changes: 49 additions & 43 deletions DuckDuckGo/HomePage/Model/HomePageContinueSetUpModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,8 @@ extension HomePage.Models {
let deleteActionTitle = UserText.newTabSetUpRemoveItemAction
let privacyConfigurationManager: PrivacyConfigurationManaging

#if NETWORK_PROTECTION && DBP
let networkProtectionRemoteMessaging: NetworkProtectionRemoteMessaging
let networkProtectionUserDefaults: UserDefaults

let dataBrokerProtectionRemoteMessaging: DataBrokerProtectionRemoteMessaging
let dataBrokerProtectionUserDefaults: UserDefaults
#if NETWORK_PROTECTION || DBP
let homePageRemoteMessaging: HomePageRemoteMessaging
#endif

var isDay0SurveyEnabled: Bool {
Expand Down Expand Up @@ -138,55 +134,28 @@ extension HomePage.Models {

@Published var visibleFeaturesMatrix: [[FeatureType]] = [[]]

#if NETWORK_PROTECTION && DBP
init(defaultBrowserProvider: DefaultBrowserProvider,
dataImportProvider: DataImportStatusProviding,
tabCollectionViewModel: TabCollectionViewModel,
emailManager: EmailManager = EmailManager(),
privacyPreferences: PrivacySecurityPreferences = PrivacySecurityPreferences.shared,
duckPlayerPreferences: DuckPlayerPreferencesPersistor,
networkProtectionRemoteMessaging: NetworkProtectionRemoteMessaging,
dataBrokerProtectionRemoteMessaging: DataBrokerProtectionRemoteMessaging,
networkProtectionUserDefaults: UserDefaults,
dataBrokerProtectionUserDefaults: UserDefaults,
homePageRemoteMessaging: HomePageRemoteMessaging,
privacyConfigurationManager: PrivacyConfigurationManaging = AppPrivacyFeatures.shared.contentBlocking.privacyConfigurationManager) {
self.defaultBrowserProvider = defaultBrowserProvider
self.dataImportProvider = dataImportProvider
self.tabCollectionViewModel = tabCollectionViewModel
self.emailManager = emailManager
self.privacyPreferences = privacyPreferences
self.duckPlayerPreferences = duckPlayerPreferences
self.networkProtectionRemoteMessaging = networkProtectionRemoteMessaging
self.dataBrokerProtectionRemoteMessaging = dataBrokerProtectionRemoteMessaging
self.networkProtectionUserDefaults = networkProtectionUserDefaults
self.dataBrokerProtectionUserDefaults = dataBrokerProtectionUserDefaults
self.homePageRemoteMessaging = homePageRemoteMessaging
self.privacyConfigurationManager = privacyConfigurationManager

refreshFeaturesMatrix()

NotificationCenter.default.addObserver(self, selector: #selector(newTabOpenNotification(_:)), name: HomePage.Models.newHomePageTabOpen, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(windowDidBecomeKey(_:)), name: NSWindow.didBecomeKeyNotification, object: nil)
}
#else
init(defaultBrowserProvider: DefaultBrowserProvider,
dataImportProvider: DataImportStatusProviding,
tabCollectionViewModel: TabCollectionViewModel,
emailManager: EmailManager = EmailManager(),
privacyPreferences: PrivacySecurityPreferences = PrivacySecurityPreferences.shared,
duckPlayerPreferences: DuckPlayerPreferencesPersistor,
privacyConfigurationManager: PrivacyConfigurationManaging = AppPrivacyFeatures.shared.contentBlocking.privacyConfigurationManager) {
self.defaultBrowserProvider = defaultBrowserProvider
self.dataImportProvider = dataImportProvider
self.tabCollectionViewModel = tabCollectionViewModel
self.emailManager = emailManager
self.privacyPreferences = privacyPreferences
self.duckPlayerPreferences = duckPlayerPreferences
self.privacyConfigurationManager = privacyConfigurationManager
refreshFeaturesMatrix()
NotificationCenter.default.addObserver(self, selector: #selector(newTabOpenNotification(_:)), name: HomePage.Models.newHomePageTabOpen, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(windowDidBecomeKey(_:)), name: NSWindow.didBecomeKeyNotification, object: nil)
}
#endif

// swiftlint:disable:next cyclomatic_complexity
@MainActor func performAction(for featureType: FeatureType) {
Expand Down Expand Up @@ -238,12 +207,12 @@ extension HomePage.Models {
shouldShowSurveyDay7 = false
case .networkProtectionRemoteMessage(let message):
#if NETWORK_PROTECTION
networkProtectionRemoteMessaging.dismiss(message: message)
homePageRemoteMessaging.networkProtectionRemoteMessaging.dismiss(message: message)
Pixel.fire(.networkProtectionRemoteMessageDismissed(messageID: message.id))
#endif
case .dataBrokerProtectionRemoteMessage(let message):
#if DBP
dataBrokerProtectionRemoteMessaging.dismiss(message: message)
homePageRemoteMessaging.dataBrokerProtectionRemoteMessaging.dismiss(message: message)
Pixel.fire(.dataBrokerProtectionRemoteMessageDismissed(messageID: message.id))
#endif
case .dataBrokerProtectionWaitlistInvited:
Expand All @@ -260,7 +229,7 @@ extension HomePage.Models {
features.append(.dataBrokerProtectionWaitlistInvited)
}

for message in dataBrokerProtectionRemoteMessaging.presentableRemoteMessages() {
for message in homePageRemoteMessaging.dataBrokerProtectionRemoteMessaging.presentableRemoteMessages() {
features.append(.dataBrokerProtectionRemoteMessage(message))
DailyPixel.fire(
pixel: .dataBrokerProtectionRemoteMessageDisplayed(messageID: message.id),
Expand All @@ -271,7 +240,7 @@ extension HomePage.Models {
#endif

#if NETWORK_PROTECTION
for message in networkProtectionRemoteMessaging.presentableRemoteMessages() {
for message in homePageRemoteMessaging.networkProtectionRemoteMessaging.presentableRemoteMessages() {
features.append(.networkProtectionRemoteMessage(message))
DailyPixel.fire(
pixel: .networkProtectionRemoteMessageDisplayed(messageID: message.id),
Expand Down Expand Up @@ -440,7 +409,7 @@ extension HomePage.Models {
#if NETWORK_PROTECTION
guard let actionType = remoteMessage.action.actionType else {
Pixel.fire(.networkProtectionRemoteMessageDismissed(messageID: remoteMessage.id))
networkProtectionRemoteMessaging.dismiss(message: remoteMessage)
homePageRemoteMessaging.networkProtectionRemoteMessaging.dismiss(message: remoteMessage)
refreshFeaturesMatrix()
return
}
Expand All @@ -455,7 +424,7 @@ extension HomePage.Models {
Pixel.fire(.networkProtectionRemoteMessageOpened(messageID: remoteMessage.id))

// Dismiss the message after the user opens the URL, even if they just close the tab immediately afterwards.
networkProtectionRemoteMessaging.dismiss(message: remoteMessage)
homePageRemoteMessaging.networkProtectionRemoteMessaging.dismiss(message: remoteMessage)
refreshFeaturesMatrix()
}
}
Expand All @@ -466,7 +435,7 @@ extension HomePage.Models {
#if DBP
guard let actionType = remoteMessage.action.actionType else {
Pixel.fire(.dataBrokerProtectionRemoteMessageDismissed(messageID: remoteMessage.id))
dataBrokerProtectionRemoteMessaging.dismiss(message: remoteMessage)
homePageRemoteMessaging.dataBrokerProtectionRemoteMessaging.dismiss(message: remoteMessage)
refreshFeaturesMatrix()
return
}
Expand All @@ -481,7 +450,7 @@ extension HomePage.Models {
Pixel.fire(.dataBrokerProtectionRemoteMessageOpened(messageID: remoteMessage.id))

// Dismiss the message after the user opens the URL, even if they just close the tab immediately afterwards.
dataBrokerProtectionRemoteMessaging.dismiss(message: remoteMessage)
homePageRemoteMessaging.dataBrokerProtectionRemoteMessaging.dismiss(message: remoteMessage)
refreshFeaturesMatrix()
}
}
Expand Down Expand Up @@ -617,3 +586,40 @@ extension HomePage.Models {
}
}
}

// MARK: - Remote Messaging

struct HomePageRemoteMessaging {

static func defaultMessaging() -> HomePageRemoteMessaging {
#if NETWORK_PROTECTION && DBP
return HomePageRemoteMessaging(
networkProtectionRemoteMessaging: DefaultNetworkProtectionRemoteMessaging(),
networkProtectionUserDefaults: .netP,
dataBrokerProtectionRemoteMessaging: DefaultDataBrokerProtectionRemoteMessaging(),
dataBrokerProtectionUserDefaults: .dbp
)
#elseif NETWORK_PROTECTION
return HomePageRemoteMessaging(
networkProtectionRemoteMessaging: DefaultNetworkProtectionRemoteMessaging(),
networkProtectionUserDefaults: .netP
)
#elseif DBP
return HomePageRemoteMessaging(
dataBrokerProtectionRemoteMessaging: DefaultDataBrokerProtectionRemoteMessaging(),
dataBrokerProtectionUserDefaults: .dbp
)
#endif
}

#if NETWORK_PROTECTION
let networkProtectionRemoteMessaging: NetworkProtectionRemoteMessaging
let networkProtectionUserDefaults: UserDefaults
#endif

#if DBP
let dataBrokerProtectionRemoteMessaging: DataBrokerProtectionRemoteMessaging
let dataBrokerProtectionUserDefaults: UserDefaults
#endif

}
18 changes: 2 additions & 16 deletions DuckDuckGo/HomePage/View/HomePageViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -140,27 +140,13 @@ final class HomePageViewController: NSViewController {
}

func createFeatureModel() -> HomePage.Models.ContinueSetUpModel {
#if NETWORK_PROTECTION && DBP
let vm = HomePage.Models.ContinueSetUpModel(
return HomePage.Models.ContinueSetUpModel(
defaultBrowserProvider: SystemDefaultBrowserProvider(),
dataImportProvider: BookmarksAndPasswordsImportStatusProvider(),
tabCollectionViewModel: tabCollectionViewModel,
duckPlayerPreferences: DuckPlayerPreferencesUserDefaultsPersistor(),
networkProtectionRemoteMessaging: DefaultNetworkProtectionRemoteMessaging(),
dataBrokerProtectionRemoteMessaging: DefaultDataBrokerProtectionRemoteMessaging(),
networkProtectionUserDefaults: .netP,
dataBrokerProtectionUserDefaults: .dbp
homePageRemoteMessaging: .defaultMessaging()
)
#else
let vm = HomePage.Models.ContinueSetUpModel(
defaultBrowserProvider: SystemDefaultBrowserProvider(),
dataImportProvider: BookmarksAndPasswordsImportStatusProvider(),
tabCollectionViewModel: tabCollectionViewModel,
duckPlayerPreferences: DuckPlayerPreferencesUserDefaultsPersistor()
)
#endif

return vm
}

func createDefaultBrowserModel() -> HomePage.Models.DefaultBrowserModel {
Expand Down

0 comments on commit 91f876c

Please sign in to comment.