From: Roopesh Chander Date: Sat, 9 Mar 2019 11:18:46 +0000 (+0530) Subject: on-demand: macOS: Auto-complete SSIDs based on currently connected SSID X-Git-Tag: 0.0.20190319-1~15 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=503ac6c8a2eec262348f11d9648b9d18f380b3ad;p=thirdparty%2Fwireguard-apple.git on-demand: macOS: Auto-complete SSIDs based on currently connected SSID Signed-off-by: Roopesh Chander --- 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?) -> [Any]? { + return currentSSIDs.filter { $0.hasPrefix(substring) } + } +} + +private func getCurrentSSIDs() -> [String] { + return CWWiFiClient.shared().interfaces()?.compactMap { $0.ssid() } ?? [] +}