Skip to content

Commit

Permalink
Fix malicious site protection user preference being out of sync
Browse files Browse the repository at this point in the history
  • Loading branch information
alessandroboron committed Dec 19, 2024
1 parent 91a047a commit 9cbec1b
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 8 deletions.
2 changes: 2 additions & 0 deletions DuckDuckGo/AppDependencyProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ protocol DependencyProvider {
var serverInfoObserver: ConnectionServerInfoObserver { get }
var vpnSettings: VPNSettings { get }
var persistentPixel: PersistentPixelFiring { get }
var maliciousSiteProtectionPreferencesManager: MaliciousSiteProtectionPreferencesManaging { get }

}

Expand Down Expand Up @@ -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)!,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,21 @@ final class MaliciousSiteProtectionPreferencesUserDefaultsStore: MaliciousSitePr
var isEnabled: Bool
}

protocol MaliciousSiteProtectionPreferencesPublishing {
protocol MaliciousSiteProtectionPreferencesReadable: AnyObject {
var isEnabled: Bool { get }
var isEnabledPublisher: AnyPublisher<Bool, Never> { get }
}

protocol MaliciousSiteProtectionPreferencesManaging: AnyObject {
protocol MaliciousSiteProtectionPreferencesWritable: AnyObject {
var isEnabled: Bool { get set }
}

final class MaliciousSiteProtectionPreferencesManager: MaliciousSiteProtectionPreferencesManaging, MaliciousSiteProtectionPreferencesPublishing {
protocol MaliciousSiteProtectionPreferencesPublishing: MaliciousSiteProtectionPreferencesReadable {
var isEnabledPublisher: AnyPublisher<Bool, Never> { get }
}

typealias MaliciousSiteProtectionPreferencesManaging = MaliciousSiteProtectionPreferencesWritable & MaliciousSiteProtectionPreferencesPublishing

final class MaliciousSiteProtectionPreferencesManager: MaliciousSiteProtectionPreferencesManaging {
@Published var isEnabled: Bool {
didSet {
store.isEnabled = isEnabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Bool, Never> {
$isEnabled.eraseToAnyPublisher()
}

}

final class MockMaliciousSiteProtectionFeatureFlags: MaliciousSiteProtectionFeatureFlagger {
Expand Down

0 comments on commit 9cbec1b

Please sign in to comment.