Skip to content

Commit

Permalink
NetP: Reconnect on app update (#1294)
Browse files Browse the repository at this point in the history
Task/Issue URL:
https://app.asana.com/0/1199230911884351/1204742178861261/f

**Description**:
- When App is updated, (already connected) NetP VPN should be
reconnected
  • Loading branch information
mallexxx authored and samsymons committed Jun 28, 2023
1 parent 08a73c9 commit 11f0610
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
6 changes: 4 additions & 2 deletions DuckDuckGo/AppDelegate/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Event, Error>.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<Event, Error> {
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
Expand Down

0 comments on commit 11f0610

Please sign in to comment.