aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoopesh Chander <roop@roopc.net>2019-03-09 16:48:46 +0530
committerJason A. Donenfeld <Jason@zx2c4.com>2019-03-18 06:46:56 +0100
commit503ac6c8a2eec262348f11d9648b9d18f380b3ad (patch)
treeab3191dab08fea72f5aa885d49005cf473dcbbfc
parenton-demand: iOS: Change wording for add-SSIDs rows (diff)
downloadwireguard-apple-503ac6c8a2eec262348f11d9648b9d18f380b3ad.tar.xz
wireguard-apple-503ac6c8a2eec262348f11d9648b9d18f380b3ad.zip
on-demand: macOS: Auto-complete SSIDs based on currently connected SSID
Signed-off-by: Roopesh Chander <roop@roopc.net>
-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 bf0e52b8..194075d4 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() } ?? []
+}