Skip to content

Commit

Permalink
Remove VPN at the conclusion of the waitlist test.
Browse files Browse the repository at this point in the history
  • Loading branch information
samsymons committed Nov 15, 2023
1 parent 5c753eb commit 272a93a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
23 changes: 21 additions & 2 deletions DuckDuckGo/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

#if NETWORK_PROTECTION
widgetRefreshModel.beginObservingVPNStatus()
updateVPNAccessFromFeatureFlagState()
#endif

return true
Expand Down Expand Up @@ -794,8 +795,26 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
do {
try await NetworkProtectionCodeRedemptionCoordinator().redeem(inviteCode)
VPNWaitlist.shared.sendInviteCodeAvailableNotification()
} catch {
// TODO
} catch {}
}
}

func updateVPNAccessFromFeatureFlagState() {
guard NetworkProtectionKeychainTokenStore().isFeatureActivated else {
return
}

let waitlistStorage = VPNWaitlist.shared.waitlistStorage
let configManager = ContentBlocking.shared.privacyConfigurationManager

if !configManager.privacyConfig.isSubfeatureEnabled(NetworkProtectionSubfeature.waitlistBetaActive) {
waitlistStorage.deleteWaitlistState()
try? NetworkProtectionKeychainTokenStore().deleteToken()

Task {
let controller = NetworkProtectionTunnelController()
await controller.stop()
await controller.removeVPN()
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions DuckDuckGo/NetworkProtectionTunnelController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ final class NetworkProtectionTunnelController: TunnelController {
tunnelManager.connection.stopVPNTunnel()
}

func removeVPN() async {
try? await tunnelManager?.removeFromPreferences()
}

// MARK: - Connection Status Querying

/// Queries Network Protection to know if its VPN is connected.
Expand Down

0 comments on commit 272a93a

Please sign in to comment.