Fix inconsistent behavior in onLost
This commit is contained in:
@@ -71,15 +71,13 @@ object VpnMonitor : UpstreamMonitor() {
|
|||||||
|
|
||||||
override fun onLost(network: Network) = synchronized(this@VpnMonitor) {
|
override fun onLost(network: Network) = synchronized(this@VpnMonitor) {
|
||||||
if (available.remove(network) == null || currentNetwork != network) return
|
if (available.remove(network) == null || currentNetwork != network) return
|
||||||
|
callbacks.forEach { it.onLost() }
|
||||||
if (available.isNotEmpty()) {
|
if (available.isNotEmpty()) {
|
||||||
val next = available.entries.first()
|
val next = available.entries.first()
|
||||||
currentNetwork = next.key
|
currentNetwork = next.key
|
||||||
debugLog(TAG, "Switching to ${next.value.interfaceName} as VPN interface")
|
debugLog(TAG, "Switching to ${next.value.interfaceName} as VPN interface")
|
||||||
callbacks.forEach { it.onAvailable(next.value.interfaceName!!, next.value.dnsServers) }
|
callbacks.forEach { it.onAvailable(next.value.interfaceName!!, next.value.dnsServers) }
|
||||||
} else {
|
} else currentNetwork = null
|
||||||
callbacks.forEach { it.onLost() }
|
|
||||||
currentNetwork = null
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user