Fix read WIFI information on macOS app store version

This commit is contained in:
世界
2025-02-20 10:57:04 +08:00
parent 6fd196958b
commit f9eecf8f8c
4 changed files with 47 additions and 2 deletions
+2
View File
@@ -30,5 +30,7 @@
<true/>
<key>com.apple.security.network.server</key>
<true/>
<key>com.apple.security.personal-information.location</key>
<true/>
</dict>
</plist>
@@ -2,7 +2,7 @@ import Foundation
import Libbox
import NetworkExtension
import UserNotifications
#if canImport(CoreWLAN)
#if os(macOS)
import CoreWLAN
#endif
+36 -1
View File
@@ -4,6 +4,9 @@ import NetworkExtension
#if os(iOS)
import WidgetKit
#endif
#if os(macOS)
import CoreLocation
#endif
open class ExtensionProvider: NEPacketTunnelProvider {
public var username: String? = nil
@@ -73,7 +76,7 @@ open class ExtensionProvider: NEPacketTunnelProvider {
writeMessage(message)
var error: NSError?
LibboxWriteServiceError(message, &error)
cancelTunnelWithError(NSError(domain: message, code: 0))
cancelTunnelWithError(nil)
}
private func startService() async {
@@ -114,9 +117,41 @@ open class ExtensionProvider: NEPacketTunnelProvider {
boxService = service
#if os(macOS)
await SharedPreferences.startedByUser.set(true)
if service.needWIFIState() {
if !Variant.useSystemExtension {
locationManager = CLLocationManager()
locationDelegate = stubLocationDelegate(boxService)
locationManager?.delegate = locationDelegate
locationManager?.requestLocation()
} else {
commandServer.writeMessage("(packet-tunnel) WIFI SSID and BSSID information is not currently available in the standalone version of SFM. We are working on resolving this issue.")
}
}
#endif
}
#if os(macOS)
private var locationManager: CLLocationManager?
private var locationDelegate: stubLocationDelegate?
class stubLocationDelegate: NSObject, CLLocationManagerDelegate {
private unowned let boxService: LibboxBoxService
init(_ boxService: LibboxBoxService) {
self.boxService = boxService
}
func locationManagerDidChangeAuthorization(_: CLLocationManager) {
boxService.updateWIFIState()
}
func locationManager(_: CLLocationManager, didUpdateLocations _: [CLLocation]) {}
func locationManager(_: CLLocationManager, didFailWithError _: Error) {}
}
#endif
private func stopService() {
if let service = boxService {
do {
+8
View File
@@ -105,5 +105,13 @@
</array>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>sing-box uses the Location permission to provide users with routing based on WIFI SSID and BSSID rules, without reading your location.</string>
<key>NSLocationUsageDescription</key>
<string>sing-box uses the Location permission to provide users with routing based on WIFI SSID and BSSID rules, without reading your location.</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>sing-box uses the Location permission to provide users with routing based on WIFI SSID and BSSID rules, without reading your location.</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>sing-box uses the Location permission to provide users with routing based on WIFI SSID and BSSID rules, without reading your location.</string>
</dict>
</plist>