From c2d7cd499fce2cec170a28f17d971b13187b8f4c Mon Sep 17 00:00:00 2001 From: Anh Do Date: Wed, 27 Mar 2024 17:05:59 -0400 Subject: [PATCH] Stop tunnel --- DuckDuckGo/AppDelegate.swift | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/DuckDuckGo/AppDelegate.swift b/DuckDuckGo/AppDelegate.swift index d03a5e125f..65073950e4 100644 --- a/DuckDuckGo/AppDelegate.swift +++ b/DuckDuckGo/AppDelegate.swift @@ -499,8 +499,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate { #if NETWORK_PROTECTION widgetRefreshModel.refreshVPNWidget() - if vpnFeatureVisibility.shouldShowThankYouMessaging() && !tunnelDefaults.vpnEarlyAccessOverAlertAlreadyShown { - presentVPNEarlyAccessOverAlert() + if vpnFeatureVisibility.shouldShowThankYouMessaging() { + stopTunnelAndShowThankYouMessagingIfNeeded() } if tunnelDefaults.showEntitlementAlert { @@ -513,6 +513,25 @@ class AppDelegate: UIResponder, UIApplicationDelegate { updateSubscriptionStatus() } + private func stopTunnelAndShowThankYouMessagingIfNeeded() { + Task { + let controller = NetworkProtectionTunnelController() + + if await controller.isConnected { + DailyPixel.fireDailyAndCount(pixel: .privacyProVPNBetaStoppedWhenPrivacyProEnabled) + } + + await controller.stop() + await controller.removeVPN() + + if !tunnelDefaults.vpnEarlyAccessOverAlertAlreadyShown { + await MainActor.run { + self.presentVPNEarlyAccessOverAlert() + } + } + } + } + func updateSubscriptionStatus() { #if SUBSCRIPTION Task {