Add clash mode selector & always on

This commit is contained in:
世界
2023-08-28 11:42:47 +08:00
parent d3b2040fe1
commit b5a89fddec
11 changed files with 169 additions and 13 deletions
@@ -5,6 +5,7 @@ import NetworkExtension
public class ExtensionPlatformInterface: NSObject, LibboxPlatformInterfaceProtocol {
private let tunnel: NEPacketTunnelProvider
private let commandServer: LibboxCommandServer
private var networkSettings: NEPacketTunnelNetworkSettings?
init(_ tunnel: NEPacketTunnelProvider, _ logServer: LibboxCommandServer) {
self.tunnel = tunnel
@@ -88,6 +89,7 @@ public class ExtensionPlatformInterface: NSObject, LibboxPlatformInterfaceProtoc
settings.proxySettings = proxySettings
}
networkSettings = settings
try runBlocking { [self] in
try await tunnel.setTunnelNetworkSettings(settings)
}
@@ -153,4 +155,21 @@ public class ExtensionPlatformInterface: NSObject, LibboxPlatformInterfaceProtoc
public func underNetworkExtension() -> Bool {
true
}
public func clearDNSCache() {
guard let networkSettings else {
return
}
tunnel.reasserting = true
tunnel.setTunnelNetworkSettings(nil) { _ in
}
tunnel.setTunnelNetworkSettings(networkSettings) { _ in
}
tunnel.reasserting = false
}
public func closeTun() throws {
tunnel.setTunnelNetworkSettings(nil) { _ in
}
}
}