Skip to content

Commit

Permalink
Add support for feature flag local override
Browse files Browse the repository at this point in the history
  • Loading branch information
miasma13 committed Nov 25, 2024
1 parent 623c5cf commit e2e5bbe
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Core/FeatureFlag.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ public enum FeatureFlag: String {
}

extension FeatureFlag: FeatureFlagDescribing {

public static var localOverrideStoreName: String = "com.duckduckgo.app.featureFlag.localOverrides"

public var supportsLocalOverriding: Bool {
switch self {
case .isPrivacyProLaunchedROWOverride:
Expand Down
7 changes: 6 additions & 1 deletion DuckDuckGo/AppDependencyProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,12 @@ final class AppDependencyProvider: DependencyProvider {

private init() {
featureFlagger = DefaultFeatureFlagger(internalUserDecider: internalUserDecider,
privacyConfigManager: ContentBlocking.shared.privacyConfigurationManager)
privacyConfigManager: ContentBlocking.shared.privacyConfigurationManager,
localOverrides: FeatureFlagLocalOverrides(
keyValueStore: UserDefaults(suiteName: FeatureFlag.localOverrideStoreName)!,
actionHandler: FeatureFlagOverridesPublishingHandler<FeatureFlag>()
),
for: FeatureFlag.self)

configurationManager = ConfigurationManager(store: configurationStore)

Expand Down
36 changes: 36 additions & 0 deletions DuckDuckGo/SubscriptionDebugViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,17 @@ import UIKit
import Subscription
import Core
import NetworkProtection
import BrowserServicesKit

final class SubscriptionDebugViewController: UITableViewController {

let subscriptionAppGroup = Bundle.main.appGroup(bundle: .subs)
private var subscriptionManager: SubscriptionManager {
AppDependencyProvider.shared.subscriptionManager
}
private var featureFlagger: FeatureFlagger {
AppDependencyProvider.shared.featureFlagger
}

// swiftlint:disable:next force_cast
private let reporter = (UIApplication.shared.delegate as! AppDelegate).privacyProDataReporter as! PrivacyProDataReporter
Expand All @@ -39,6 +43,7 @@ final class SubscriptionDebugViewController: UITableViewController {
Sections.appstore: "App Store",
Sections.environment: "Environment",
Sections.pixels: "Promo Pixel Parameters",
Sections.featureFlags: "Feature flags"
]

enum Sections: Int, CaseIterable {
Expand All @@ -47,6 +52,7 @@ final class SubscriptionDebugViewController: UITableViewController {
case appstore
case environment
case pixels
case featureFlags
}

enum AuthorizationRows: Int, CaseIterable {
Expand Down Expand Up @@ -74,6 +80,10 @@ final class SubscriptionDebugViewController: UITableViewController {
case randomize
}

enum FeatureFlagRows: Int, CaseIterable {
case isLaunchedROW
}

override func numberOfSections(in tableView: UITableView) -> Int {
return Sections.allCases.count
}
Expand Down Expand Up @@ -145,6 +155,16 @@ final class SubscriptionDebugViewController: UITableViewController {
case .none:
break
}

case .featureFlags:

switch FeatureFlagRows(rawValue: indexPath.row) {
case .isLaunchedROW:
cell.textLabel?.text = "isLaunchedROW"
cell.accessoryType = featureFlagger.isFeatureOn(.isPrivacyProLaunchedROWOverride) ? .checkmark : .none
case .none:
break
}
case .none:
break
}
Expand All @@ -159,6 +179,7 @@ final class SubscriptionDebugViewController: UITableViewController {
case .appstore: return AppStoreRows.allCases.count
case .environment: return EnvironmentRows.allCases.count
case .pixels: return PixelsRows.allCases.count
case .featureFlags: return FeatureFlagRows.allCases.count
case .none: return 0

}
Expand Down Expand Up @@ -193,6 +214,11 @@ final class SubscriptionDebugViewController: UITableViewController {
case .randomize: showRandomizedParamters()
default: break
}
case .featureFlags:
switch FeatureFlagRows(rawValue: indexPath.row) {
case .isLaunchedROW: toggleIsLaunchedROWFlag()
default: break
}
case .none:
break
}
Expand Down Expand Up @@ -301,6 +327,16 @@ final class SubscriptionDebugViewController: UITableViewController {
showAlert(title: "", message: message)
}

private func toggleIsLaunchedROWFlag() {
let flag = FeatureFlag.isPrivacyProLaunchedROWOverride
if featureFlagger.localOverrides?.override(for: flag) == nil {
featureFlagger.localOverrides?.toggleOverride(for: flag)
} else {
featureFlagger.localOverrides?.clearOverride(for: flag)
}
tableView.reloadData()
}

private func syncAppleIDAccount() {
Task {
do {
Expand Down

0 comments on commit e2e5bbe

Please sign in to comment.