iOS 1.0.3 source candidate only; no Apple build or installation acceptance

This commit is contained in:
2026-10-27 02:46:08 +00:00
parent 1cf54a46e4
commit 295799b1ab
29 changed files with 1499 additions and 213 deletions
+39 -10
View File
@@ -15,7 +15,10 @@ final class VPNController: ObservableObject {
queue: .main
) { [weak self] note in
guard let connection = note.object as? NEVPNConnection else { return }
Task { @MainActor in self?.status = connection.status }
Task { @MainActor in
guard let self, connection === self.manager?.connection else { return }
self.status = connection.status
}
}
}
@@ -38,26 +41,51 @@ final class VPNController: ObservableObject {
}
}
func connect(configJSON: String, resolvedRemoteAddress: String, node: VPNNode, route: RouteMode) async throws {
func connect(
configJSON: String,
resolvedRemoteAddress: String,
node: VPNNode,
route: RouteMode,
internalEndpoint: ProxyTransportEndpoint? = nil,
configContract: Int? = nil,
connectionScope: String? = nil
) async throws {
guard route.id != "direct" else {
disconnect()
try await disconnectAndWait()
return
}
if let internalEndpoint {
guard internalEndpoint.address == resolvedRemoteAddress,
ProxyTransportPolicy.authorizedInternalEndpoint(
endpoint: internalEndpoint, nodeSlug: node.slug, configContract: configContract,
connectionScope: connectionScope, routeMode: route.id, configJSON: configJSON
) != nil else {
throw UCVLError.invalidConfiguration("内部入口与后台授权节点不一致。")
}
} else if !NetworkAddress.isPublicIPv4(resolvedRemoteAddress) {
throw UCVLError.invalidConfiguration("公网入口地址不可用。")
}
let selected = try await loadManager()
let tunnelProtocol = NETunnelProviderProtocol()
tunnelProtocol.providerBundleIdentifier = "cn.toplc.zonghengjia.PacketTunnel"
tunnelProtocol.serverAddress = node.name
tunnelProtocol.disconnectOnSleep = false
tunnelProtocol.includeAllNetworks = false
tunnelProtocol.providerConfiguration = [
var configuration: [String: Any] = [
"configJSON": configJSON,
"resolvedRemoteAddress": resolvedRemoteAddress,
"nodeSlug": node.slug,
"nodeName": node.name,
"routeMode": route.id,
]
if let internalEndpoint {
configuration["internalEndpointJSON"] = try JSONEncoder().encode(internalEndpoint)
configuration["configContract"] = configContract
configuration["connectionScope"] = connectionScope ?? ""
}
tunnelProtocol.providerConfiguration = configuration
selected.localizedDescription = "优创⁺纵横家"
selected.localizedDescription = "纵横家"
selected.protocolConfiguration = tunnelProtocol
selected.isEnabled = true
try await save(selected)
@@ -68,7 +96,7 @@ final class VPNController: ObservableObject {
try selected.connection.startVPNTunnel()
} catch {
activeNodeSlug = nil
throw UCVLError.vpnPermission("系统 VPN 启动失败,请在“设置”中允许优创⁺纵横家添加 VPN 配置。")
throw UCVLError.vpnPermission("系统 VPN 启动失败,请在“设置”中允许纵横家添加 VPN 配置。")
}
do {
try await waitUntilConnected(selected.connection)
@@ -84,15 +112,16 @@ final class VPNController: ObservableObject {
activeNodeSlug = nil
}
func disconnectAndWait(timeout: TimeInterval = 8) async {
func disconnectAndWait(timeout: TimeInterval = 8) async throws {
disconnect()
let deadline = Date().addingTimeInterval(timeout)
while Date() < deadline {
let deadline = ProcessInfo.processInfo.systemUptime + timeout
while ProcessInfo.processInfo.systemUptime < deadline {
let current = manager?.connection.status ?? .disconnected
status = current
if current == .disconnected || current == .invalid { return }
try? await Task.sleep(nanoseconds: 200_000_000)
try await Task.sleep(nanoseconds: 200_000_000)
}
throw UCVLError.invalidConfiguration("系统 VPN 尚未完成断开,已停止切换线路,请稍后重试。")
}
var isConnected: Bool {