From 2998514533f23792fc4acccf68f4e6d30ae7d9f1 Mon Sep 17 00:00:00 2001 From: anlicheng <244108715@qq.com> Date: Sun, 3 Aug 2025 22:20:24 +0800 Subject: [PATCH] fix --- .../xcschemes/xcschememanagement.plist | 4 ++-- punchnet/ContentView.swift | 6 +++++- punchnet/Core/PunchnetConfig.swift | 8 +++++++- punchnet/VPNManager.swift | 2 +- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/punchnet.xcodeproj/xcuserdata/anlicheng.xcuserdatad/xcschemes/xcschememanagement.plist b/punchnet.xcodeproj/xcuserdata/anlicheng.xcuserdatad/xcschemes/xcschememanagement.plist index 4e9260e..516c2c6 100644 --- a/punchnet.xcodeproj/xcuserdata/anlicheng.xcuserdatad/xcschemes/xcschememanagement.plist +++ b/punchnet.xcodeproj/xcuserdata/anlicheng.xcuserdatad/xcschemes/xcschememanagement.plist @@ -7,12 +7,12 @@ Tun.xcscheme_^#shared#^_ orderHint - 0 + 1 punchnet.xcscheme_^#shared#^_ orderHint - 1 + 0 diff --git a/punchnet/ContentView.swift b/punchnet/ContentView.swift index baeab9f..8256770 100644 --- a/punchnet/ContentView.swift +++ b/punchnet/ContentView.swift @@ -75,7 +75,11 @@ struct ContentView: View { .cornerRadius(5.0) .onTapGesture { Task { - try await self.clickSwitchButton() + do { + try await self.clickSwitchButton() + } catch let err { + NSLog("start vpn get error: \(err)") + } } } diff --git a/punchnet/Core/PunchnetConfig.swift b/punchnet/Core/PunchnetConfig.swift index c8e9dbe..0fd065f 100644 --- a/punchnet/Core/PunchnetConfig.swift +++ b/punchnet/Core/PunchnetConfig.swift @@ -6,15 +6,21 @@ // import Foundation +enum PunchnetError: Error { + case dnsUnreachable +} + struct PunchnetConfig { static let server = "punchnet.aioe.tech" static let port = 18083 - static func getOptions() -> [String:NSObject] { + static func getOptions() throws -> [String:NSObject] { var options: [String: NSObject] = [:] if let ip = DNSResolver.resolveAddrInfos(PunchnetConfig.server).first { options["super_ip"] = ip as NSObject + } else { + throw PunchnetError.dnsUnreachable } return options diff --git a/punchnet/VPNManager.swift b/punchnet/VPNManager.swift index b8d61ca..d905fab 100644 --- a/punchnet/VPNManager.swift +++ b/punchnet/VPNManager.swift @@ -32,7 +32,7 @@ class VPNManager: ObservableObject { try await manager.loadFromPreferences() self.addVPNStatusObserver(manager) - var configOptions = PunchnetConfig.getOptions() + var configOptions = try PunchnetConfig.getOptions() configOptions.merge(options, uniquingKeysWith: {$1}) try manager.connection.startVPNTunnel(options: configOptions)