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
+3
View File
@@ -94,6 +94,9 @@ public class CommandClient: ObservableObject {
func connected() {
DispatchQueue.main.async { [self] in
if commandClient.connectionType == .log {
commandClient.logList = []
}
commandClient.isConnected = true
}
}
@@ -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()
+2 -1
View File
@@ -108,14 +108,15 @@ open class ExtensionProvider: NEPacketTunnelProvider {
guard let service else {
return
}
commandServer.setService(service)
do {
try service.start()
} catch {
commandServer.setService(nil)
writeError("(packet-tunnel) error: start service: \(error.localizedDescription)")
return
}
boxService = service
commandServer.setService(service)
#if os(macOS)
await SharedPreferences.startedByUser.set(true)
#endif