447f3f494e
经长链路排查(同机对照可工作的 Tailscale),修复 macOS 系统扩展 realize 失败(OSSystemExtensionErrorDomain code=4)与 libbox 运行时崩溃,使内嵌 sing-box 的系统扩展能在 macOS 15 上激活并启动隧道。 系统扩展 realize(三个叠加根因): - 扩展自包含:PacketTunnel 加 OTHER_LDFLAGS="" 切断对项目级 CocoaPods 链接 标志的继承(原会把 flutter_secure_storage 链进扩展);Libbox.xcframework 改纯 Link(静态),从 Embed Frameworks 移除冗余内嵌 - bundle 名 = 标识符:PRODUCT_NAME 设为 com.pangolin.pangolin.PacketTunnel - 扩展 Info.plist 补 NSSystemExtensionUsageDescription(网络扩展类别强制要求) - App Group 改 macOS 原生格式 BYL4KQHMTN.com.pangolin.pangolin;NEMachServiceName 以其为前缀;扩展补 network.client/server;get-task-allow=false + 签名加 --timestamp - CFBundleVersion 随构建递增(否则 sysextd 视为同版本不更新) libbox 运行时: - startOrReloadService(options:) 传 nil 致空指针 SIGSEGV → 传 LibboxOverrideOptions() - 默认接口监控阻塞到首个 path 更新再返回,修 "no available network interface" 配套: - scripts/local_test.sh:build/sign/notarize/copy/run 一条龙(Developer ID + 公证) - client/macos/sign_libbox.sh:构建期以 Developer ID 重签内嵌 Libbox - VpnChannel:401 自动刷新 token、详尽 os_log;auth/api 统一走 kApiBaseUrl - docs/macos-sysext-realize-troubleshooting.html:完整踩坑复盘 WIP / 临时(后续清理): - 隧道运行时仍在排查:剥离远程 rule-set 后 sing-box 启动卡点未定位 - 含临时诊断代码:main.swift stderr 重定向、box.log 输出、rule-set 剥离、debug 日志 - api_config 仍指向联调节点,发版前还原 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JEHzjEcFzvGwgbxT6Wbt6c
33 lines
1.2 KiB
Dart
33 lines
1.2 KiB
Dart
// vpn_bridge_provider.dart — VpnBridge 平台分派
|
||
//
|
||
// macOS / Linux / Windows → DesktopVpnBridge(真实子进程)
|
||
// 其他平台(iOS / Web / 测试)→ VpnBridgeMock
|
||
import 'package:flutter/foundation.dart';
|
||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||
|
||
import 'desktop_vpn_bridge.dart';
|
||
import 'vpn_bridge.dart';
|
||
import 'vpn_bridge_mock.dart';
|
||
|
||
// 通过 dart:io Platform 按平台选择实现。
|
||
// Web 平台须先检查 kIsWeb(dart: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 = true;
|
||
|
||
/// 全局单例 VpnBridge。Ref 生命周期内不变。
|
||
final vpnBridgeProvider = Provider<VpnBridge>((ref) {
|
||
if (!kIsWeb) {
|
||
if (Platform.isMacOS && kUseNativeVpnMacOS) {
|
||
return VpnNativeBridge();
|
||
}
|
||
if (Platform.isMacOS || Platform.isLinux || Platform.isWindows) {
|
||
return DesktopVpnBridge();
|
||
}
|
||
}
|
||
return VpnBridgeMock();
|
||
});
|