diff --git a/DuckDuckGo.xcodeproj/project.pbxproj b/DuckDuckGo.xcodeproj/project.pbxproj index 0ebcdc2ee8..50b55b4c09 100644 --- a/DuckDuckGo.xcodeproj/project.pbxproj +++ b/DuckDuckGo.xcodeproj/project.pbxproj @@ -9304,7 +9304,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "# Embeds login items for the App Store build.\n\n# Skip login item embedding for release builds until they're ready to go live.\nif [ \"${CONFIGURATION}\" = \"Release\" ]; then\n echo \"Skipping login item embedding for release build.\"\n exit 0\n \n VPN_AGENT_NAME=\"${AGENT_RELEASE_PRODUCT_NAME}\"\n PIR_AGENT_NAME=\"${DBP_BACKGROUND_AGENT_RELEASE_PRODUCT_NAME}\"\nelse\n VPN_AGENT_NAME=\"${AGENT_PRODUCT_NAME}\"\n PIR_AGENT_NAME=\"${DBP_BACKGROUND_AGENT_PRODUCT_NAME}\"\nfi\n\nVPN_AGENT_ORIGIN=$(readlink -f \"${CONFIGURATION_BUILD_DIR}/${VPN_AGENT_NAME}.app\")\nPIR_AGENT_ORIGIN=$(readlink -f \"${CONFIGURATION_BUILD_DIR}/${PIR_AGENT_NAME}.app\")\nAGENT_DESTINATION=\"${CONFIGURATION_BUILD_DIR}/${CONTENTS_FOLDER_PATH}/Library/LoginItems\"\n \n# Make sure that Library/LoginItems exists before copying\nmkdir -p \"$AGENT_DESTINATION\"\n \necho \"Copying VPN agent from $VPN_AGENT_ORIGIN to $AGENT_DESTINATION\"\nrsync -r --links \"$VPN_AGENT_ORIGIN\" \"$AGENT_DESTINATION\"\n \necho \"Copying Personal Information Removal agent from $PIR_AGENT_ORIGIN to $AGENT_DESTINATION\"\nrsync -r --links \"$PIR_AGENT_ORIGIN\" \"$AGENT_DESTINATION\"\n"; + shellScript = "# Embeds login items for the App Store build.\n\n# Skip login item embedding for release builds until they're ready to go live.\nif [ \"${CONFIGURATION}\" = \"Release\" ]; then\n VPN_AGENT_NAME=\"${AGENT_RELEASE_PRODUCT_NAME}\"\n PIR_AGENT_NAME=\"${DBP_BACKGROUND_AGENT_RELEASE_PRODUCT_NAME}\"\nelse\n VPN_AGENT_NAME=\"${AGENT_PRODUCT_NAME}\"\n PIR_AGENT_NAME=\"${DBP_BACKGROUND_AGENT_PRODUCT_NAME}\"\nfi\n\nVPN_AGENT_ORIGIN=$(readlink -f \"${CONFIGURATION_BUILD_DIR}/${VPN_AGENT_NAME}.app\")\nPIR_AGENT_ORIGIN=$(readlink -f \"${CONFIGURATION_BUILD_DIR}/${PIR_AGENT_NAME}.app\")\nAGENT_DESTINATION=\"${CONFIGURATION_BUILD_DIR}/${CONTENTS_FOLDER_PATH}/Library/LoginItems\"\n \n# Make sure that Library/LoginItems exists before copying\nmkdir -p \"$AGENT_DESTINATION\"\n \necho \"Copying VPN agent from $VPN_AGENT_ORIGIN to $AGENT_DESTINATION\"\nrsync -r --links \"$VPN_AGENT_ORIGIN\" \"$AGENT_DESTINATION\"\n \necho \"Copying Personal Information Removal agent from $PIR_AGENT_ORIGIN to $AGENT_DESTINATION\"\nrsync -r --links \"$PIR_AGENT_ORIGIN\" \"$AGENT_DESTINATION\"\n"; }; 7B31FD922AD126C40086AA24 /* Embed System Network Extension */ = { isa = PBXShellScriptBuildPhase; diff --git a/DuckDuckGo/NetworkProtection/AppTargets/BothAppTargets/NetworkProtectionAppEvents.swift b/DuckDuckGo/NetworkProtection/AppTargets/BothAppTargets/NetworkProtectionAppEvents.swift index 981e4155b8..10877dc019 100644 --- a/DuckDuckGo/NetworkProtection/AppTargets/BothAppTargets/NetworkProtectionAppEvents.swift +++ b/DuckDuckGo/NetworkProtection/AppTargets/BothAppTargets/NetworkProtectionAppEvents.swift @@ -61,7 +61,7 @@ final class NetworkProtectionAppEvents { await removeLegacyLoginItemAndVPNConfiguration() migrateNetworkProtectionAuthTokenToSharedKeychainIfNecessary() - guard featureVisibility.isNetworkProtectionVisible() else { + if featureVisibility.shouldUninstallAutomatically() { featureVisibility.disableForAllUsers() return } diff --git a/DuckDuckGo/Waitlist/NetworkProtectionFeatureVisibility.swift b/DuckDuckGo/Waitlist/NetworkProtectionFeatureVisibility.swift index 729e2e7114..35dd79662b 100644 --- a/DuckDuckGo/Waitlist/NetworkProtectionFeatureVisibility.swift +++ b/DuckDuckGo/Waitlist/NetworkProtectionFeatureVisibility.swift @@ -27,6 +27,7 @@ import NetworkProtectionUI protocol NetworkProtectionFeatureVisibility { func isNetworkProtectionVisible() -> Bool + func shouldUninstallAutomatically() -> Bool func disableForAllUsers() func disableForWaitlistUsers() } @@ -65,30 +66,17 @@ 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 { - #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" - } + /// Returns whether Network Protection should be uninstalled automatically. + /// This is only true when the user is not an Easter Egg user, the waitlist test has ended, and the user is onboarded. + func shouldUninstallAutomatically() -> Bool { + let waitlistAccessEnded = isWaitlistUser && !waitlistIsOngoing + let isNotEasterEggUser = !isEasterEggUser + let isOnboarded = UserDefaults.netP.networkProtectionOnboardingStatus != .default - #if DEBUG // Always assume US for debug builds - regionCode = "US" - #endif - - return (regionCode ?? "US") == "US" + return isNotEasterEggUser && waitlistAccessEnded && isOnboarded } /// Whether the user is fully onboarded @@ -152,10 +140,6 @@ 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/Menus/MoreOptionsMenuTests.swift b/UnitTests/Menus/MoreOptionsMenuTests.swift index bee9716173..f64d87be9b 100644 --- a/UnitTests/Menus/MoreOptionsMenuTests.swift +++ b/UnitTests/Menus/MoreOptionsMenuTests.swift @@ -167,6 +167,10 @@ final class NetworkProtectionVisibilityMock: NetworkProtectionFeatureVisibility self.visible = visible } + func shouldUninstallAutomatically() -> Bool { + return !visible + } + func isNetworkProtectionVisible() -> Bool { return visible }