diff --git a/DuckDuckGo/AppDependencyProvider.swift b/DuckDuckGo/AppDependencyProvider.swift index 00b6f9fc29..a54a0db8cf 100644 --- a/DuckDuckGo/AppDependencyProvider.swift +++ b/DuckDuckGo/AppDependencyProvider.swift @@ -52,6 +52,7 @@ protocol DependencyProvider { var serverInfoObserver: ConnectionServerInfoObserver { get } var vpnSettings: VPNSettings { get } var persistentPixel: PersistentPixelFiring { get } + var maliciousSiteProtectionPreferencesManager: MaliciousSiteProtectionPreferencesManaging { get } } @@ -91,6 +92,7 @@ final class AppDependencyProvider: DependencyProvider { let serverInfoObserver: ConnectionServerInfoObserver = ConnectionServerInfoObserverThroughSession() let vpnSettings = VPNSettings(defaults: .networkProtectionGroupDefaults) let persistentPixel: PersistentPixelFiring = PersistentPixel() + let maliciousSiteProtectionPreferencesManager: MaliciousSiteProtectionPreferencesManaging = MaliciousSiteProtectionPreferencesManager() private init() { let featureFlaggerOverrides = FeatureFlagLocalOverrides(keyValueStore: UserDefaults(suiteName: FeatureFlag.localOverrideStoreName)!, diff --git a/DuckDuckGo/MaliciousSiteProtection/MaliciousSiteProtectionManager.swift b/DuckDuckGo/MaliciousSiteProtection/MaliciousSiteProtectionManager.swift index c4f5fea1bc..e1658f866d 100644 --- a/DuckDuckGo/MaliciousSiteProtection/MaliciousSiteProtectionManager.swift +++ b/DuckDuckGo/MaliciousSiteProtection/MaliciousSiteProtectionManager.swift @@ -46,7 +46,7 @@ final class MaliciousSiteProtectionManager: MaliciousSiteDetecting { embeddedDataProvider: MaliciousSiteProtection.EmbeddedDataProviding = EmbeddedDataProvider(), dataManager: MaliciousSiteProtection.DataManager? = nil, detector: MaliciousSiteProtection.MaliciousSiteDetecting? = nil, - preferencesManager: MaliciousSiteProtectionPreferencesPublishing = MaliciousSiteProtectionPreferencesManager(), + preferencesManager: MaliciousSiteProtectionPreferencesPublishing = AppDependencyProvider.shared.maliciousSiteProtectionPreferencesManager, maliciousSiteProtectionFeatureFlagger: MaliciousSiteProtectionFeatureFlagger = MaliciousSiteProtectionFeatureFlags(), updateIntervalProvider: UpdateManager.UpdateIntervalProvider? = nil ) { diff --git a/DuckDuckGo/MaliciousSiteProtection/Settings/MaliciousSiteProtectionSettingsViewModel.swift b/DuckDuckGo/MaliciousSiteProtection/Settings/MaliciousSiteProtectionSettingsViewModel.swift index 30a2bb64db..c4e13afdd3 100644 --- a/DuckDuckGo/MaliciousSiteProtection/Settings/MaliciousSiteProtectionSettingsViewModel.swift +++ b/DuckDuckGo/MaliciousSiteProtection/Settings/MaliciousSiteProtectionSettingsViewModel.swift @@ -43,14 +43,14 @@ final class MaliciousSiteProtectionSettingsViewModel: ObservableObject { private let urlOpener: URLOpener init( - manager: MaliciousSiteProtectionPreferencesManaging = MaliciousSiteProtectionPreferencesManager(), + manager: MaliciousSiteProtectionPreferencesManaging = AppDependencyProvider.shared.maliciousSiteProtectionPreferencesManager, featureFlagger: MaliciousSiteProtectionFeatureFlagger = MaliciousSiteProtectionFeatureFlags(), urlOpener: URLOpener = UIApplication.shared ) { self.manager = manager self.featureFlagger = featureFlagger self.urlOpener = urlOpener - shouldShowMaliciousSiteProtectionSection = true //featureFlagger.isMaliciousSiteProtectionEnabled + shouldShowMaliciousSiteProtectionSection = featureFlagger.isMaliciousSiteProtectionEnabled isMaliciousSiteProtectionEnabled = manager.isEnabled } diff --git a/DuckDuckGo/MaliciousSiteProtection/UserPreferences/MaliciousSiteProtectionPreferencesManager.swift b/DuckDuckGo/MaliciousSiteProtection/UserPreferences/MaliciousSiteProtectionPreferencesManager.swift index 05be25310d..76d37dabf7 100644 --- a/DuckDuckGo/MaliciousSiteProtection/UserPreferences/MaliciousSiteProtectionPreferencesManager.swift +++ b/DuckDuckGo/MaliciousSiteProtection/UserPreferences/MaliciousSiteProtectionPreferencesManager.swift @@ -30,16 +30,21 @@ final class MaliciousSiteProtectionPreferencesUserDefaultsStore: MaliciousSitePr var isEnabled: Bool } -protocol MaliciousSiteProtectionPreferencesPublishing { +protocol MaliciousSiteProtectionPreferencesReadable: AnyObject { var isEnabled: Bool { get } - var isEnabledPublisher: AnyPublisher { get } } -protocol MaliciousSiteProtectionPreferencesManaging: AnyObject { +protocol MaliciousSiteProtectionPreferencesWritable: AnyObject { var isEnabled: Bool { get set } } -final class MaliciousSiteProtectionPreferencesManager: MaliciousSiteProtectionPreferencesManaging, MaliciousSiteProtectionPreferencesPublishing { +protocol MaliciousSiteProtectionPreferencesPublishing: MaliciousSiteProtectionPreferencesReadable { + var isEnabledPublisher: AnyPublisher { get } +} + +typealias MaliciousSiteProtectionPreferencesManaging = MaliciousSiteProtectionPreferencesWritable & MaliciousSiteProtectionPreferencesPublishing + +final class MaliciousSiteProtectionPreferencesManager: MaliciousSiteProtectionPreferencesManaging { @Published var isEnabled: Bool { didSet { store.isEnabled = isEnabled diff --git a/DuckDuckGoTests/MaliciousSiteProtection/Mocks/MaliciousSiteProtectionMocks.swift b/DuckDuckGoTests/MaliciousSiteProtection/Mocks/MaliciousSiteProtectionMocks.swift index e5b7dc35c1..e0c39a769d 100644 --- a/DuckDuckGoTests/MaliciousSiteProtection/Mocks/MaliciousSiteProtectionMocks.swift +++ b/DuckDuckGoTests/MaliciousSiteProtection/Mocks/MaliciousSiteProtectionMocks.swift @@ -105,13 +105,14 @@ final class MockMaliciousSiteDetector: MaliciousSiteProtection.MaliciousSiteDete } } -final class MockMaliciousSiteProtectionPreferencesManager: MaliciousSiteProtectionPreferencesManaging, MaliciousSiteProtectionPreferencesPublishing { +final class MockMaliciousSiteProtectionPreferencesManager: MaliciousSiteProtectionPreferencesManaging { @Published var isEnabled: Bool = false var isEnabledPublisher: AnyPublisher { $isEnabled.eraseToAnyPublisher() } + } final class MockMaliciousSiteProtectionFeatureFlags: MaliciousSiteProtectionFeatureFlagger {