aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoopesh Chander <roop@roopc.net>2019-03-08 11:51:27 +0530
committerJason A. Donenfeld <Jason@zx2c4.com>2019-03-18 06:46:55 +0100
commitbd339e2876545388f3c4197d0a74eb67adb48738 (patch)
tree3a1b19cf3e4017e7031ea74aae1ff30e911af059
parenton-demand: macOS: Support SSIDs in on demand activation (diff)
downloadwireguard-apple-bd339e2876545388f3c4197d0a74eb67adb48738.tar.xz
wireguard-apple-bd339e2876545388f3c4197d0a74eb67adb48738.zip
on-demand: ActivateOnDemandViewModel: Uniquify SSIDs list
And if SSIDs list is empty, fall back to .anySSID option Signed-off-by: Roopesh Chander <roop@roopc.net>
-rw-r--r--WireGuard/WireGuard/UI/ActivateOnDemandViewModel.swift18
1 files changed, 16 insertions, 2 deletions
diff --git a/WireGuard/WireGuard/UI/ActivateOnDemandViewModel.swift b/WireGuard/WireGuard/UI/ActivateOnDemandViewModel.swift
index a8528182..55da6e07 100644
--- a/WireGuard/WireGuard/UI/ActivateOnDemandViewModel.swift
+++ b/WireGuard/WireGuard/UI/ActivateOnDemandViewModel.swift
@@ -156,9 +156,23 @@ private extension ActivateOnDemandViewModel {
case .anySSID:
return .anySSID
case .onlySpecificSSIDs:
- return .onlySpecificSSIDs(selectedSSIDs)
+ let ssids = uniquifiedNonEmptySelectedSSIDs()
+ return ssids.isEmpty ? .anySSID : .onlySpecificSSIDs(selectedSSIDs)
case .exceptSpecificSSIDs:
- return .exceptSpecificSSIDs(selectedSSIDs)
+ let ssids = uniquifiedNonEmptySelectedSSIDs()
+ return ssids.isEmpty ? .anySSID : .exceptSpecificSSIDs(selectedSSIDs)
}
}
+
+ func uniquifiedNonEmptySelectedSSIDs() -> [String] {
+ let nonEmptySSIDs = selectedSSIDs.filter { !$0.isEmpty }
+ var seenSSIDs = Set<String>()
+ var uniquified = [String]()
+ for ssid in nonEmptySSIDs {
+ guard !seenSSIDs.contains(ssid) else { continue }
+ uniquified.append(ssid)
+ seenSSIDs.insert(ssid)
+ }
+ return uniquified
+ }
}