Skip irrelevant notifications for VPN protocol

Based on tunnel bundle identifier in notification.
This commit is contained in:
Davide De Rosa 2022-04-29 01:32:05 +02:00
parent 17198e53eb
commit 7ba41a0e73

View File

@ -169,7 +169,9 @@ extension VPNManager {
// MARK: Notifications // MARK: Notifications
private func onVPNReinstall(_ notification: Notification) { private func onVPNReinstall(_ notification: Notification) {
currentBundleIdentifier = notification.vpnBundleIdentifier guard isRelevantNotification(notification) else {
return
}
vpnState.send(AtomicState( vpnState.send(AtomicState(
isEnabled: notification.vpnIsEnabled, isEnabled: notification.vpnIsEnabled,
@ -178,8 +180,11 @@ extension VPNManager {
} }
private func onVPNStatus(_ notification: Notification) { private func onVPNStatus(_ notification: Notification) {
guard isRelevantNotification(notification) else {
return
}
var error: Error? var error: Error?
currentBundleIdentifier = notification.vpnBundleIdentifier
switch notification.vpnStatus { switch notification.vpnStatus {
case .connected: case .connected:
@ -211,6 +216,19 @@ extension VPNManager {
currentState?.lastError = notification.vpnError currentState?.lastError = notification.vpnError
} }
private func isRelevantNotification(_ notification: Notification) -> Bool {
guard let notificationTunnelIdentifier = notification.vpnBundleIdentifier else {
return false
}
guard notificationTunnelIdentifier == currentBundleIdentifier else {
pp_log.debug("Skipping not relevant notification from \(notificationTunnelIdentifier)")
return false
}
return true
}
// MARK: Data count
private func onDataCount(_: Date) { private func onDataCount(_: Date) {
switch vpnState.value.vpnStatus { switch vpnState.value.vpnStatus {
case .connected: case .connected: