mirror of
https://github.com/passepartoutvpn/wireguard-apple.git
synced 2025-02-16 12:52:06 +00:00
on-demand: macOS: Auto-complete SSIDs based on currently connected SSID
This commit is contained in:
parent
1333f6dc42
commit
c01964de4f
@ -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
Block a user