aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/WireGuard/UI/ActivateOnDemandViewModel.swift
diff options
context:
space:
mode:
Diffstat (limited to 'WireGuard/WireGuard/UI/ActivateOnDemandViewModel.swift')
-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
+ }
}