feat(client/macos): P1 方案B 骨架 — System Extension + NETunnelProviderManager 接线
ci-pangolin / Lint — shellcheck (push) Has been cancelled
ci-pangolin / OpenAPI Sync Check (push) Has been cancelled
ci-pangolin / Redline Scan — 脱敏 (UI 文案) (push) Has been cancelled
ci-pangolin / Flutter — analyze + test (push) Has been cancelled

把 PoC 的 sudo sing-box 外部二进制换成自包含、免 root 的 NEPacketTunnelProvider
(System Extension)+ 嵌入 libbox 的生产架构铺好骨架(不破坏现有 PoC 构建)。

- PacketTunnel/:扩展 target 源 — PacketTunnelProvider(LibboxSetup→NewService→start,
  openTun 建 NEPacketTunnelNetworkSettings)、Info.plist(NEProviderClasses)、
  entitlements(packet-tunnel-provider-systemextension + App Group)
- Runner/VpnChannel.swift:主 app 经 NETunnelProviderManager 启停 + 状态/速率回传,
  对齐 Dart 侧 VpnNativeBridge 的 pangolin/vpn channel 契约
- vpn_bridge_provider.dart:kUseNativeVpnMacOS 开关(默认 false,联调通过后置 true)
- docs/p1-macos-system-extension.md:文件清单 + Xcode/签名步骤 + 待办
  (Team BYL4KQHMTN;Network Extensions 已确认自助开通、无需 Apple 审批)

非破坏:新源文件未入 build target、注册行/app-group entitlements 均注释、gate 默认 false。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
wangjia
2026-06-19 11:07:36 +08:00
parent 64a1a64c3f
commit b25c8bbc2c
10 changed files with 480 additions and 6 deletions
+12 -3
View File
@@ -13,11 +13,20 @@ import 'vpn_bridge_mock.dart';
// Web 平台须先检查 kIsWebdart:io 在 Web 上不可用)。
import 'dart:io' show Platform;
/// P1 方案B 开关:macOS 是否走原生 System Extension(VpnNativeBridge)而非 PoC 的
/// sudo 子进程(DesktopVpnBridge)。默认 false——待 PacketTunnel target/签名就绪、
/// 原生侧联调通过后置 true。见 docs/p1-macos-system-extension.md。
const bool kUseNativeVpnMacOS = false;
/// 全局单例 VpnBridge。Ref 生命周期内不变。
final vpnBridgeProvider = Provider<VpnBridge>((ref) {
if (!kIsWeb &&
(Platform.isMacOS || Platform.isLinux || Platform.isWindows)) {
return DesktopVpnBridge();
if (!kIsWeb) {
if (Platform.isMacOS && kUseNativeVpnMacOS) {
return VpnNativeBridge();
}
if (Platform.isMacOS || Platform.isLinux || Platform.isWindows) {
return DesktopVpnBridge();
}
}
return VpnBridgeMock();
});