Tunnel view model: If there's just one peer, populate the scratchpad on init
So that exclude private IPs can be computed correctly.
This commit is contained in:
parent
c61491391e
commit
864394cf81
|
@ -179,11 +179,9 @@ class TunnelViewModel {
|
||||||
var validatedConfiguration: PeerConfiguration? = nil
|
var validatedConfiguration: PeerConfiguration? = nil
|
||||||
|
|
||||||
// For exclude private IPs
|
// For exclude private IPs
|
||||||
var shouldAllowExcludePrivateIPsControl: Bool = false
|
var shouldAllowExcludePrivateIPsControl: Bool = false /* Read-only from the VC's point of view */
|
||||||
var excludePrivateIPsValue: Bool = false
|
var excludePrivateIPsValue: Bool = false /* Read-only from the VC's point of view */
|
||||||
var numberOfPeers: Int = 0 {
|
fileprivate var numberOfPeers: Int = 0
|
||||||
didSet { updateExcludePrivateIPsFieldState() }
|
|
||||||
}
|
|
||||||
|
|
||||||
init(index: Int) {
|
init(index: Int) {
|
||||||
self.index = index
|
self.index = index
|
||||||
|
@ -318,6 +316,9 @@ class TunnelViewModel {
|
||||||
excludePrivateIPsValue = false
|
excludePrivateIPsValue = false
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if (scratchpad.isEmpty) {
|
||||||
|
populateScratchpad()
|
||||||
|
}
|
||||||
let allowedIPStrings = Set<String>(
|
let allowedIPStrings = Set<String>(
|
||||||
(scratchpad[.allowedIPs] ?? "")
|
(scratchpad[.allowedIPs] ?? "")
|
||||||
.split(separator: ",")
|
.split(separator: ",")
|
||||||
|
@ -365,8 +366,8 @@ class TunnelViewModel {
|
||||||
var peersData: [PeerData]
|
var peersData: [PeerData]
|
||||||
|
|
||||||
init(tunnelConfiguration: TunnelConfiguration?) {
|
init(tunnelConfiguration: TunnelConfiguration?) {
|
||||||
interfaceData = InterfaceData()
|
let interfaceData: InterfaceData = InterfaceData()
|
||||||
peersData = []
|
var peersData: [PeerData] = []
|
||||||
if let tunnelConfiguration = tunnelConfiguration {
|
if let tunnelConfiguration = tunnelConfiguration {
|
||||||
interfaceData.validatedConfiguration = tunnelConfiguration.interface
|
interfaceData.validatedConfiguration = tunnelConfiguration.interface
|
||||||
for (i, peerConfiguration) in tunnelConfiguration.peers.enumerated() {
|
for (i, peerConfiguration) in tunnelConfiguration.peers.enumerated() {
|
||||||
|
@ -378,7 +379,10 @@ class TunnelViewModel {
|
||||||
let numberOfPeers = peersData.count
|
let numberOfPeers = peersData.count
|
||||||
for peerData in peersData {
|
for peerData in peersData {
|
||||||
peerData.numberOfPeers = numberOfPeers
|
peerData.numberOfPeers = numberOfPeers
|
||||||
|
peerData.updateExcludePrivateIPsFieldState()
|
||||||
}
|
}
|
||||||
|
self.interfaceData = interfaceData
|
||||||
|
self.peersData = peersData
|
||||||
}
|
}
|
||||||
|
|
||||||
func appendEmptyPeer() {
|
func appendEmptyPeer() {
|
||||||
|
@ -386,6 +390,7 @@ class TunnelViewModel {
|
||||||
peersData.append(peer)
|
peersData.append(peer)
|
||||||
for p in peersData {
|
for p in peersData {
|
||||||
p.numberOfPeers = peersData.count
|
p.numberOfPeers = peersData.count
|
||||||
|
p.updateExcludePrivateIPsFieldState()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -398,6 +403,7 @@ class TunnelViewModel {
|
||||||
}
|
}
|
||||||
for p in peersData {
|
for p in peersData {
|
||||||
p.numberOfPeers = peersData.count
|
p.numberOfPeers = peersData.count
|
||||||
|
p.updateExcludePrivateIPsFieldState()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue