From 6e41bea1c7149e7ee5e4c53c0ac18894a5864175 Mon Sep 17 00:00:00 2001 From: Diego Rey Mendez Date: Thu, 28 Nov 2024 13:56:27 +0100 Subject: [PATCH 1/2] Changes the tunnel restart logic for the VPN --- DuckDuckGo.xcodeproj/project.pbxproj | 4 ++-- .../xcshareddata/swiftpm/Package.resolved | 3 +-- .../NetworkProtectionTunnelController.swift | 23 +++++++++---------- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/DuckDuckGo.xcodeproj/project.pbxproj b/DuckDuckGo.xcodeproj/project.pbxproj index 85f2f10605..c64f8d0859 100644 --- a/DuckDuckGo.xcodeproj/project.pbxproj +++ b/DuckDuckGo.xcodeproj/project.pbxproj @@ -15204,8 +15204,8 @@ isa = XCRemoteSwiftPackageReference; repositoryURL = "https://github.com/duckduckgo/BrowserServicesKit"; requirement = { - kind = exactVersion; - version = 212.0.0; + kind = revision; + revision = cab867b50a4ae91b7616decb2a2d20be6c5dc621; }; }; 9FF521422BAA8FF300B9819B /* XCRemoteSwiftPackageReference "lottie-spm" */ = { diff --git a/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index ea5f5ad5fc..61fe02185d 100644 --- a/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -32,8 +32,7 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/duckduckgo/BrowserServicesKit", "state" : { - "revision" : "5a24a885425dcb5626353bf5a8ca6af79c44c1cb", - "version" : "212.0.0" + "revision" : "cab867b50a4ae91b7616decb2a2d20be6c5dc621" } }, { diff --git a/DuckDuckGo/NetworkProtection/AppTargets/BothAppTargets/NetworkProtectionTunnelController.swift b/DuckDuckGo/NetworkProtection/AppTargets/BothAppTargets/NetworkProtectionTunnelController.swift index 8982657cf6..ddef1ff756 100644 --- a/DuckDuckGo/NetworkProtection/AppTargets/BothAppTargets/NetworkProtectionTunnelController.swift +++ b/DuckDuckGo/NetworkProtection/AppTargets/BothAppTargets/NetworkProtectionTunnelController.swift @@ -665,16 +665,23 @@ final class NetworkProtectionTunnelController: TunnelController, TunnelSessionPr /// @MainActor func stop() async { + await stop(disableOnDemand: false) + } + + @MainActor + func stop(disableOnDemand: Bool) async { guard let manager = await manager else { return } - await stop(tunnelManager: manager) + await stop(tunnelManager: manager, disableOnDemand: disableOnDemand) } @MainActor - private func stop(tunnelManager: NETunnelProviderManager) async { - try? await self.disableOnDemand(tunnelManager: tunnelManager) + private func stop(tunnelManager: NETunnelProviderManager, disableOnDemand: Bool) async { + if disableOnDemand { + try? await self.disableOnDemand(tunnelManager: tunnelManager) + } switch tunnelManager.connection.status { case .connected, .connecting, .reasserting: @@ -692,15 +699,7 @@ final class NetworkProtectionTunnelController: TunnelController, TunnelSessionPr /// @MainActor func restart() async { - guard let manager = await manager else { - return - } - - await stop(tunnelManager: manager) - await start() - - // When restarting the tunnel we enable on-demand optimistically - try? await enableOnDemand(tunnelManager: manager) + await stop(disableOnDemand: false) } // MARK: - On Demand & Kill Switch From 3ccf672a3a433c3e9603d3dde55ab165a3553bde Mon Sep 17 00:00:00 2001 From: Diego Rey Mendez Date: Thu, 28 Nov 2024 14:07:06 +0100 Subject: [PATCH 2/2] Fixes a mistake in the previous commit --- .../BothAppTargets/NetworkProtectionTunnelController.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DuckDuckGo/NetworkProtection/AppTargets/BothAppTargets/NetworkProtectionTunnelController.swift b/DuckDuckGo/NetworkProtection/AppTargets/BothAppTargets/NetworkProtectionTunnelController.swift index ddef1ff756..a35f9a6d29 100644 --- a/DuckDuckGo/NetworkProtection/AppTargets/BothAppTargets/NetworkProtectionTunnelController.swift +++ b/DuckDuckGo/NetworkProtection/AppTargets/BothAppTargets/NetworkProtectionTunnelController.swift @@ -665,7 +665,7 @@ final class NetworkProtectionTunnelController: TunnelController, TunnelSessionPr /// @MainActor func stop() async { - await stop(disableOnDemand: false) + await stop(disableOnDemand: true) } @MainActor