on-demand: macOS: Auto-complete SSIDs based on currently connected SSID
Signed-off-by: Roopesh Chander <roop@roopc.net>
This commit is contained in:
parent
5f30e021ef
commit
503ac6c8a2
|
@ -2,6 +2,7 @@
|
||||||
// Copyright © 2018-2019 WireGuard LLC. All Rights Reserved.
|
// Copyright © 2018-2019 WireGuard LLC. All Rights Reserved.
|
||||||
|
|
||||||
import Cocoa
|
import Cocoa
|
||||||
|
import CoreWLAN
|
||||||
|
|
||||||
class OnDemandWiFiControls: NSStackView {
|
class OnDemandWiFiControls: NSStackView {
|
||||||
|
|
||||||
|
@ -38,7 +39,10 @@ class OnDemandWiFiControls: NSStackView {
|
||||||
didSet { updateSSIDControls() }
|
didSet { updateSSIDControls() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var currentSSIDs: [String]
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
|
currentSSIDs = getCurrentSSIDs()
|
||||||
super.init(frame: CGRect.zero)
|
super.init(frame: CGRect.zero)
|
||||||
onDemandSSIDOptionsPopup.addItems(withTitles: OnDemandWiFiControls.onDemandSSIDOptions.map { $0.localizedUIString })
|
onDemandSSIDOptionsPopup.addItems(withTitles: OnDemandWiFiControls.onDemandSSIDOptions.map { $0.localizedUIString })
|
||||||
setViews([onDemandWiFiCheckbox, onDemandSSIDOptionsPopup, onDemandSSIDsField], in: .leading)
|
setViews([onDemandWiFiCheckbox, onDemandSSIDOptionsPopup, onDemandSSIDsField], in: .leading)
|
||||||
|
@ -56,6 +60,8 @@ class OnDemandWiFiControls: NSStackView {
|
||||||
onDemandSSIDOptionsPopup.target = self
|
onDemandSSIDOptionsPopup.target = self
|
||||||
onDemandSSIDOptionsPopup.action = #selector(ssidOptionsPopupValueChanged)
|
onDemandSSIDOptionsPopup.action = #selector(ssidOptionsPopupValueChanged)
|
||||||
|
|
||||||
|
onDemandSSIDsField.delegate = self
|
||||||
|
|
||||||
updateSSIDControls()
|
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() } ?? []
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue