This commit is contained in:
anlicheng 2025-08-03 22:20:24 +08:00
parent d8644bd366
commit 2998514533
4 changed files with 15 additions and 5 deletions

View File

@ -7,12 +7,12 @@
<key>Tun.xcscheme_^#shared#^_</key> <key>Tun.xcscheme_^#shared#^_</key>
<dict> <dict>
<key>orderHint</key> <key>orderHint</key>
<integer>0</integer> <integer>1</integer>
</dict> </dict>
<key>punchnet.xcscheme_^#shared#^_</key> <key>punchnet.xcscheme_^#shared#^_</key>
<dict> <dict>
<key>orderHint</key> <key>orderHint</key>
<integer>1</integer> <integer>0</integer>
</dict> </dict>
</dict> </dict>
</dict> </dict>

View File

@ -75,7 +75,11 @@ struct ContentView: View {
.cornerRadius(5.0) .cornerRadius(5.0)
.onTapGesture { .onTapGesture {
Task { Task {
do {
try await self.clickSwitchButton() try await self.clickSwitchButton()
} catch let err {
NSLog("start vpn get error: \(err)")
}
} }
} }

View File

@ -6,15 +6,21 @@
// //
import Foundation import Foundation
enum PunchnetError: Error {
case dnsUnreachable
}
struct PunchnetConfig { struct PunchnetConfig {
static let server = "punchnet.aioe.tech" static let server = "punchnet.aioe.tech"
static let port = 18083 static let port = 18083
static func getOptions() -> [String:NSObject] { static func getOptions() throws -> [String:NSObject] {
var options: [String: NSObject] = [:] var options: [String: NSObject] = [:]
if let ip = DNSResolver.resolveAddrInfos(PunchnetConfig.server).first { if let ip = DNSResolver.resolveAddrInfos(PunchnetConfig.server).first {
options["super_ip"] = ip as NSObject options["super_ip"] = ip as NSObject
} else {
throw PunchnetError.dnsUnreachable
} }
return options return options

View File

@ -32,7 +32,7 @@ class VPNManager: ObservableObject {
try await manager.loadFromPreferences() try await manager.loadFromPreferences()
self.addVPNStatusObserver(manager) self.addVPNStatusObserver(manager)
var configOptions = PunchnetConfig.getOptions() var configOptions = try PunchnetConfig.getOptions()
configOptions.merge(options, uniquingKeysWith: {$1}) configOptions.merge(options, uniquingKeysWith: {$1})
try manager.connection.startVPNTunnel(options: configOptions) try manager.connection.startVPNTunnel(options: configOptions)