Skip to content

Commit

Permalink
Release branch login item embed fix (#2216)
Browse files Browse the repository at this point in the history
Task/Issue URL: https://app.asana.com/0/1199230911884351/1206624161225335/f
Tech Design URL:
CC:

Description:

This PR fixes a couple release blockers.
  • Loading branch information
samsymons authored Feb 16, 2024
1 parent e132b43 commit 9512a2c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 26 deletions.
2 changes: 1 addition & 1 deletion DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ final class NetworkProtectionAppEvents {
await removeLegacyLoginItemAndVPNConfiguration()
migrateNetworkProtectionAuthTokenToSharedKeychainIfNecessary()

guard featureVisibility.isNetworkProtectionVisible() else {
if featureVisibility.shouldUninstallAutomatically() {
featureVisibility.disableForAllUsers()
return
}
Expand Down
32 changes: 8 additions & 24 deletions DuckDuckGo/Waitlist/NetworkProtectionFeatureVisibility.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import NetworkProtectionUI

protocol NetworkProtectionFeatureVisibility {
func isNetworkProtectionVisible() -> Bool
func shouldUninstallAutomatically() -> Bool
func disableForAllUsers()
func disableForWaitlistUsers()
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions UnitTests/Menus/MoreOptionsMenuTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ final class NetworkProtectionVisibilityMock: NetworkProtectionFeatureVisibility
self.visible = visible
}

func shouldUninstallAutomatically() -> Bool {
return !visible
}

func isNetworkProtectionVisible() -> Bool {
return visible
}
Expand Down

0 comments on commit 9512a2c

Please sign in to comment.