From 11f0610cc6cfe044073f67fe9be97bc3325ff9d1 Mon Sep 17 00:00:00 2001 From: Alexey Martemyanov Date: Tue, 27 Jun 2023 17:06:55 +0600 Subject: [PATCH] NetP: Reconnect on app update (#1294) Task/Issue URL: https://app.asana.com/0/1199230911884351/1204742178861261/f **Description**: - When App is updated, (already connected) NetP VPN should be reconnected --- DuckDuckGo/AppDelegate/AppDelegate.swift | 6 ++++-- .../SystemExtensionManager.swift | 16 ++++++++-------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/DuckDuckGo/AppDelegate/AppDelegate.swift b/DuckDuckGo/AppDelegate/AppDelegate.swift index f298902407..8713fe3a6a 100644 --- a/DuckDuckGo/AppDelegate/AppDelegate.swift +++ b/DuckDuckGo/AppDelegate/AppDelegate.swift @@ -341,15 +341,17 @@ final class AppDelegate: NSObject, NSApplicationDelegate, FileDownloadManagerDel } private func updateNetworkProtectionTunnelAndMenu() { + NetworkProtectionTunnelController.resetLoginItems() + Task { let provider = NetworkProtectionTunnelController() + // Restart NetP SysEx on app update if await provider.isConnected() { await provider.stop() + try? await provider.start() } } - - NetworkProtectionTunnelController.resetLoginItems() } /// Fetches a new list of Network Protection servers, and updates the existing set. diff --git a/DuckDuckGo/NetworkProtection/AppTargets/DeveloperIDTarget/SystemExtensionManager.swift b/DuckDuckGo/NetworkProtection/AppTargets/DeveloperIDTarget/SystemExtensionManager.swift index 665091bd1b..c5dc13ee2f 100644 --- a/DuckDuckGo/NetworkProtection/AppTargets/DeveloperIDTarget/SystemExtensionManager.swift +++ b/DuckDuckGo/NetworkProtection/AppTargets/DeveloperIDTarget/SystemExtensionManager.swift @@ -52,34 +52,34 @@ final class SystemExtensionRequest: NSObject { typealias Event = SystemExtensionManager.ActivationRequestEvent - private let activationRequest: OSSystemExtensionRequest + private let request: OSSystemExtensionRequest private let manager: OSSystemExtensionManager private var continuation: AsyncThrowingStream.Continuation? - private init(activationRequest: OSSystemExtensionRequest, manager: OSSystemExtensionManager) { + private init(request: OSSystemExtensionRequest, manager: OSSystemExtensionManager) { self.manager = manager - self.activationRequest = activationRequest + self.request = request super.init() } static func activationRequest(forExtensionWithIdentifier bundleId: String, manager: OSSystemExtensionManager) -> Self { - self.init(activationRequest: .activationRequest(forExtensionWithIdentifier: bundleId, queue: .global()), manager: manager) + self.init(request: .activationRequest(forExtensionWithIdentifier: bundleId, queue: .global()), manager: manager) } static func deactivationRequest(forExtensionWithIdentifier bundleId: String, manager: OSSystemExtensionManager) -> Self { - self.init(activationRequest: .deactivationRequest(forExtensionWithIdentifier: bundleId, queue: .global()), manager: manager) + self.init(request: .deactivationRequest(forExtensionWithIdentifier: bundleId, queue: .global()), manager: manager) } /// submitting the request returns an Async Iterator providing the OSSystemExtensionRequest state change events - /// until an `ActivationRequestEvent` event is received. + /// until an Event is received. func submit() -> AsyncThrowingStream { assert(continuation == nil, "Request can only be submitted once") defer { - activationRequest.delegate = self - manager.submitRequest(activationRequest) + request.delegate = self + manager.submitRequest(request) } return AsyncThrowingStream { [self /* keep the request delegate alive */] continuation in continuation.onTermination = { _ in