Add read WIFI state support

This commit is contained in:
世界
2023-11-18 14:39:04 +08:00
parent 1b12837eec
commit 1a8c59faaf
6 changed files with 43 additions and 7 deletions
@@ -1,6 +1,9 @@
import Foundation
import Libbox
import NetworkExtension
#if canImport(CoreWLAN)
import CoreWLAN
#endif
public class ExtensionPlatformInterface: NSObject, LibboxPlatformInterfaceProtocol, LibboxCommandServerHandlerProtocol {
private let tunnel: ExtensionProvider
@@ -172,6 +175,31 @@ public class ExtensionPlatformInterface: NSObject, LibboxPlatformInterfaceProtoc
tunnel.reasserting = false
}
public func readWIFIState() -> LibboxWIFIState? {
#if os(iOS)
let network = runBlocking {
await NEHotspotNetwork.fetchCurrent()
}
guard let network else {
return nil
}
return LibboxWIFIState(network.ssid, wifiBSSID: network.bssid)!
#elseif os(macOS)
guard let interface = CWWiFiClient.shared().interface() else {
return nil
}
guard let ssid = interface.ssid() else {
return nil
}
guard let bssid = interface.bssid() else {
return nil
}
return LibboxWIFIState(ssid, wifiBSSID: bssid)!
#else
return nil
#endif
}
public func serviceReload() throws {
runBlocking { [self] in
await tunnel.reloadService()