Fix Packet Tunnel options not working

This commit is contained in:
世界
2026-03-05 18:43:04 +08:00
parent 80c866861d
commit c8199ca3da
4 changed files with 51 additions and 17 deletions
@@ -15,6 +15,7 @@ struct PacketTunnelView: View {
@State private var excludeCellularServices = false
@State private var excludeLocalNetworks = false
@State private var enforceRoutes = false
@State private var excludeDeviceCommunication = false
init() {}
var body: some View {
@@ -48,6 +49,7 @@ struct PacketTunnelView: View {
await restartService()
}
if #available(iOS 16.4, macOS 13.3, *) {
FormToggle("excludeAPNs", """
If this property is true, the system excludes Apple Push Notification services (APNs) traffic, but only when the **includeAllNetworks** property is also true.
@@ -65,6 +67,7 @@ struct PacketTunnelView: View {
await SharedPreferences.excludeCellularServices.set(newValue)
await restartService()
}
}
FormToggle("excludeLocalNetworks", """
If this property is true, the system excludes network connections to hosts on the local network — such as AirPlay, AirDrop, and CarPlay — but only when the **includeAllNetworks** or **enforceRoutes** property is also true.
@@ -86,6 +89,17 @@ struct PacketTunnelView: View {
await restartService()
}
if #available(iOS 17.4, macOS 14.4, *) {
FormToggle("excludeDeviceCommunication", """
No documentation.
[Apple Documentation](https://developer.apple.com/documentation/networkextension/nevpnprotocol/excludedevicecommunication)
""", $excludeDeviceCommunication) { newValue in
await SharedPreferences.excludeDeviceCommunication.set(newValue)
await restartService()
}
}
#endif
FormButton {
@@ -126,10 +140,15 @@ struct PacketTunnelView: View {
#endif
#if !os(tvOS)
includeAllNetworks = await SharedPreferences.includeAllNetworks.get()
excludeAPNs = await SharedPreferences.excludeAPNs.get()
excludeCellularServices = await SharedPreferences.excludeCellularServices.get()
excludeLocalNetworks = await SharedPreferences.excludeLocalNetworks.get()
enforceRoutes = await SharedPreferences.enforceRoutes.get()
if #available(iOS 16.4, macOS 13.3, *) {
excludeAPNs = await SharedPreferences.excludeAPNs.get()
excludeCellularServices = await SharedPreferences.excludeCellularServices.get()
}
if #available(iOS 17.4, macOS 14.4, *) {
excludeDeviceCommunication = await SharedPreferences.excludeDeviceCommunication.get()
}
#endif
isLoading = false
}
+3
View File
@@ -38,6 +38,7 @@ public enum SharedPreferences {
public static let excludeLocalNetworks = Preference<Bool>("exclude_local_networks", defaultValue: excludeLocalNetworksByDefault)
public static let excludeCellularServices = Preference<Bool>("exclude_cellular_services", defaultValue: true)
public static let enforceRoutes = Preference<Bool>("enforce_routes", defaultValue: false)
public static let excludeDeviceCommunication = Preference<Bool>("exclude_device_communication", defaultValue: true)
#endif
@@ -49,6 +50,7 @@ public enum SharedPreferences {
excludeLocalNetworks.name,
excludeCellularServices.name,
enforceRoutes.name,
excludeDeviceCommunication.name,
]
#elseif os(tvOS)
let names = [ignoreMemoryLimit.name]
@@ -60,6 +62,7 @@ public enum SharedPreferences {
excludeLocalNetworks.name,
excludeCellularServices.name,
enforceRoutes.name,
excludeDeviceCommunication.name,
]
#endif
try? await batchDelete(names)
+7 -1
View File
@@ -145,8 +145,14 @@ public class ExtensionProfile: ObservableObject {
if let protocolConfiguration = manager.protocolConfiguration {
let includeAllNetworks = await SharedPreferences.includeAllNetworks.get()
protocolConfiguration.includeAllNetworks = includeAllNetworks
protocolConfiguration.excludeLocalNetworks = await SharedPreferences.excludeLocalNetworks.get()
protocolConfiguration.enforceRoutes = await SharedPreferences.enforceRoutes.get()
if #available(iOS 16.4, macOS 13.3, *) {
protocolConfiguration.excludeCellularServices = !includeAllNetworks
protocolConfiguration.excludeAPNs = await SharedPreferences.excludeAPNs.get()
protocolConfiguration.excludeCellularServices = await SharedPreferences.excludeCellularServices.get()
}
if #available(iOS 17.4, macOS 14.4, *) {
protocolConfiguration.excludeDeviceCommunication = await SharedPreferences.excludeDeviceCommunication.get()
}
}
#endif
+6
View File
@@ -3290,6 +3290,9 @@
},
"shouldTranslate" : false
},
"excludeDeviceCommunication" : {
"shouldTranslate" : false
},
"excludeLocalNetworks" : {
"localizations" : {
"fa" : {
@@ -5550,6 +5553,9 @@
}
}
},
"No documentation.\n\n[Apple Documentation](https://developer.apple.com/documentation/networkextension/nevpnprotocol/excludedevicecommunication)" : {
"shouldTranslate" : false
},
"Ok" : {
"localizations" : {
"fa" : {