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,22 +49,24 @@ struct PacketTunnelView: View {
await restartService()
}
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.
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.
[Apple Documentation](https://developer.apple.com/documentation/networkextension/nevpnprotocol/4140516-excludeapns)
""", $excludeAPNs) { newValue in
await SharedPreferences.excludeAPNs.set(newValue)
await restartService()
}
[Apple Documentation](https://developer.apple.com/documentation/networkextension/nevpnprotocol/4140516-excludeapns)
""", $excludeAPNs) { newValue in
await SharedPreferences.excludeAPNs.set(newValue)
await restartService()
}
FormToggle("excludeCellularServices", """
If this property is true, the system excludes cellular services — such as Wi-Fi Calling, MMS, SMS, and Visual Voicemail — but only when the **includeAllNetworks** property is also true. This property doesn't impact services that use the cellular network only — such as VoLTE — which the system automatically excludes.
FormToggle("excludeCellularServices", """
If this property is true, the system excludes cellular services — such as Wi-Fi Calling, MMS, SMS, and Visual Voicemail — but only when the **includeAllNetworks** property is also true. This property doesn't impact services that use the cellular network only — such as VoLTE — which the system automatically excludes.
[Apple Documentation](https://developer.apple.com/documentation/networkextension/nevpnprotocol/4140517-excludecellularservices)
""", $excludeCellularServices) { newValue in
await SharedPreferences.excludeCellularServices.set(newValue)
await restartService()
[Apple Documentation](https://developer.apple.com/documentation/networkextension/nevpnprotocol/4140517-excludecellularservices)
""", $excludeCellularServices) { newValue in
await SharedPreferences.excludeCellularServices.set(newValue)
await restartService()
}
}
FormToggle("excludeLocalNetworks", """
@@ -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
+7 -1
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" : {
@@ -8632,4 +8638,4 @@
}
},
"version" : "1.0"
}
}