Add read WIFI state support
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user