From 6a9a7c424ee03a62621bddea214c5f0bf1f54f6b Mon Sep 17 00:00:00 2001 From: wangjia <809946525@qq.com> Date: Fri, 19 Jun 2026 15:43:42 +0800 Subject: [PATCH] =?UTF-8?q?feat(client/macos):=20=E4=B8=BB=20app=20VPN=20?= =?UTF-8?q?=E6=8E=A5=E7=BA=BF=E7=BC=96=E8=AF=91=E9=80=9A=E8=BF=87=20?= =?UTF-8?q?=E2=80=94=20VpnChannel=20=E5=85=A5=20Runner=20target?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - VpnChannel.swift 加入 Runner target(Compile Sources) - Logger→NSLog(Runner 部署目标 10.15,os.Logger 需 11)+ 去掉未用的 SystemExtensions import - 至此原生 VPN 控制链路全编译通过:主 app(NETunnelProviderManager 启停/ 状态)+ 扩展(libbox)。kUseNativeVpnMacOS 仍 false(待隧道能跑切换)。 Co-Authored-By: Claude Opus 4.8 --- client/macos/Runner.xcodeproj/project.pbxproj | 4 ++++ client/macos/Runner/VpnChannel.swift | 7 +++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/client/macos/Runner.xcodeproj/project.pbxproj b/client/macos/Runner.xcodeproj/project.pbxproj index adee338..f53522e 100644 --- a/client/macos/Runner.xcodeproj/project.pbxproj +++ b/client/macos/Runner.xcodeproj/project.pbxproj @@ -37,6 +37,7 @@ A17B79FC2FE526F5001ABF28 /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A17B79FB2FE526F5001ABF28 /* SystemConfiguration.framework */; }; A17B79FE2FE52708001ABF28 /* AppKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A17B79FD2FE52708001ABF28 /* AppKit.framework */; }; A17B7A002FE52723001ABF28 /* libresolv.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = A17B79FF2FE52715001ABF28 /* libresolv.tbd */; }; + A17B7A072FE52A10001ABF28 /* VpnChannel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A17B7A062FE52A10001ABF28 /* VpnChannel.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -127,6 +128,7 @@ A17B79FB2FE526F5001ABF28 /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = System/Library/Frameworks/SystemConfiguration.framework; sourceTree = SDKROOT; }; A17B79FD2FE52708001ABF28 /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = System/Library/Frameworks/AppKit.framework; sourceTree = SDKROOT; }; A17B79FF2FE52715001ABF28 /* libresolv.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libresolv.tbd; path = usr/lib/libresolv.tbd; sourceTree = SDKROOT; }; + A17B7A062FE52A10001ABF28 /* VpnChannel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VpnChannel.swift; sourceTree = ""; }; B21E68FC1F5D33DD67A0DF5E /* Pods-RunnerTests.profile.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RunnerTests.profile.xcconfig"; path = "Target Support Files/Pods-RunnerTests/Pods-RunnerTests.profile.xcconfig"; sourceTree = ""; }; C55C525CAAF7B3313B74AC65 /* Pods-Runner.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"; sourceTree = ""; }; C57BBFD43F9175D1E23685EF /* Pods-RunnerTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RunnerTests.debug.xcconfig"; path = "Target Support Files/Pods-RunnerTests/Pods-RunnerTests.debug.xcconfig"; sourceTree = ""; }; @@ -249,6 +251,7 @@ 33FAB671232836740065AC1E /* Runner */ = { isa = PBXGroup; children = ( + A17B7A062FE52A10001ABF28 /* VpnChannel.swift */, 33CC10F02044A3C60003C045 /* AppDelegate.swift */, 33CC11122044BFA00003C045 /* MainFlutterWindow.swift */, 33E51913231747F40026EE4D /* DebugProfile.entitlements */, @@ -561,6 +564,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + A17B7A072FE52A10001ABF28 /* VpnChannel.swift in Sources */, 33CC11132044BFA00003C045 /* MainFlutterWindow.swift in Sources */, 33CC10F12044A3C60003C045 /* AppDelegate.swift in Sources */, 335BBD1B22A9A15E00E9071D /* GeneratedPluginRegistrant.swift in Sources */, diff --git a/client/macos/Runner/VpnChannel.swift b/client/macos/Runner/VpnChannel.swift index e36ae2f..4057510 100644 --- a/client/macos/Runner/VpnChannel.swift +++ b/client/macos/Runner/VpnChannel.swift @@ -12,10 +12,9 @@ import FlutterMacOS import NetworkExtension -import SystemExtensions -import os -private let log = Logger(subsystem: "com.pangolin.pangolin", category: "vpn") +// NSLog 兼容老部署目标(Runner < macOS 11,os.Logger 不可用)。 +private func vpnLog(_ message: String) { NSLog("[pangolin/vpn] %@", message) } final class VpnChannel: NSObject { private static let tunnelBundleId = "com.pangolin.pangolin.PacketTunnel" @@ -76,7 +75,7 @@ final class VpnChannel: NSObject { ]) result(nil) } catch { - log.error("start failed: \(error.localizedDescription)") + vpnLog("start failed: \(error.localizedDescription)") result(FlutterError(code: "start_failed", message: error.localizedDescription, details: nil)) } }