aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/WireGuard/UI/macOS
diff options
context:
space:
mode:
Diffstat (limited to 'WireGuard/WireGuard/UI/macOS')
-rw-r--r--WireGuard/WireGuard/UI/macOS/View/OnDemandWiFiControls.swift16
1 files changed, 16 insertions, 0 deletions
diff --git a/WireGuard/WireGuard/UI/macOS/View/OnDemandWiFiControls.swift b/WireGuard/WireGuard/UI/macOS/View/OnDemandWiFiControls.swift
index bf0e52b..194075d 100644
--- a/WireGuard/WireGuard/UI/macOS/View/OnDemandWiFiControls.swift
+++ b/WireGuard/WireGuard/UI/macOS/View/OnDemandWiFiControls.swift
@@ -2,6 +2,7 @@
// Copyright © 2018-2019 WireGuard LLC. All Rights Reserved.
import Cocoa
+import CoreWLAN
class OnDemandWiFiControls: NSStackView {
@@ -38,7 +39,10 @@ class OnDemandWiFiControls: NSStackView {
didSet { updateSSIDControls() }
}
+ var currentSSIDs: [String]
+
init() {
+ currentSSIDs = getCurrentSSIDs()
super.init(frame: CGRect.zero)
onDemandSSIDOptionsPopup.addItems(withTitles: OnDemandWiFiControls.onDemandSSIDOptions.map { $0.localizedUIString })
setViews([onDemandWiFiCheckbox, onDemandSSIDOptionsPopup, onDemandSSIDsField], in: .leading)
@@ -56,6 +60,8 @@ class OnDemandWiFiControls: NSStackView {
onDemandSSIDOptionsPopup.target = self
onDemandSSIDOptionsPopup.action = #selector(ssidOptionsPopupValueChanged)
+ onDemandSSIDsField.delegate = self
+
updateSSIDControls()
}
@@ -95,3 +101,13 @@ class OnDemandWiFiControls: NSStackView {
}
}
}
+
+extension OnDemandWiFiControls: NSTokenFieldDelegate {
+ func tokenField(_ tokenField: NSTokenField, completionsForSubstring substring: String, indexOfToken tokenIndex: Int, indexOfSelectedItem selectedIndex: UnsafeMutablePointer<Int>?) -> [Any]? {
+ return currentSSIDs.filter { $0.hasPrefix(substring) }
+ }
+}
+
+private func getCurrentSSIDs() -> [String] {
+ return CWWiFiClient.shared().interfaces()?.compactMap { $0.ssid() } ?? []
+}