From 4209093d9d90450d85bfc1d76002503c7eec688e Mon Sep 17 00:00:00 2001 From: Sam Symons Date: Thu, 15 Feb 2024 09:18:26 -0800 Subject: [PATCH] NetP App Store waitlist tweaks (#2197) (#2204) Task/Issue URL: https://app.asana.com/0/1199230911884351/1206604571588642/f Tech Design URL: CC: @Bunn **Description**: This PR cherry picks a recent NetP changes and turns NetP on in release builds. --- Configuration/AppStore.xcconfig | 6 ++-- Configuration/Common.xcconfig | 2 +- .../Tests/UnitTestsAppStore.xcconfig | 2 +- .../NetworkProtectionAppEvents.swift | 2 +- .../NetworkProtectionNavBarButtonModel.swift | 2 ++ .../NetworkProtectionFeatureVisibility.swift | 29 ++++++++++++++++++- .../HomePage/ContinueSetUpModelTests.swift | 6 ++++ 7 files changed, 42 insertions(+), 7 deletions(-) diff --git a/Configuration/AppStore.xcconfig b/Configuration/AppStore.xcconfig index af55b7fa5d..c2ae87c9b5 100644 --- a/Configuration/AppStore.xcconfig +++ b/Configuration/AppStore.xcconfig @@ -31,9 +31,9 @@ GCC_PREPROCESSOR_DEFINITIONS[config=Review][arch=*][sdk=*] = APPSTORE=1 REVIEW=1 MACOSX_DEPLOYMENT_TARGET = 12.3 SWIFT_ACTIVE_COMPILATION_CONDITIONS[arch=*][sdk=*] = APPSTORE $(FEATURE_FLAGS) -SWIFT_ACTIVE_COMPILATION_CONDITIONS[config=CI][arch=*][sdk=*] = APPSTORE DEBUG NETWORK_PROTECTION DBP CI $(FEATURE_FLAGS) -SWIFT_ACTIVE_COMPILATION_CONDITIONS[config=Debug][arch=*][sdk=*] = APPSTORE DEBUG NETWORK_PROTECTION DBP $(FEATURE_FLAGS) -SWIFT_ACTIVE_COMPILATION_CONDITIONS[config=Review][arch=*][sdk=*] = APPSTORE REVIEW NETWORK_PROTECTION DBP $(FEATURE_FLAGS) +SWIFT_ACTIVE_COMPILATION_CONDITIONS[config=CI][arch=*][sdk=*] = APPSTORE DEBUG CI $(FEATURE_FLAGS) +SWIFT_ACTIVE_COMPILATION_CONDITIONS[config=Debug][arch=*][sdk=*] = APPSTORE DEBUG $(FEATURE_FLAGS) +SWIFT_ACTIVE_COMPILATION_CONDITIONS[config=Review][arch=*][sdk=*] = APPSTORE REVIEW $(FEATURE_FLAGS) NETP_BASE_APP_GROUP = $(DEVELOPMENT_TEAM).com.duckduckgo.macos.browser.network-protection NETP_APP_GROUP[config=CI][sdk=macos*] = $(NETP_BASE_APP_GROUP).debug diff --git a/Configuration/Common.xcconfig b/Configuration/Common.xcconfig index 04c51ab42e..5c38d4e8e4 100644 --- a/Configuration/Common.xcconfig +++ b/Configuration/Common.xcconfig @@ -21,7 +21,7 @@ COMBINE_HIDPI_IMAGES = YES DEVELOPMENT_TEAM = HKE973VLUW DEVELOPMENT_TEAM[config=CI][sdk=*] = -FEATURE_FLAGS = FEEDBACK DBP +FEATURE_FLAGS = FEEDBACK DBP NETWORK_PROTECTION GCC_PREPROCESSOR_DEFINITIONS[config=CI][arch=*][sdk=*] = DEBUG=1 CI=1 $(inherited) GCC_PREPROCESSOR_DEFINITIONS[config=Debug][arch=*][sdk=*] = DEBUG=1 $(inherited) diff --git a/Configuration/Tests/UnitTestsAppStore.xcconfig b/Configuration/Tests/UnitTestsAppStore.xcconfig index fb90843360..a885a868ed 100644 --- a/Configuration/Tests/UnitTestsAppStore.xcconfig +++ b/Configuration/Tests/UnitTestsAppStore.xcconfig @@ -16,7 +16,7 @@ #include "UnitTests.xcconfig" #include "../AppStore.xcconfig" -FEATURE_FLAGS = FEEDBACK +FEATURE_FLAGS = FEEDBACK NETWORK_PROTECTION DBP PRODUCT_BUNDLE_IDENTIFIER = com.duckduckgo.mobile.ios.DuckDuckGoTests diff --git a/DuckDuckGo/NetworkProtection/AppTargets/BothAppTargets/NetworkProtectionAppEvents.swift b/DuckDuckGo/NetworkProtection/AppTargets/BothAppTargets/NetworkProtectionAppEvents.swift index a1e96fa4cf..981e4155b8 100644 --- a/DuckDuckGo/NetworkProtection/AppTargets/BothAppTargets/NetworkProtectionAppEvents.swift +++ b/DuckDuckGo/NetworkProtection/AppTargets/BothAppTargets/NetworkProtectionAppEvents.swift @@ -57,7 +57,7 @@ final class NetworkProtectionAppEvents { func applicationDidFinishLaunching() { let loginItemsManager = LoginItemsManager() - Task { + Task { @MainActor in await removeLegacyLoginItemAndVPNConfiguration() migrateNetworkProtectionAuthTokenToSharedKeychainIfNecessary() diff --git a/DuckDuckGo/NetworkProtection/AppTargets/BothAppTargets/NetworkProtectionNavBarButtonModel.swift b/DuckDuckGo/NetworkProtection/AppTargets/BothAppTargets/NetworkProtectionNavBarButtonModel.swift index df8396f857..df0b97b8ac 100644 --- a/DuckDuckGo/NetworkProtection/AppTargets/BothAppTargets/NetworkProtectionNavBarButtonModel.swift +++ b/DuckDuckGo/NetworkProtection/AppTargets/BothAppTargets/NetworkProtectionNavBarButtonModel.swift @@ -209,6 +209,7 @@ final class NetworkProtectionNavBarButtonModel: NSObject, ObservableObject { let isWaitlistUser = waitlist.waitlistStorage.isWaitlistUser let hasAuthToken = NetworkProtectionKeychainTokenStore().isFeatureActivated +#if !APPSTORE // If the user hasn't signed up to the waitlist or doesn't have an auth token through some other method, then show them the badged icon // to get their attention and encourage them to sign up. Also avoid showing the button is the user has opened the waitlist UI but // dismissed it. @@ -216,6 +217,7 @@ final class NetworkProtectionNavBarButtonModel: NSObject, ObservableObject { showButton = true return } +#endif } guard !isPinned, diff --git a/DuckDuckGo/Waitlist/NetworkProtectionFeatureVisibility.swift b/DuckDuckGo/Waitlist/NetworkProtectionFeatureVisibility.swift index 370acfc068..729e2e7114 100644 --- a/DuckDuckGo/Waitlist/NetworkProtectionFeatureVisibility.swift +++ b/DuckDuckGo/Waitlist/NetworkProtectionFeatureVisibility.swift @@ -65,7 +65,30 @@ struct DefaultNetworkProtectionVisibility: NetworkProtectionFeatureVisibility { /// /// Once the waitlist beta has ended, we can trigger a remote change that removes the user's auth token and turn off the waitlist flag, hiding Network Protection from the user. func isNetworkProtectionVisible() -> Bool { - isEasterEggUser || waitlistIsOngoing + #if APPSTORE + return isEasterEggUser || (isUserLocaleAllowed && waitlistIsOngoing) + #else + return isEasterEggUser || waitlistIsOngoing + #endif + } + + var isUserLocaleAllowed: Bool { + var regionCode: String? + if #available(macOS 13, *) { + regionCode = Locale.current.region?.identifier + } else { + regionCode = Locale.current.regionCode + } + + if isInternalUser { + regionCode = "US" + } + + #if DEBUG // Always assume US for debug builds + regionCode = "US" + #endif + + return (regionCode ?? "US") == "US" } /// Whether the user is fully onboarded @@ -129,6 +152,10 @@ struct DefaultNetworkProtectionVisibility: NetworkProtectionFeatureVisibility { } } + private var isInternalUser: Bool { + NSApp.delegateTyped.internalUserDecider.isInternalUser + } + func disableForAllUsers() { Task { await featureDisabler.disable(keepAuthToken: false, uninstallSystemExtension: false) diff --git a/UnitTests/HomePage/ContinueSetUpModelTests.swift b/UnitTests/HomePage/ContinueSetUpModelTests.swift index e37b1fff44..e9411db6e1 100644 --- a/UnitTests/HomePage/ContinueSetUpModelTests.swift +++ b/UnitTests/HomePage/ContinueSetUpModelTests.swift @@ -109,6 +109,8 @@ final class ContinueSetUpModelTests: XCTestCase { dataBrokerProtectionRemoteMessaging: MockDataBrokerProtectionRemoteMessaging(), dataBrokerProtectionUserDefaults: userDefaults ) +#else + let messaging = HomePageRemoteMessaging.defaultMessaging() #endif vm = HomePage.Models.ContinueSetUpModel( @@ -543,6 +545,8 @@ final class ContinueSetUpModelTests: XCTestCase { dataBrokerProtectionRemoteMessaging: MockDataBrokerProtectionRemoteMessaging(), dataBrokerProtectionUserDefaults: userDefaults ) +#else + return HomePageRemoteMessaging.defaultMessaging() #endif } @@ -587,6 +591,8 @@ extension HomePage.Models.ContinueSetUpModel { dataBrokerProtectionRemoteMessaging: MockDataBrokerProtectionRemoteMessaging(), dataBrokerProtectionUserDefaults: appGroupUserDefaults ) +#else + let messaging = HomePageRemoteMessaging.defaultMessaging() #endif return HomePage.Models.ContinueSetUpModel(