Fix VPN internet connectivity and simplify client setup
Initialize Android physical interfaces and preserve macOS scoped routes. Add redacted diagnostics, default DNS, ordered auto-save, simplified controls, scanner rotation settings, and native regression coverage. Restore vendored build sources and document validation and stability checks.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||
@@ -8,6 +9,10 @@
|
||||
android:label="MeshPort"
|
||||
android:name="${applicationName}"
|
||||
android:icon="@mipmap/ic_launcher">
|
||||
<!-- Override ZXing's sensorLandscape default and respect user rotation. -->
|
||||
<activity android:name="com.journeyapps.barcodescanner.CaptureActivity"
|
||||
android:screenOrientation="fullUser"
|
||||
tools:replace="android:screenOrientation" />
|
||||
<service android:name=".MeshVpnService" android:exported="false"
|
||||
android:permission="android.permission.BIND_VPN_SERVICE" android:foregroundServiceType="specialUse">
|
||||
<intent-filter><action android:name="android.net.VpnService" /></intent-filter>
|
||||
|
||||
@@ -33,6 +33,13 @@ class MainActivity : FlutterActivity() {
|
||||
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
|
||||
super.configureFlutterEngine(flutterEngine)
|
||||
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, "meshport/system_vpn").setMethodCallHandler { call, result ->
|
||||
if (call.method == "runtime_log") {
|
||||
// Flutter redacts credentials before sending these bounded events.
|
||||
val text = call.arguments as? String ?: ""
|
||||
Log.i("MeshPortRuntime", text.take(4096))
|
||||
result.success(null)
|
||||
return@setMethodCallHandler
|
||||
}
|
||||
if (call.method in listOf("import_file", "import_qr_image", "scan_qr")) {
|
||||
if (importResult != null) { result.error("IMPORT_BUSY", "Import already open", null); return@setMethodCallHandler }
|
||||
importResult = result
|
||||
|
||||
+6
-1
@@ -40,7 +40,7 @@ class MeshVpnService : VpnService() {
|
||||
manager.createNotificationChannel(NotificationChannel("meshport_vpn", "MeshPort 组网", NotificationManager.IMPORTANCE_LOW))
|
||||
val open = PendingIntent.getActivity(this, 0, Intent(this, MainActivity::class.java), PendingIntent.FLAG_IMMUTABLE)
|
||||
startForeground(77, Notification.Builder(this, "meshport_vpn")
|
||||
.setContentTitle("MeshPort").setContentText("虚拟组网服务正在运行")
|
||||
.setContentTitle("MeshPort").setContentText("VPN 服务正在运行")
|
||||
.setSmallIcon(R.drawable.ic_stat_meshport).setContentIntent(open).setOngoing(true).build())
|
||||
worker.scheduleWithFixedDelay({
|
||||
if (running) try {
|
||||
@@ -177,6 +177,7 @@ class MeshVpnService : VpnService() {
|
||||
private fun startUnified(config: String) {
|
||||
val manager = getSystemService(ConnectivityManager::class.java)
|
||||
physical = physicalNetwork(); setUnderlyingNetworks(arrayOf(physical!!))
|
||||
Log.i("MeshPortVPN", "Unified VPN: physical network selected; mesh enabled=$meshEnabled")
|
||||
if (meshEnabled) {
|
||||
val validated = native(JSONObject().put("op","validate").put("toml",config)).getJSONObject("data")
|
||||
check(validated.getString("runtime_mode") == "application") { "Unified VPN requires application-mode MeshPort" }
|
||||
@@ -204,11 +205,13 @@ class MeshVpnService : VpnService() {
|
||||
builder.allowFamily(OsConstants.AF_INET6)
|
||||
}
|
||||
tun = builder.establish() ?: error("VPN authorization revoked")
|
||||
Log.i("MeshPortVPN", "Unified VPN: TUN established; internet routes=$internet")
|
||||
proxyHandle = NativeBridge.newProxyContext()
|
||||
check(proxyHandle != 0L)
|
||||
proxyCall(JSONObject().put("op","configure_cache").put("directory",cacheDir.absolutePath))
|
||||
restartProxy(routes)
|
||||
running = true
|
||||
Log.i("MeshPortVPN", "Unified VPN: proxy engine ready")
|
||||
networkCallback = object: ConnectivityManager.NetworkCallback() {
|
||||
override fun onAvailable(network: android.net.Network) { worker.execute { updatePhysical() } }
|
||||
override fun onLost(network: android.net.Network) { worker.execute { updatePhysical() } }
|
||||
@@ -250,6 +253,7 @@ class MeshVpnService : VpnService() {
|
||||
.put("tun",JSONObject().put("fd",tun!!.fd).put("name",NativeBridge.tunName(tun!!.fd) ?: error("TUN name unavailable"))
|
||||
.put("physical_interface",iface).put("physical_index",index))
|
||||
proxyCall(JSONObject().put("op","start").put("config",config))
|
||||
Log.i("MeshPortVPN", "Unified VPN: protected physical sockets; learned routes=${routes.size}")
|
||||
installed = routes
|
||||
}
|
||||
private fun unifiedStatus(): JSONObject {
|
||||
@@ -262,6 +266,7 @@ class MeshVpnService : VpnService() {
|
||||
return JSONObject().put("ok",true).put("data",data)
|
||||
}
|
||||
private fun shutdown() {
|
||||
if (running || handle != 0L || proxyHandle != 0L || tun != null) Log.i("MeshPortVPN", "Stopping VPN and releasing TUN")
|
||||
running = false
|
||||
if (proxyHandle != 0L) { NativeBridge.freeProxyContext(proxyHandle); proxyHandle = 0L }
|
||||
val connectivity = getSystemService(ConnectivityManager::class.java)
|
||||
|
||||
@@ -0,0 +1,168 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'dart:typed_data';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:integration_test/integration_test.dart';
|
||||
import 'package:meshport_client_core/meshport_client_core.dart';
|
||||
import 'package:meshport_flutter/meshport_flutter.dart';
|
||||
|
||||
const channel = MethodChannel('meshport/system_vpn');
|
||||
const fixtureHost = String.fromEnvironment('ANDROID_PROXY_FIXTURE');
|
||||
|
||||
Future<void> httpsCheck() async {
|
||||
final client = HttpClient()..connectionTimeout = const Duration(seconds: 20);
|
||||
try {
|
||||
final request = await client.getUrl(
|
||||
Uri.parse('https://www.gstatic.com/generate_204'),
|
||||
);
|
||||
final reply = await request.close().timeout(const Duration(seconds: 30));
|
||||
expect(reply.statusCode, 204);
|
||||
await reply.drain<void>();
|
||||
} finally {
|
||||
client.close(force: true);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> proxyTcpCheck() async {
|
||||
final client = HttpClient()..connectionTimeout = const Duration(seconds: 10);
|
||||
try {
|
||||
final request = await client.getUrl(
|
||||
Uri.parse('http://198.51.100.45:18082/meshport-device-test'),
|
||||
);
|
||||
final reply = await request.close().timeout(const Duration(seconds: 15));
|
||||
expect(reply.statusCode, 200);
|
||||
expect(await utf8.decoder.bind(reply).join(), 'MeshPort proxy fixture');
|
||||
} finally {
|
||||
client.close(force: true);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> udpCheck() async {
|
||||
final socket = await RawDatagramSocket.bind(InternetAddress.anyIPv4, 0);
|
||||
final reply = Completer<Datagram>();
|
||||
final subscription = socket.listen((event) {
|
||||
if (event == RawSocketEvent.read) {
|
||||
final packet = socket.receive();
|
||||
if (packet != null && !reply.isCompleted) reply.complete(packet);
|
||||
}
|
||||
}, onError: reply.completeError);
|
||||
final payload = utf8.encode('MeshPort Android UDP');
|
||||
try {
|
||||
socket.send(payload, InternetAddress('198.51.100.45'), 18083);
|
||||
expect(
|
||||
(await reply.future.timeout(const Duration(seconds: 15))).data,
|
||||
orderedEquals(payload),
|
||||
);
|
||||
} finally {
|
||||
await subscription.cancel();
|
||||
socket.close();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> tunDnsCheck() async {
|
||||
final socket = await RawDatagramSocket.bind(InternetAddress.anyIPv4, 0);
|
||||
final reply = Completer<Datagram>();
|
||||
final subscription = socket.listen((event) {
|
||||
if (event == RawSocketEvent.read) {
|
||||
final packet = socket.receive();
|
||||
if (packet != null && !reply.isCompleted) reply.complete(packet);
|
||||
}
|
||||
}, onError: reply.completeError);
|
||||
// An uncached name asks the VPN DNS server to use the default encrypted DNS.
|
||||
final packet = BytesBuilder()
|
||||
..add([0x4d, 0x50, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0]);
|
||||
for (final label in 'example.com'.split('.')) {
|
||||
packet.addByte(label.length);
|
||||
packet.add(ascii.encode(label));
|
||||
}
|
||||
packet.add([0, 0, 1, 0, 1]);
|
||||
try {
|
||||
socket.send(packet.toBytes(), InternetAddress('172.19.0.2'), 53);
|
||||
final data = (await reply.future.timeout(const Duration(seconds: 30))).data;
|
||||
expect(data.length, greaterThan(12));
|
||||
expect(data.take(2), [0x4d, 0x50]);
|
||||
expect(data[3] & 15, 0, reason: 'DNS response must succeed');
|
||||
expect((data[6] << 8) | data[7], greaterThan(0));
|
||||
} finally {
|
||||
await subscription.cancel();
|
||||
socket.close();
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
|
||||
testWidgets(
|
||||
'Android unified VPN default DNS and proxy data plane',
|
||||
(tester) async {
|
||||
expect(fixtureHost, isNotEmpty);
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(
|
||||
home: Scaffold(body: Center(child: Text('MeshPort Android 代理验证中'))),
|
||||
),
|
||||
);
|
||||
expect(await channel.invokeMethod<bool>('debug_storage_self_test'), true);
|
||||
await httpsCheck();
|
||||
debugPrint('ANDROID_BASELINE_HTTPS_PASS');
|
||||
final profile = ProxyProfile()
|
||||
..feature = 'proxy'
|
||||
..mode = 'global'
|
||||
..entry = 'unified_vpn';
|
||||
profile.addNodes(
|
||||
importProxyNodes('socks5://$fixtureHost:18084#Device-test').nodes,
|
||||
);
|
||||
profile.validateConnection();
|
||||
expect(profile.selectedId, profile.nodes.single.id);
|
||||
expect(profile.effectiveProxyDns, ProxyProfile.defaultProxyDns);
|
||||
debugPrint('WAITING_FOR_ANDROID_VPN_PERMISSION');
|
||||
final vpn = await openAndroidSystemVpn(
|
||||
prepare: () => channel.invokeMethod<void>('prepare_android_vpn'),
|
||||
request: (request) async =>
|
||||
jsonDecode(
|
||||
(await channel.invokeMethod<String>(
|
||||
'android_vpn_request',
|
||||
jsonEncode(request),
|
||||
))!,
|
||||
)
|
||||
as Map<String, dynamic>,
|
||||
);
|
||||
try {
|
||||
for (var attempt = 0; attempt < 2; attempt++) {
|
||||
await vpn.request({
|
||||
'op': 'start',
|
||||
'toml': '', // Proxy-only must not require a mesh configuration.
|
||||
'unified_profile': profile.runtime(),
|
||||
});
|
||||
// Wait for system clients to observe the newly established VPN.
|
||||
await Future<void>.delayed(const Duration(seconds: 2));
|
||||
final state = await vpn.status();
|
||||
expect(state['state'], 'Running');
|
||||
expect(state['platform_network']['ready'], true);
|
||||
await proxyTcpCheck();
|
||||
debugPrint('ANDROID_UNIFIED_OS_TCP_PASS_$attempt');
|
||||
await udpCheck();
|
||||
debugPrint('ANDROID_UNIFIED_OS_UDP_PASS_$attempt');
|
||||
await tunDnsCheck();
|
||||
debugPrint('ANDROID_DEFAULT_DOH_PASS_$attempt');
|
||||
await httpsCheck();
|
||||
debugPrint('ANDROID_UNIFIED_HTTPS_PASS_$attempt');
|
||||
await vpn.stop();
|
||||
await Future<void>.delayed(const Duration(seconds: 2));
|
||||
expect((await vpn.status())['state'], 'Stopped');
|
||||
await httpsCheck();
|
||||
debugPrint('ANDROID_NETWORK_RESTORED_PASS_$attempt');
|
||||
}
|
||||
} catch (_) {
|
||||
debugPrint(
|
||||
'ANDROID_UNIFIED_FAILURE_STATE ${jsonEncode(await vpn.status())}',
|
||||
);
|
||||
rethrow;
|
||||
} finally {
|
||||
await vpn.close();
|
||||
}
|
||||
},
|
||||
timeout: const Timeout(Duration(minutes: 8)),
|
||||
);
|
||||
}
|
||||
@@ -8,7 +8,9 @@ class MeshPortApp extends StatelessWidget {
|
||||
title: 'MeshPort',
|
||||
debugShowCheckedModeBanner: false,
|
||||
theme: meshPortTheme(),
|
||||
home: const LabScreen(),
|
||||
home: const LabScreen(
|
||||
initializeNative: !bool.fromEnvironment('MESHPORT_UI_PREVIEW'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -452,7 +452,7 @@ class _DnsPageState extends State<DnsPage> {
|
||||
style: TextStyle(color: Theme.of(context).colorScheme.error),
|
||||
),
|
||||
const Text(
|
||||
'代理模式下须明确配置代理 DNS;普通域名解析经所选代理,失败不回退直连 DNS。启动 DNS 仅用于节点和解析器地址,组网域名走组网 DNS。直连模式不提供代理 DNS 防泄露;应用内入口仅保护交给它的流量。',
|
||||
'默认使用 Cloudflare 加密 DNS,经所选代理查询,失败不回退直连。代理 DNS 留空时使用默认值。直连模式使用直连 DNS。启动 DNS 用于连接节点和解析器,组网域名走组网 DNS。',
|
||||
),
|
||||
TextField(
|
||||
controller: bootstrap,
|
||||
@@ -475,7 +475,8 @@ class _DnsPageState extends State<DnsPage> {
|
||||
onChanged: (_) => setState(() => dirty = true),
|
||||
decoration: const InputDecoration(
|
||||
labelText: '代理 DNS',
|
||||
helperText: '代理模式必填:IP / DoH / DoT;经所选代理,失败不回退',
|
||||
helperText:
|
||||
'留空使用 https://cloudflare-dns.com/dns-query;支持 IP / DoH / DoT',
|
||||
),
|
||||
),
|
||||
SwitchListTile(
|
||||
|
||||
@@ -204,7 +204,9 @@ class LogsPageBody extends StatelessWidget {
|
||||
Widget build(BuildContext context) => Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
const Text('仅保留本次应用会话最近 300 条事件,不写日志文件。复制会保留节点地址,但移除认证信息。'),
|
||||
const Text(
|
||||
'显示本次应用会话最近 300 条事件。macOS 同步写入系统日志,可在 Console 中筛选 MeshPort / Runtime。复制保留节点地址,隐藏认证信息。',
|
||||
),
|
||||
Wrap(
|
||||
spacing: 12,
|
||||
children: [
|
||||
|
||||
@@ -11,6 +11,7 @@ import 'network_telemetry.dart';
|
||||
import 'proxy_panel.dart';
|
||||
import 'configuration_pages.dart';
|
||||
import 'detail_pages.dart';
|
||||
import 'runtime_diagnostics.dart';
|
||||
|
||||
class LabScreen extends StatefulWidget {
|
||||
const LabScreen({super.key, this.initializeNative = true});
|
||||
@@ -21,12 +22,22 @@ class LabScreen extends StatefulWidget {
|
||||
|
||||
class _LabScreenState extends State<LabScreen> {
|
||||
MeshPortClient? client, applicationClient, systemClient;
|
||||
String runtimeMode = 'application';
|
||||
String runtimeMode = Platform.isMacOS || Platform.isAndroid
|
||||
? 'unified_vpn'
|
||||
: 'application';
|
||||
bool singBoxEnabled = false;
|
||||
MeshProxySession? proxySession;
|
||||
ProxyProfile proxyProfile = ProxyProfile();
|
||||
ProxyProfile proxyProfile = ProxyProfile()
|
||||
..feature = 'proxy'
|
||||
..mode = 'global'
|
||||
..entry = (Platform.isMacOS || Platform.isAndroid
|
||||
? 'unified_vpn'
|
||||
: 'application');
|
||||
String runningProxyLabel = '', runningProxyMode = '';
|
||||
bool proxyDraftChanged = false;
|
||||
int proxySavesPending = 0;
|
||||
bool proxySaveFailed = false;
|
||||
Future<void> proxySaveTail = Future.value();
|
||||
bool rememberConfig = false;
|
||||
String? savedConfig;
|
||||
String? loadedConfig, loadedForm;
|
||||
@@ -54,6 +65,9 @@ class _LabScreenState extends State<LabScreen> {
|
||||
Map<String, dynamic> status = {'state': 'Stopped', 'peer_count': 0};
|
||||
Map<String, dynamic>? result;
|
||||
final logs = <String>[];
|
||||
final diagnosticRedactor = DiagnosticRedactor();
|
||||
String lastProxyState = '';
|
||||
int proxyEventSequence = 0;
|
||||
final latencies = <double>[];
|
||||
final name = TextEditingController(text: 'game-net');
|
||||
final secret = TextEditingController();
|
||||
@@ -81,9 +95,11 @@ class _LabScreenState extends State<LabScreen> {
|
||||
|
||||
Future<void> initialize() async {
|
||||
try {
|
||||
log('客户端启动 · ${Platform.operatingSystem} · 代理诊断日志已开启');
|
||||
const path = String.fromEnvironment('MESHPORT_LIBRARY');
|
||||
final opened = await MeshPortClient.open(
|
||||
libraryPath: path.isEmpty ? null : path,
|
||||
final opened = await diagnosticStage(
|
||||
'加载 MeshPort 动态库',
|
||||
() => MeshPortClient.open(libraryPath: path.isEmpty ? null : path),
|
||||
);
|
||||
if (!mounted) {
|
||||
await opened.close();
|
||||
@@ -100,6 +116,9 @@ class _LabScreenState extends State<LabScreen> {
|
||||
proxyProfile = ProxyProfile.fromJson(
|
||||
jsonDecode(stored) as Map<String, dynamic>,
|
||||
);
|
||||
if (proxyProfile.entry == 'system_vpn') {
|
||||
proxyProfile.feature = 'mesh';
|
||||
}
|
||||
savedProxyJson = jsonEncode(proxyProfile.toJson());
|
||||
}
|
||||
} catch (_) {
|
||||
@@ -142,7 +161,11 @@ class _LabScreenState extends State<LabScreen> {
|
||||
await loadForm(defaults);
|
||||
if (mounted) setState(() => rememberConfig = profileSupported);
|
||||
log(
|
||||
secret.text.isEmpty
|
||||
proxyProfile.feature == 'proxy'
|
||||
? (proxyProfile.nodes.isEmpty
|
||||
? '默认代理设置已就绪,导入节点后即可连接'
|
||||
: '已载入代理设置,点击连接即可使用')
|
||||
: secret.text.isEmpty
|
||||
? '已载入默认配置,首次填写网络密钥后保存即可'
|
||||
: '已载入默认网络配置,点击连接即可组网',
|
||||
);
|
||||
@@ -150,8 +173,11 @@ class _LabScreenState extends State<LabScreen> {
|
||||
log('默认配置加载失败,请在设置中导入配置');
|
||||
}
|
||||
}
|
||||
if (proxyProfile.proxyEnabled || !restored) {
|
||||
if (savedProxyJson != null || !restored) {
|
||||
runtimeMode = proxyProfile.entry;
|
||||
} else {
|
||||
proxyProfile.feature = 'mesh';
|
||||
proxyProfile.entry = runtimeMode;
|
||||
}
|
||||
singBoxEnabled = proxyProfile.proxyEnabled;
|
||||
final diagnostics = await opened.enableDiagnostics();
|
||||
@@ -226,26 +252,19 @@ class _LabScreenState extends State<LabScreen> {
|
||||
}
|
||||
|
||||
void log(String text) {
|
||||
final secrets = <String>[
|
||||
secret.text,
|
||||
for (final node in proxyProfile.nodes)
|
||||
for (final key in ['password', 'uuid'])
|
||||
if (node.options[key] is String) node.options[key] as String,
|
||||
];
|
||||
for (final value in secrets.where((value) => value.isNotEmpty)) {
|
||||
text = text.replaceAll(value, '[已隐藏]');
|
||||
}
|
||||
text = text.replaceAllMapped(
|
||||
RegExp(r'(https?://)[^\s/]+@'),
|
||||
(m) => '${m[1]}[已隐藏]@',
|
||||
);
|
||||
text = text.replaceAllMapped(
|
||||
RegExp(r'(https?://[^\s?]+)\?[^\s]+'),
|
||||
(m) => '${m[1]}?[已隐藏]',
|
||||
);
|
||||
if (!mounted) {
|
||||
return;
|
||||
}
|
||||
diagnosticRedactor.remember({'network_secret': secret.text});
|
||||
diagnosticRedactor.remember(proxyProfile.toJson());
|
||||
text = diagnosticRedactor.sanitize(text);
|
||||
if ((Platform.isMacOS || Platform.isAndroid) && widget.initializeNative) {
|
||||
unawaited(
|
||||
vpnChannel
|
||||
.invokeMethod<void>('runtime_log', text)
|
||||
.catchError((Object _) {}),
|
||||
);
|
||||
}
|
||||
setState(() {
|
||||
logs.insert(
|
||||
0,
|
||||
@@ -257,15 +276,43 @@ class _LabScreenState extends State<LabScreen> {
|
||||
});
|
||||
}
|
||||
|
||||
Future<T> diagnosticStage<T>(
|
||||
String stage,
|
||||
Future<T> Function() action,
|
||||
) async {
|
||||
final elapsed = Stopwatch()..start();
|
||||
log('[$stage] 开始');
|
||||
try {
|
||||
final result = await action();
|
||||
log('[$stage] 成功 · ${elapsed.elapsedMilliseconds} ms');
|
||||
return result;
|
||||
} catch (e) {
|
||||
log('[$stage] 失败 · ${elapsed.elapsedMilliseconds} ms · $e');
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> refresh() async {
|
||||
if (refreshing) return;
|
||||
refreshing = true;
|
||||
try {
|
||||
final next =
|
||||
runtimeMode != 'system_vpn' && singBoxEnabled && proxySession != null
|
||||
final next = client == applicationClient && proxySession != null
|
||||
? await proxySession!.refresh()
|
||||
: await client?.status();
|
||||
if (mounted && next != null) {
|
||||
for (final event
|
||||
in (next['proxy'] as Map?)?['runtime_events'] as List? ?? []) {
|
||||
final sequence = (event['sequence'] as num).toInt();
|
||||
if (sequence > proxyEventSequence) {
|
||||
log('代理 · ${event['message']}');
|
||||
proxyEventSequence = sequence;
|
||||
}
|
||||
}
|
||||
final proxyState = proxySession?.state ?? '';
|
||||
if (proxyState != lastProxyState) {
|
||||
lastProxyState = proxyState;
|
||||
if (proxyState.isNotEmpty) log('代理会话状态 → $proxyState');
|
||||
}
|
||||
final instance = next['instance_id'] as String? ?? '';
|
||||
if (eventInstance != instance) {
|
||||
eventInstance = instance;
|
||||
@@ -449,11 +496,16 @@ class _LabScreenState extends State<LabScreen> {
|
||||
}
|
||||
|
||||
Future<void> startConfig(String config) async {
|
||||
proxyEventSequence = 0;
|
||||
if (singBoxEnabled) proxyProfile.validateConnection();
|
||||
// Validation selects mode from effective flags, avoiding ad-hoc TOML parsing.
|
||||
final validated = singBoxEnabled && proxyProfile.feature == 'proxy'
|
||||
? <String, dynamic>{'runtime_mode': 'application'}
|
||||
: await applicationClient!.request({'op': 'validate', 'toml': config});
|
||||
: await diagnosticStage(
|
||||
'校验组网配置',
|
||||
() =>
|
||||
applicationClient!.request({'op': 'validate', 'toml': config}),
|
||||
);
|
||||
final unified = runtimeMode == 'unified_vpn';
|
||||
final system = validated['runtime_mode'] == 'system_vpn' || unified;
|
||||
if (proxySession != null) {
|
||||
@@ -471,15 +523,18 @@ class _LabScreenState extends State<LabScreen> {
|
||||
if (singBoxEnabled) {
|
||||
proxySession = MeshProxySession(
|
||||
mesh: applicationClient!,
|
||||
proxy: await NativeProxyEngine.open(),
|
||||
proxy: await diagnosticStage(
|
||||
'加载 sing-box 动态库',
|
||||
NativeProxyEngine.open,
|
||||
),
|
||||
profile:
|
||||
jsonDecode(jsonEncode(proxyProfile.runtime()))
|
||||
as Map<String, dynamic>,
|
||||
);
|
||||
await proxySession!.start(config);
|
||||
await diagnosticStage('启动应用内代理会话', () => proxySession!.start(config));
|
||||
log('sing-box 组网入口:${proxySession!.endpoint ?? '等待虚拟地址'}');
|
||||
} else {
|
||||
await applicationClient!.start(config);
|
||||
await diagnosticStage('启动组网引擎', () => applicationClient!.start(config));
|
||||
}
|
||||
if (!singBoxEnabled || proxyProfile.feature != 'proxy') {
|
||||
await saveProfile(config);
|
||||
@@ -497,25 +552,35 @@ class _LabScreenState extends State<LabScreen> {
|
||||
: await openMacSystemVpn(
|
||||
launch: (path, uid) async {
|
||||
log('等待管理员授权以创建虚拟网卡');
|
||||
await vpnChannel.invokeMethod<void>('launch', {
|
||||
'socket': path,
|
||||
'uid': uid,
|
||||
});
|
||||
await diagnosticStage(
|
||||
'授权并启动 macOS VPN 辅助进程',
|
||||
() => vpnChannel.invokeMethod<void>('launch', {
|
||||
'socket': path,
|
||||
'uid': uid,
|
||||
}),
|
||||
);
|
||||
},
|
||||
);
|
||||
try {
|
||||
await opened.enableDiagnostics();
|
||||
if (unified) {
|
||||
await opened.request({
|
||||
'op': 'start',
|
||||
'toml': config,
|
||||
'unified_profile': proxyProfile.runtime(),
|
||||
});
|
||||
await diagnosticStage(
|
||||
'启动统一 VPN 代理',
|
||||
() => opened.request({
|
||||
'op': 'start',
|
||||
'toml': config,
|
||||
'unified_profile': proxyProfile.runtime(),
|
||||
}),
|
||||
);
|
||||
} else {
|
||||
await opened.start(config);
|
||||
}
|
||||
systemClient = client = opened;
|
||||
log('系统 VPN 已启动,接入虚拟网段与远端子网');
|
||||
log(
|
||||
unified && proxyProfile.feature == 'proxy'
|
||||
? '统一 VPN 已启动,互联网流量已接入'
|
||||
: '系统 VPN 已启动,接入虚拟网段与远端子网',
|
||||
);
|
||||
await saveProfile(config);
|
||||
} catch (_) {
|
||||
await opened.close();
|
||||
@@ -775,7 +840,63 @@ class _LabScreenState extends State<LabScreen> {
|
||||
},
|
||||
);
|
||||
|
||||
Widget overview() => Column(
|
||||
Widget overview() {
|
||||
if (proxyProfile.feature != 'proxy') return networkOverview();
|
||||
final selected = proxyProfile.nodes
|
||||
.where((node) => node.id == proxyProfile.selectedId)
|
||||
.firstOrNull;
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
panel('连接', [
|
||||
ListTile(
|
||||
leading: Icon(
|
||||
running ? Icons.check_circle_outline : Icons.power_settings_new,
|
||||
),
|
||||
title: Text(running ? '代理已连接' : '尚未连接'),
|
||||
subtitle: Text(
|
||||
running && runningProxyLabel.isNotEmpty
|
||||
? '$runningProxyMode · $runningProxyLabel'
|
||||
: selected == null
|
||||
? '导入一个节点即可开始'
|
||||
: '${proxyProfile.modeLabel} · ${selected.name}',
|
||||
),
|
||||
trailing: TextButton(
|
||||
onPressed: busy || client == null ? null : primaryConnection,
|
||||
child: Text(
|
||||
running ? (proxyDraftChanged ? '重连应用修改' : '断开连接') : '连接',
|
||||
),
|
||||
),
|
||||
),
|
||||
if (proxyDraftChanged) const Text('配置已修改,重连后生效。'),
|
||||
Wrap(
|
||||
spacing: 12,
|
||||
runSpacing: 12,
|
||||
children: [
|
||||
FilledButton.tonal(
|
||||
onPressed: () => setState(() => page = 1),
|
||||
child: const Text('管理代理节点'),
|
||||
),
|
||||
OutlinedButton(
|
||||
onPressed: () => openDetail(
|
||||
'运行日志',
|
||||
() => LogsPageBody(
|
||||
logs: logs,
|
||||
onClear: () => setState(() => logs.clear()),
|
||||
),
|
||||
),
|
||||
child: const Text('诊断与日志'),
|
||||
),
|
||||
],
|
||||
),
|
||||
]),
|
||||
if (logs.isNotEmpty)
|
||||
panel('最近事件', logs.take(3).map((line) => Text(line)).toList()),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget networkOverview() => Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Card(
|
||||
@@ -800,16 +921,10 @@ class _LabScreenState extends State<LabScreen> {
|
||||
: '应用内网络'}',
|
||||
),
|
||||
trailing: TextButton(
|
||||
onPressed: busy || client == null
|
||||
? null
|
||||
: () => perform(
|
||||
running
|
||||
? (c) async {
|
||||
await stopActive(c);
|
||||
}
|
||||
: connect,
|
||||
),
|
||||
child: Text(running ? '断开连接' : '连接网络'),
|
||||
onPressed: busy || client == null ? null : primaryConnection,
|
||||
child: Text(
|
||||
running ? (proxyDraftChanged ? '重连应用修改' : '断开连接') : '连接',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -916,12 +1031,22 @@ class _LabScreenState extends State<LabScreen> {
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
panel('组网配置', [
|
||||
for (final title in ['基础配置', '连接与打洞', '高级配置', '线路策略'])
|
||||
ListTile(
|
||||
title: Text(title),
|
||||
trailing: const Icon(Icons.chevron_right),
|
||||
onTap: () => openNetworkConfig(title),
|
||||
),
|
||||
ListTile(
|
||||
title: const Text('基础配置'),
|
||||
trailing: const Icon(Icons.chevron_right),
|
||||
onTap: () => openNetworkConfig('基础配置'),
|
||||
),
|
||||
ExpansionTile(
|
||||
title: const Text('高级组网设置'),
|
||||
children: [
|
||||
for (final title in ['连接与打洞', '高级配置', '线路策略'])
|
||||
ListTile(
|
||||
title: Text(title),
|
||||
trailing: const Icon(Icons.chevron_right),
|
||||
onTap: () => openNetworkConfig(title),
|
||||
),
|
||||
],
|
||||
),
|
||||
ListTile(
|
||||
title: const Text('自动接入子网'),
|
||||
trailing: const Icon(Icons.chevron_right),
|
||||
@@ -1128,10 +1253,8 @@ class _LabScreenState extends State<LabScreen> {
|
||||
onTap: () => Navigator.push<void>(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (_) => DnsPage(
|
||||
profile: proxyProfile,
|
||||
changed: () => setState(() => proxyDraftChanged = true),
|
||||
),
|
||||
builder: (_) =>
|
||||
DnsPage(profile: proxyProfile, changed: proxyChanged),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -1174,6 +1297,7 @@ class _LabScreenState extends State<LabScreen> {
|
||||
if (!mounted ||
|
||||
busy ||
|
||||
subscriptionUpdating ||
|
||||
proxySavesPending > 0 ||
|
||||
savedProxyJson != jsonEncode(proxyProfile.toJson()) ||
|
||||
!profileSupported) {
|
||||
return;
|
||||
@@ -1241,42 +1365,69 @@ class _LabScreenState extends State<LabScreen> {
|
||||
}
|
||||
|
||||
Future<void> saveProxyProfile() async {
|
||||
if (const bool.fromEnvironment('MESHPORT_UI_PREVIEW')) return;
|
||||
final text = jsonEncode(proxyProfile.toJson());
|
||||
if (utf8.encode(text).length > 65536) {
|
||||
if (mounted) setState(() => proxySaveFailed = true);
|
||||
throw const FormatException('保存配置超过 64 KiB,请减少节点数量');
|
||||
}
|
||||
await vpnChannel.invokeMethod<void>('save_proxy_profile', text);
|
||||
savedProxyJson = text;
|
||||
if (mounted && !running) setState(() => proxyDraftChanged = false);
|
||||
log('代理配置已安全保存');
|
||||
if (!profileSupported) return;
|
||||
if (mounted) setState(() => proxySavesPending++);
|
||||
final job = proxySaveTail.then((_) async {
|
||||
try {
|
||||
await vpnChannel.invokeMethod<void>('save_proxy_profile', text);
|
||||
savedProxyJson = text;
|
||||
if (mounted) setState(() => proxySaveFailed = false);
|
||||
} catch (_) {
|
||||
if (mounted) setState(() => proxySaveFailed = true);
|
||||
rethrow;
|
||||
} finally {
|
||||
if (mounted) setState(() => proxySavesPending--);
|
||||
}
|
||||
});
|
||||
proxySaveTail = job.then<void>(
|
||||
(_) {},
|
||||
onError: (Object error, StackTrace trace) {},
|
||||
);
|
||||
await job;
|
||||
}
|
||||
|
||||
void proxyChanged() {
|
||||
if (!mounted) return;
|
||||
setState(() => proxyDraftChanged = running);
|
||||
unawaited(
|
||||
saveProxyProfile().catchError((Object _) {
|
||||
log('自动保存失败,请在代理页重试保存');
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> primaryConnection() async {
|
||||
if (running && !proxyDraftChanged) {
|
||||
await perform(stopActive);
|
||||
} else {
|
||||
await connectProxy();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> connectProxy() async {
|
||||
if (runtimeMode != 'system_vpn') proxyProfile.validateConnection();
|
||||
if (running) {
|
||||
final approved = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (c) => AlertDialog(
|
||||
title: const Text('重连使配置生效'),
|
||||
content: const Text('当前会话和连接将关闭,再按草稿启动。'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(c, false),
|
||||
child: const Text('取消'),
|
||||
),
|
||||
FilledButton(
|
||||
onPressed: () => Navigator.pop(c, true),
|
||||
child: const Text('重连'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
if (approved != true) return;
|
||||
}
|
||||
log(
|
||||
'请求代理连接 · 入口=$runtimeMode · 功能=${proxyProfile.feature} · '
|
||||
'模式=${proxyProfile.mode} · 节点数=${proxyProfile.nodes.length} · '
|
||||
'已选择出口=${proxyProfile.nodes.any((n) => n.id == proxyProfile.selectedId)} · '
|
||||
'代理 DNS=已配置',
|
||||
);
|
||||
await diagnosticStage('校验代理配置', () async {
|
||||
if (runtimeMode != 'system_vpn') proxyProfile.validateConnection();
|
||||
});
|
||||
if (!mounted) return;
|
||||
await perform((c) async {
|
||||
if (runtimeMode == 'system_vpn' && proxyProfile.feature != 'mesh') {
|
||||
throw StateError('互联网代理需要选择统一 VPN 或应用内入口');
|
||||
}
|
||||
await proxySaveTail;
|
||||
proxyProfile.entry = runtimeMode;
|
||||
if (profileSupported) await saveProxyProfile();
|
||||
final nextConfig = buildFormConfig();
|
||||
if (proxyProfile.feature != 'proxy') {
|
||||
await applicationClient!.request({
|
||||
@@ -1285,7 +1436,9 @@ class _LabScreenState extends State<LabScreen> {
|
||||
});
|
||||
}
|
||||
if (running) await stopActive(c);
|
||||
singBoxEnabled = runtimeMode != 'system_vpn';
|
||||
singBoxEnabled =
|
||||
runtimeMode == 'unified_vpn' ||
|
||||
(runtimeMode == 'application' && proxyProfile.feature != 'mesh');
|
||||
await startConfig(buildFormConfig());
|
||||
runningProxyLabel =
|
||||
proxyProfile.nodes
|
||||
@@ -1302,17 +1455,27 @@ class _LabScreenState extends State<LabScreen> {
|
||||
|
||||
Widget proxyPage() => ProxyPanel(
|
||||
entry: runtimeMode,
|
||||
entryChanged: (v) => setState(() {
|
||||
runtimeMode = v;
|
||||
proxyProfile.entry = v;
|
||||
proxyDraftChanged = true;
|
||||
}),
|
||||
entryChanged: (v) {
|
||||
setState(() {
|
||||
runtimeMode = v;
|
||||
proxyProfile.entry = v;
|
||||
});
|
||||
proxyChanged();
|
||||
},
|
||||
profile: proxyProfile,
|
||||
busy: busy,
|
||||
running: running,
|
||||
save: saveProxyProfile,
|
||||
connect: connectProxy,
|
||||
changed: () => setState(() => proxyDraftChanged = true),
|
||||
connect: primaryConnection,
|
||||
changed: proxyChanged,
|
||||
draftChanged: proxyDraftChanged,
|
||||
saving: proxySavesPending > 0,
|
||||
saveFailed: proxySaveFailed,
|
||||
showLogs: () => openDetail(
|
||||
'运行日志',
|
||||
() =>
|
||||
LogsPageBody(logs: logs, onClear: () => setState(() => logs.clear())),
|
||||
),
|
||||
);
|
||||
Future<void> importConfig() async {
|
||||
final text = await showDialog<String>(
|
||||
@@ -1322,7 +1485,16 @@ class _LabScreenState extends State<LabScreen> {
|
||||
if (text != null && mounted) {
|
||||
await perform((c) async {
|
||||
await loadForm(text);
|
||||
proxyProfile.feature = 'mesh';
|
||||
proxyProfile.entry = runtimeMode;
|
||||
proxyProfile.proxyEnabled = false;
|
||||
singBoxEnabled = false;
|
||||
await startConfig(text);
|
||||
try {
|
||||
await saveProxyProfile();
|
||||
} catch (_) {
|
||||
log('组网已连接,但连接方式未能保存,请重试保存');
|
||||
}
|
||||
log('导入配置并启动引擎');
|
||||
});
|
||||
}
|
||||
@@ -1385,7 +1557,7 @@ class _LabScreenState extends State<LabScreen> {
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
if (wide)
|
||||
if (wide && proxyProfile.feature != 'proxy')
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(right: 20),
|
||||
child: ConstrainedBox(
|
||||
|
||||
@@ -11,8 +11,10 @@ class ProxyPanel extends StatefulWidget {
|
||||
final String entry;
|
||||
final void Function(String) entryChanged;
|
||||
final bool busy, running;
|
||||
final bool draftChanged, saving, saveFailed;
|
||||
final Future<void> Function() save, connect;
|
||||
final VoidCallback changed;
|
||||
final VoidCallback? showLogs;
|
||||
const ProxyPanel({
|
||||
super.key,
|
||||
required this.profile,
|
||||
@@ -23,6 +25,10 @@ class ProxyPanel extends StatefulWidget {
|
||||
required this.save,
|
||||
required this.connect,
|
||||
required this.changed,
|
||||
this.showLogs,
|
||||
this.draftChanged = false,
|
||||
this.saving = false,
|
||||
this.saveFailed = false,
|
||||
});
|
||||
@override
|
||||
State<ProxyPanel> createState() => _ProxyPanelState();
|
||||
@@ -33,13 +39,19 @@ class _ProxyPanelState extends State<ProxyPanel> {
|
||||
bool working = false;
|
||||
String error = '';
|
||||
void change(VoidCallback work) {
|
||||
setState(work);
|
||||
setState(() {
|
||||
work();
|
||||
error = '';
|
||||
});
|
||||
widget.changed();
|
||||
}
|
||||
|
||||
Future<void> act(Future<void> Function() work) async {
|
||||
if (working || widget.busy) return;
|
||||
setState(() => working = true);
|
||||
setState(() {
|
||||
working = true;
|
||||
error = '';
|
||||
});
|
||||
try {
|
||||
await work();
|
||||
} catch (e) {
|
||||
@@ -96,7 +108,7 @@ class _ProxyPanelState extends State<ProxyPanel> {
|
||||
);
|
||||
if (preview == null || !mounted) return;
|
||||
if (preview is ImportPreview) {
|
||||
change(() => p.nodes.addAll(preview.nodes));
|
||||
change(() => p.addNodes(preview.nodes));
|
||||
}
|
||||
if (preview is Map<String, dynamic>) {
|
||||
final sub = await Navigator.push<Map<String, dynamic>>(
|
||||
@@ -134,7 +146,7 @@ class _ProxyPanelState extends State<ProxyPanel> {
|
||||
options: node.options,
|
||||
);
|
||||
} else {
|
||||
p.nodes.add(node);
|
||||
p.addNodes([node]);
|
||||
}
|
||||
});
|
||||
return;
|
||||
@@ -146,7 +158,7 @@ class _ProxyPanelState extends State<ProxyPanel> {
|
||||
if (node == null || !mounted) return;
|
||||
change(
|
||||
() => existing == null || existing.source != 'manual'
|
||||
? p.nodes.add(node)
|
||||
? p.addNodes([node])
|
||||
: p.nodes[p.nodes.indexWhere((n) => n.id == existing.id)] = node,
|
||||
);
|
||||
}
|
||||
@@ -199,10 +211,7 @@ class _ProxyPanelState extends State<ProxyPanel> {
|
||||
return;
|
||||
}
|
||||
change(() {
|
||||
p.nodes.removeWhere((n) => n.source == source);
|
||||
p.nodes.addAll(replacement);
|
||||
if (removed) p.selectedId = null;
|
||||
sub['updated'] = DateTime.now().toIso8601String();
|
||||
replaceSubscription(p, source, preview, DateTime.now());
|
||||
});
|
||||
}
|
||||
|
||||
@@ -285,74 +294,95 @@ class _ProxyPanelState extends State<ProxyPanel> {
|
||||
error,
|
||||
style: TextStyle(color: Theme.of(context).colorScheme.error),
|
||||
),
|
||||
section('代理与组网', [
|
||||
DropdownButtonFormField<String>(
|
||||
isExpanded: true,
|
||||
initialValue: widget.entry,
|
||||
decoration: const InputDecoration(labelText: '网络入口'),
|
||||
items: const [
|
||||
DropdownMenuItem(value: 'application', child: Text('应用内 SOCKS5')),
|
||||
DropdownMenuItem(value: 'system_vpn', child: Text('独立系统组网')),
|
||||
DropdownMenuItem(
|
||||
value: 'unified_vpn',
|
||||
child: Text('统一 VPN · 单一 TUN'),
|
||||
),
|
||||
],
|
||||
onChanged: disabled ? null : (v) => widget.entryChanged(v!),
|
||||
),
|
||||
const Text(
|
||||
'修改的是草稿。保存不会更改运行出口;连接或重连后生效。应用内模式通过 SOCKS5 127.0.0.1:10818 接入。',
|
||||
),
|
||||
section('连接', [
|
||||
DropdownButtonFormField<String>(
|
||||
isExpanded: true,
|
||||
initialValue: p.feature,
|
||||
decoration: const InputDecoration(labelText: '启用功能'),
|
||||
decoration: const InputDecoration(labelText: '连接方式'),
|
||||
items: const [
|
||||
DropdownMenuItem(value: 'mesh', child: Text('仅组网')),
|
||||
DropdownMenuItem(value: 'proxy', child: Text('仅代理')),
|
||||
DropdownMenuItem(value: 'combined', child: Text('代理 + 组网')),
|
||||
],
|
||||
onChanged: disabled ? null : (v) => change(() => p.feature = v!),
|
||||
),
|
||||
DropdownButtonFormField<String>(
|
||||
isExpanded: true,
|
||||
initialValue: p.mode,
|
||||
decoration: const InputDecoration(labelText: '普通互联网流量模式'),
|
||||
items: const [
|
||||
DropdownMenuItem(value: 'bypass_cn', child: Text('绕过中国大陆')),
|
||||
DropdownMenuItem(value: 'rule', child: Text('自定义规则')),
|
||||
DropdownMenuItem(value: 'global', child: Text('全局代理')),
|
||||
DropdownMenuItem(value: 'direct', child: Text('直连')),
|
||||
],
|
||||
onChanged: disabled || p.feature == 'mesh'
|
||||
onChanged: disabled
|
||||
? null
|
||||
: (v) => change(() => p.mode = v!),
|
||||
: (v) => change(() {
|
||||
p.feature = v!;
|
||||
if (widget.entry == 'system_vpn' && v != 'mesh') {
|
||||
widget.entryChanged('unified_vpn');
|
||||
}
|
||||
}),
|
||||
),
|
||||
if (widget.entry == 'system_vpn' && p.feature != 'mesh')
|
||||
const Text('独立系统组网只支持仅组网;代理功能请选择统一 VPN 或应用内入口。'),
|
||||
Text(
|
||||
p.mode == 'bypass_cn' && p.feature != 'mesh'
|
||||
? '中国大陆 IP 和普通私网直连,其余走所选代理;组网始终优先。内置 IP 规则集通过代理每 24 小时更新,首次下载失败会阻止连接。'
|
||||
: '组网优先始终生效。全局/直连暂停普通规则;仅组网不接管互联网。',
|
||||
p.feature == 'mesh'
|
||||
? '填写组网配置后连接。'
|
||||
: p.mode == 'direct'
|
||||
? '直连模式无需代理节点。'
|
||||
: '导入节点后连接即可,已提供默认加密 DNS。',
|
||||
),
|
||||
if (p.feature != 'mesh')
|
||||
DropdownButtonFormField<String>(
|
||||
isExpanded: true,
|
||||
initialValue: p.mode,
|
||||
decoration: const InputDecoration(labelText: '上网模式'),
|
||||
items: const [
|
||||
DropdownMenuItem(value: 'bypass_cn', child: Text('绕过中国大陆')),
|
||||
DropdownMenuItem(value: 'rule', child: Text('自定义规则')),
|
||||
DropdownMenuItem(value: 'global', child: Text('全局代理')),
|
||||
DropdownMenuItem(value: 'direct', child: Text('直连')),
|
||||
],
|
||||
onChanged: disabled || p.feature == 'mesh'
|
||||
? null
|
||||
: (v) => change(() => p.mode = v!),
|
||||
),
|
||||
if (p.mode == 'bypass_cn' && p.feature != 'mesh')
|
||||
const Text('中国大陆 IP 和普通私网直连,其余通过代理。首次使用会下载分流规则。'),
|
||||
Text(
|
||||
widget.entry == 'application'
|
||||
? '应用内代理:需要在使用它的软件中设置 SOCKS5 127.0.0.1:10818。'
|
||||
: widget.entry == 'system_vpn'
|
||||
? '连接后接入组网地址。'
|
||||
: '连接后设备流量自动接入。',
|
||||
),
|
||||
Wrap(
|
||||
spacing: 8,
|
||||
runSpacing: 12,
|
||||
children: [
|
||||
FilledButton(
|
||||
onPressed:
|
||||
disabled ||
|
||||
(widget.entry == 'system_vpn' && p.feature != 'mesh')
|
||||
? null
|
||||
: () => act(widget.connect),
|
||||
child: Text(widget.running ? '重连使草稿生效' : '连接'),
|
||||
),
|
||||
OutlinedButton(
|
||||
onPressed: disabled ? null : () => act(widget.save),
|
||||
child: const Text('安全保存配置'),
|
||||
FilledButton.icon(
|
||||
onPressed: disabled ? null : () => act(widget.connect),
|
||||
icon: Icon(
|
||||
widget.running && !widget.draftChanged
|
||||
? Icons.stop
|
||||
: Icons.power_settings_new,
|
||||
),
|
||||
label: Text(
|
||||
widget.running
|
||||
? (widget.draftChanged ? '重连应用修改' : '断开连接')
|
||||
: '连接',
|
||||
),
|
||||
),
|
||||
if (widget.showLogs != null)
|
||||
OutlinedButton.icon(
|
||||
onPressed: widget.showLogs,
|
||||
icon: const Icon(Icons.monitor_heart_outlined),
|
||||
label: const Text('诊断与日志'),
|
||||
),
|
||||
if (widget.saveFailed)
|
||||
OutlinedButton(
|
||||
onPressed: disabled ? null : () => act(widget.save),
|
||||
child: const Text('重试保存'),
|
||||
),
|
||||
],
|
||||
),
|
||||
Text(
|
||||
widget.saveFailed
|
||||
? '配置未保存,请重试。'
|
||||
: widget.saving
|
||||
? '正在自动保存…'
|
||||
: widget.running && widget.draftChanged
|
||||
? '修改已保存,重连后生效。'
|
||||
: '配置修改后自动保存。',
|
||||
),
|
||||
]),
|
||||
section('代理节点', [
|
||||
Wrap(
|
||||
@@ -369,7 +399,7 @@ class _ProxyPanelState extends State<ProxyPanel> {
|
||||
),
|
||||
],
|
||||
),
|
||||
if (p.nodes.isEmpty) const Text('尚未添加节点。全局代理或使用代理出口的规则需要选中一个节点。'),
|
||||
if (p.nodes.isEmpty) const Text('导入第一个节点即可开始;多个节点时请选择一个出口。'),
|
||||
for (final node in p.nodes)
|
||||
ListTile(
|
||||
leading: IconButton(
|
||||
@@ -383,7 +413,11 @@ class _ProxyPanelState extends State<ProxyPanel> {
|
||||
? null
|
||||
: () => change(() => p.selectedId = node.id),
|
||||
),
|
||||
title: Text(node.name),
|
||||
title: Text(
|
||||
node.name,
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
onTap: () => Navigator.push<void>(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
@@ -434,53 +468,103 @@ class _ProxyPanelState extends State<ProxyPanel> {
|
||||
),
|
||||
),
|
||||
]),
|
||||
section('分流与 DNS', [
|
||||
const Text('受管理规则:有效组网地址 → 组网;已失效的已知组网地址 → 拒绝;随后才应用普通规则与默认出口。'),
|
||||
DropdownButtonFormField<String>(
|
||||
isExpanded: true,
|
||||
initialValue: p.defaultAction,
|
||||
decoration: const InputDecoration(labelText: '规则模式默认出口'),
|
||||
items: const [
|
||||
DropdownMenuItem(value: 'proxy', child: Text('所选代理')),
|
||||
DropdownMenuItem(value: 'direct', child: Text('直连')),
|
||||
DropdownMenuItem(value: 'reject', child: Text('拒绝')),
|
||||
Card(
|
||||
child: ExpansionTile(
|
||||
key: const PageStorageKey('proxy-advanced'),
|
||||
title: const Text('高级设置'),
|
||||
subtitle: const Text('网络入口、DNS 与分流规则'),
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(18),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
DropdownButtonFormField<String>(
|
||||
key: ValueKey('entry-${widget.entry}'),
|
||||
isExpanded: true,
|
||||
initialValue: widget.entry,
|
||||
decoration: const InputDecoration(labelText: '网络入口'),
|
||||
items: const [
|
||||
DropdownMenuItem(
|
||||
value: 'application',
|
||||
child: Text('应用内 SOCKS5'),
|
||||
),
|
||||
DropdownMenuItem(
|
||||
value: 'system_vpn',
|
||||
child: Text('独立系统组网'),
|
||||
),
|
||||
DropdownMenuItem(
|
||||
value: 'unified_vpn',
|
||||
child: Text('统一 VPN · 单一 TUN'),
|
||||
),
|
||||
],
|
||||
onChanged: disabled
|
||||
? null
|
||||
: (v) => widget.entryChanged(v!),
|
||||
),
|
||||
const SizedBox(height: 18),
|
||||
const Text('修改连接设置后,重连使其生效。'),
|
||||
const SizedBox(height: 18),
|
||||
const Text(
|
||||
'受管理规则:有效组网地址 → 组网;已失效的已知组网地址 → 拒绝;随后才应用普通规则与默认出口。',
|
||||
),
|
||||
DropdownButtonFormField<String>(
|
||||
isExpanded: true,
|
||||
initialValue: p.defaultAction,
|
||||
decoration: const InputDecoration(labelText: '规则模式默认出口'),
|
||||
items: const [
|
||||
DropdownMenuItem(value: 'proxy', child: Text('所选代理')),
|
||||
DropdownMenuItem(value: 'direct', child: Text('直连')),
|
||||
DropdownMenuItem(value: 'reject', child: Text('拒绝')),
|
||||
],
|
||||
onChanged:
|
||||
disabled || p.mode != 'rule' || p.feature == 'mesh'
|
||||
? null
|
||||
: (v) => change(() => p.defaultAction = v!),
|
||||
),
|
||||
Text(
|
||||
'${p.rules.length} 条普通规则 · ${p.mode == 'rule' && p.feature != 'mesh' ? '规则模式执行' : '已暂停'}',
|
||||
),
|
||||
OutlinedButton(
|
||||
onPressed: disabled
|
||||
? null
|
||||
: () => Navigator.push<void>(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (_) => RulesPage(
|
||||
profile: p,
|
||||
changed: widget.changed,
|
||||
),
|
||||
),
|
||||
),
|
||||
child: const Text('编辑普通规则'),
|
||||
),
|
||||
Text(
|
||||
'启动 DNS:${p.dnsServer} · 直连 DNS:${p.directDnsServer.isEmpty ? '启动 DNS' : p.directDnsServer} · 代理 DNS:${p.effectiveProxyDns}',
|
||||
),
|
||||
OutlinedButton(
|
||||
onPressed: disabled
|
||||
? null
|
||||
: () => Navigator.push<void>(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (_) => DnsPage(
|
||||
profile: p,
|
||||
changed: widget.changed,
|
||||
),
|
||||
),
|
||||
),
|
||||
child: const Text('编辑 DNS'),
|
||||
),
|
||||
Text(
|
||||
'FakeIP:${p.fakeIP ? '开启' : '关闭'} · 组网域名自动排除,解析失败无公共 DNS 回退。',
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
onChanged: disabled || p.mode != 'rule' || p.feature == 'mesh'
|
||||
? null
|
||||
: (v) => change(() => p.defaultAction = v!),
|
||||
),
|
||||
Text(
|
||||
'${p.rules.length} 条普通规则 · ${p.mode == 'rule' && p.feature != 'mesh' ? '规则模式执行' : '已暂停'}',
|
||||
),
|
||||
OutlinedButton(
|
||||
onPressed: disabled
|
||||
? null
|
||||
: () => Navigator.push<void>(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (_) =>
|
||||
RulesPage(profile: p, changed: widget.changed),
|
||||
),
|
||||
),
|
||||
child: const Text('编辑普通规则'),
|
||||
),
|
||||
Text(
|
||||
'启动 DNS:${p.dnsServer} · 直连 DNS:${p.directDnsServer.isEmpty ? '启动 DNS' : p.directDnsServer} · 代理 DNS:${p.proxyDnsServer.isEmpty ? '待配置 · 代理模式必填' : p.proxyDnsServer}',
|
||||
),
|
||||
OutlinedButton(
|
||||
onPressed: disabled
|
||||
? null
|
||||
: () => Navigator.push<void>(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (_) =>
|
||||
DnsPage(profile: p, changed: widget.changed),
|
||||
),
|
||||
),
|
||||
child: const Text('编辑 DNS'),
|
||||
),
|
||||
Text('FakeIP:${p.fakeIP ? '开启' : '关闭'} · 组网域名自动排除,解析失败无公共 DNS 回退。'),
|
||||
]),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
/// Keeps known credentials for the whole session, including replaced drafts.
|
||||
class DiagnosticRedactor {
|
||||
final _secrets = <String>{};
|
||||
|
||||
void remember(Object? value, {String? key}) {
|
||||
if (value is Map) {
|
||||
for (final entry in value.entries) {
|
||||
remember(entry.value, key: '${entry.key}');
|
||||
}
|
||||
} else if (value is Iterable) {
|
||||
for (final item in value) {
|
||||
remember(item, key: key);
|
||||
}
|
||||
} else if (value is String &&
|
||||
value.isNotEmpty &&
|
||||
{
|
||||
'password',
|
||||
'username',
|
||||
'uuid',
|
||||
'network_secret',
|
||||
'token',
|
||||
'private_key',
|
||||
}.contains(key)) {
|
||||
_secrets.add(value);
|
||||
}
|
||||
}
|
||||
|
||||
String sanitize(String text) {
|
||||
final secrets = _secrets.toList()
|
||||
..sort((a, b) => b.length.compareTo(a.length));
|
||||
for (final value in secrets) {
|
||||
text = text.replaceAll(value, '[已隐藏]');
|
||||
}
|
||||
text = text.replaceAllMapped(
|
||||
RegExp(r'([a-zA-Z][a-zA-Z0-9+.-]*://)[^\s/]+@'),
|
||||
(m) => '${m[1]}[已隐藏]@',
|
||||
);
|
||||
text = text.replaceAllMapped(
|
||||
RegExp(r'([a-zA-Z][a-zA-Z0-9+.-]*://[^\s?]+)\?[^\s]+'),
|
||||
(m) => '${m[1]}?[已隐藏]',
|
||||
);
|
||||
return text;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
platform :osx, '10.15'
|
||||
platform :osx, '12.0'
|
||||
|
||||
# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
|
||||
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
|
||||
@@ -38,5 +38,8 @@ end
|
||||
post_install do |installer|
|
||||
installer.pods_project.targets.each do |target|
|
||||
flutter_additional_macos_build_settings(target)
|
||||
target.build_configurations.each do |config|
|
||||
config.build_settings['MACOSX_DEPLOYMENT_TARGET'] = '12.0'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
PODS:
|
||||
- FlutterMacOS (1.0.0)
|
||||
|
||||
DEPENDENCIES:
|
||||
- FlutterMacOS (from `Flutter/ephemeral`)
|
||||
|
||||
EXTERNAL SOURCES:
|
||||
FlutterMacOS:
|
||||
:path: Flutter/ephemeral
|
||||
|
||||
SPEC CHECKSUMS:
|
||||
FlutterMacOS: d0db08ddef1a9af05a5ec4b724367152bb0500b1
|
||||
|
||||
PODFILE CHECKSUM: 13edfb9e70ac3646927b8e6c9a212ad1d0fa29b2
|
||||
|
||||
COCOAPODS: 1.16.2
|
||||
@@ -27,6 +27,8 @@
|
||||
33CC10F32044A3C60003C045 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 33CC10F22044A3C60003C045 /* Assets.xcassets */; };
|
||||
33CC10F62044A3C60003C045 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 33CC10F42044A3C60003C045 /* MainMenu.xib */; };
|
||||
33CC11132044BFA00003C045 /* MainFlutterWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33CC11122044BFA00003C045 /* MainFlutterWindow.swift */; };
|
||||
4AB602CD95E220C185C9978C /* Pods_RunnerTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BBFCA921103BE03628578208 /* Pods_RunnerTests.framework */; };
|
||||
B0B2671181DD147C22F9DA95 /* Pods_Runner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7A55BFDF956E46C7632C102B /* Pods_Runner.framework */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXContainerItemProxy section */
|
||||
@@ -60,11 +62,13 @@
|
||||
/* End PBXCopyFilesBuildPhase section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
092517D44FE622E53982B8F7 /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = "<group>"; };
|
||||
0C42A6D1E91FCC75A8FFACCD /* Pods-RunnerTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RunnerTests.release.xcconfig"; path = "Target Support Files/Pods-RunnerTests/Pods-RunnerTests.release.xcconfig"; sourceTree = "<group>"; };
|
||||
331C80D5294CF71000263BE5 /* RunnerTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = RunnerTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
331C80D7294CF71000263BE5 /* RunnerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RunnerTests.swift; sourceTree = "<group>"; };
|
||||
333000ED22D3DE5D00554162 /* Warnings.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Warnings.xcconfig; sourceTree = "<group>"; };
|
||||
335BBD1A22A9A15E00E9071D /* GeneratedPluginRegistrant.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GeneratedPluginRegistrant.swift; sourceTree = "<group>"; };
|
||||
33CC10ED2044A3C60003C045 /* meshport_lab.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "meshport_lab.app"; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
33CC10ED2044A3C60003C045 /* meshport_lab.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = meshport_lab.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
33CC10F02044A3C60003C045 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
|
||||
33CC10F22044A3C60003C045 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Assets.xcassets; path = Runner/Assets.xcassets; sourceTree = "<group>"; };
|
||||
33CC10F52044A3C60003C045 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/MainMenu.xib; sourceTree = "<group>"; };
|
||||
@@ -76,8 +80,14 @@
|
||||
33E51913231747F40026EE4D /* DebugProfile.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = DebugProfile.entitlements; sourceTree = "<group>"; };
|
||||
33E51914231749380026EE4D /* Release.entitlements */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.entitlements; path = Release.entitlements; sourceTree = "<group>"; };
|
||||
33E5194F232828860026EE4D /* AppInfo.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = AppInfo.xcconfig; sourceTree = "<group>"; };
|
||||
393D3BD1764A737A49EE8A67 /* 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 = "<group>"; };
|
||||
671D7CA622257FEE05245595 /* 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 = "<group>"; };
|
||||
7A18F7D923A92E299909B27F /* Pods-Runner.profile.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.profile.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig"; sourceTree = "<group>"; };
|
||||
7A55BFDF956E46C7632C102B /* Pods_Runner.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Runner.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Release.xcconfig; sourceTree = "<group>"; };
|
||||
927C0C870CC973445A7543D6 /* 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 = "<group>"; };
|
||||
9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = Debug.xcconfig; sourceTree = "<group>"; };
|
||||
BBFCA921103BE03628578208 /* Pods_RunnerTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_RunnerTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
@@ -85,6 +95,7 @@
|
||||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
4AB602CD95E220C185C9978C /* Pods_RunnerTests.framework in Frameworks */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
@@ -92,6 +103,7 @@
|
||||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
B0B2671181DD147C22F9DA95 /* Pods_Runner.framework in Frameworks */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
@@ -125,6 +137,7 @@
|
||||
331C80D6294CF71000263BE5 /* RunnerTests */,
|
||||
33CC10EE2044A3C60003C045 /* Products */,
|
||||
D73912EC22F37F3D000D13A0 /* Frameworks */,
|
||||
7A80F7A78DF7A6F1790E273C /* Pods */,
|
||||
);
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
@@ -172,9 +185,25 @@
|
||||
path = Runner;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
7A80F7A78DF7A6F1790E273C /* Pods */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
092517D44FE622E53982B8F7 /* Pods-Runner.debug.xcconfig */,
|
||||
927C0C870CC973445A7543D6 /* Pods-Runner.release.xcconfig */,
|
||||
7A18F7D923A92E299909B27F /* Pods-Runner.profile.xcconfig */,
|
||||
393D3BD1764A737A49EE8A67 /* Pods-RunnerTests.debug.xcconfig */,
|
||||
0C42A6D1E91FCC75A8FFACCD /* Pods-RunnerTests.release.xcconfig */,
|
||||
671D7CA622257FEE05245595 /* Pods-RunnerTests.profile.xcconfig */,
|
||||
);
|
||||
name = Pods;
|
||||
path = Pods;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
D73912EC22F37F3D000D13A0 /* Frameworks */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
7A55BFDF956E46C7632C102B /* Pods_Runner.framework */,
|
||||
BBFCA921103BE03628578208 /* Pods_RunnerTests.framework */,
|
||||
);
|
||||
name = Frameworks;
|
||||
sourceTree = "<group>";
|
||||
@@ -186,6 +215,7 @@
|
||||
isa = PBXNativeTarget;
|
||||
buildConfigurationList = 331C80DE294CF71000263BE5 /* Build configuration list for PBXNativeTarget "RunnerTests" */;
|
||||
buildPhases = (
|
||||
29CF92A05BAD308ACBBCF0A7 /* [CP] Check Pods Manifest.lock */,
|
||||
331C80D1294CF70F00263BE5 /* Sources */,
|
||||
331C80D2294CF70F00263BE5 /* Frameworks */,
|
||||
331C80D3294CF70F00263BE5 /* Resources */,
|
||||
@@ -204,6 +234,7 @@
|
||||
isa = PBXNativeTarget;
|
||||
buildConfigurationList = 33CC10FB2044A3C60003C045 /* Build configuration list for PBXNativeTarget "Runner" */;
|
||||
buildPhases = (
|
||||
49184CD3D43FEC521263B28B /* [CP] Check Pods Manifest.lock */,
|
||||
33CC10E92044A3C60003C045 /* Sources */,
|
||||
33CC10EA2044A3C60003C045 /* Frameworks */,
|
||||
33CC10EB2044A3C60003C045 /* Resources */,
|
||||
@@ -291,6 +322,28 @@
|
||||
/* End PBXResourcesBuildPhase section */
|
||||
|
||||
/* Begin PBXShellScriptBuildPhase section */
|
||||
29CF92A05BAD308ACBBCF0A7 /* [CP] Check Pods Manifest.lock */ = {
|
||||
isa = PBXShellScriptBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
);
|
||||
inputFileListPaths = (
|
||||
);
|
||||
inputPaths = (
|
||||
"${PODS_PODFILE_DIR_PATH}/Podfile.lock",
|
||||
"${PODS_ROOT}/Manifest.lock",
|
||||
);
|
||||
name = "[CP] Check Pods Manifest.lock";
|
||||
outputFileListPaths = (
|
||||
);
|
||||
outputPaths = (
|
||||
"$(DERIVED_FILE_DIR)/Pods-RunnerTests-checkManifestLockResult.txt",
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
shellPath = /bin/sh;
|
||||
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
|
||||
showEnvVarsInLog = 0;
|
||||
};
|
||||
3399D490228B24CF009A79C7 /* ShellScript */ = {
|
||||
isa = PBXShellScriptBuildPhase;
|
||||
alwaysOutOfDate = 1;
|
||||
@@ -329,6 +382,28 @@
|
||||
shellPath = /bin/sh;
|
||||
shellScript = "\"$FLUTTER_ROOT\"/packages/flutter_tools/bin/macos_assemble.sh && touch Flutter/ephemeral/tripwire";
|
||||
};
|
||||
49184CD3D43FEC521263B28B /* [CP] Check Pods Manifest.lock */ = {
|
||||
isa = PBXShellScriptBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
);
|
||||
inputFileListPaths = (
|
||||
);
|
||||
inputPaths = (
|
||||
"${PODS_PODFILE_DIR_PATH}/Podfile.lock",
|
||||
"${PODS_ROOT}/Manifest.lock",
|
||||
);
|
||||
name = "[CP] Check Pods Manifest.lock";
|
||||
outputFileListPaths = (
|
||||
);
|
||||
outputPaths = (
|
||||
"$(DERIVED_FILE_DIR)/Pods-Runner-checkManifestLockResult.txt",
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
shellPath = /bin/sh;
|
||||
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
|
||||
showEnvVarsInLog = 0;
|
||||
};
|
||||
/* End PBXShellScriptBuildPhase section */
|
||||
|
||||
/* Begin PBXSourcesBuildPhase section */
|
||||
@@ -380,6 +455,7 @@
|
||||
/* Begin XCBuildConfiguration section */
|
||||
331C80DB294CF71000263BE5 /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
baseConfigurationReference = 393D3BD1764A737A49EE8A67 /* Pods-RunnerTests.debug.xcconfig */;
|
||||
buildSettings = {
|
||||
BUNDLE_LOADER = "$(TEST_HOST)";
|
||||
CURRENT_PROJECT_VERSION = 1;
|
||||
@@ -394,6 +470,7 @@
|
||||
};
|
||||
331C80DC294CF71000263BE5 /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
baseConfigurationReference = 0C42A6D1E91FCC75A8FFACCD /* Pods-RunnerTests.release.xcconfig */;
|
||||
buildSettings = {
|
||||
BUNDLE_LOADER = "$(TEST_HOST)";
|
||||
CURRENT_PROJECT_VERSION = 1;
|
||||
@@ -408,6 +485,7 @@
|
||||
};
|
||||
331C80DD294CF71000263BE5 /* Profile */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
baseConfigurationReference = 671D7CA622257FEE05245595 /* Pods-RunnerTests.profile.xcconfig */;
|
||||
buildSettings = {
|
||||
BUNDLE_LOADER = "$(TEST_HOST)";
|
||||
CURRENT_PROJECT_VERSION = 1;
|
||||
@@ -461,7 +539,7 @@
|
||||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.15;
|
||||
MACOSX_DEPLOYMENT_TARGET = 12.0;
|
||||
MTL_ENABLE_DEBUG_INFO = NO;
|
||||
SDKROOT = macosx;
|
||||
SWIFT_COMPILATION_MODE = wholemodule;
|
||||
@@ -543,7 +621,7 @@
|
||||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.15;
|
||||
MACOSX_DEPLOYMENT_TARGET = 12.0;
|
||||
MTL_ENABLE_DEBUG_INFO = YES;
|
||||
ONLY_ACTIVE_ARCH = YES;
|
||||
SDKROOT = macosx;
|
||||
@@ -593,7 +671,7 @@
|
||||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.15;
|
||||
MACOSX_DEPLOYMENT_TARGET = 12.0;
|
||||
MTL_ENABLE_DEBUG_INFO = NO;
|
||||
SDKROOT = macosx;
|
||||
SWIFT_COMPILATION_MODE = wholemodule;
|
||||
|
||||
@@ -4,4 +4,7 @@
|
||||
<FileRef
|
||||
location = "group:Runner.xcodeproj">
|
||||
</FileRef>
|
||||
<FileRef
|
||||
location = "group:Pods/Pods.xcodeproj">
|
||||
</FileRef>
|
||||
</Workspace>
|
||||
|
||||
@@ -6,8 +6,10 @@ import UniformTypeIdentifiers
|
||||
import AVFoundation
|
||||
import Vision
|
||||
import ImageIO
|
||||
import OSLog
|
||||
|
||||
class MainFlutterWindow: NSWindow {
|
||||
private let runtimeLogger = Logger(subsystem: "com.example.meshportLab", category: "Runtime")
|
||||
private var vpnChannel: FlutterMethodChannel?
|
||||
private var qrScanner: MeshQRScanner?
|
||||
private var importing = false
|
||||
@@ -102,6 +104,14 @@ class MainFlutterWindow: NSWindow {
|
||||
return ["login_status":status,"auto_connect":UserDefaults.standard.bool(forKey:"MeshPort.autoConnect")]
|
||||
}
|
||||
private func handleCapabilities(_ call: FlutterMethodCall, result: @escaping FlutterResult) -> Bool {
|
||||
if call.method == "runtime_log" {
|
||||
guard let message = call.arguments as? String, message.utf8.count <= 8192 else {
|
||||
result(FlutterError(code: "BAD_LOG", message: "Invalid diagnostic event", details: nil)); return true
|
||||
}
|
||||
// Flutter sends only credential-redacted diagnostic events, never profiles.
|
||||
runtimeLogger.notice("\(message, privacy: .public)")
|
||||
result(nil); return true
|
||||
}
|
||||
if call.method == "startup_status" { result(startupStatus()); return true }
|
||||
if call.method == "set_startup" {
|
||||
guard let args = call.arguments as? [String:Any] else { result(FlutterError(code:"BAD_ARGUMENT",message:"Invalid preferences",details:nil));return true }
|
||||
|
||||
@@ -4,22 +4,42 @@ import 'package:meshport_client_core/meshport_client_core.dart';
|
||||
import 'package:meshport_lab/features/configuration_pages.dart';
|
||||
|
||||
void main() {
|
||||
test(
|
||||
'client protects DNS and requires explicit resolver before connecting',
|
||||
() {
|
||||
final p = ProxyProfile();
|
||||
expect(p.runtime()['dns_protection'], true);
|
||||
expect(p.validateConnection, throwsStateError);
|
||||
p.proxyDnsServer = 'tls://resolver.example';
|
||||
expect(p.validateConnection, returnsNormally);
|
||||
p.proxyDnsServer = '';
|
||||
p.mode = 'direct';
|
||||
expect(p.validateConnection, returnsNormally);
|
||||
p.mode = 'global';
|
||||
p.feature = 'mesh';
|
||||
expect(p.validateConnection, returnsNormally);
|
||||
},
|
||||
);
|
||||
test('client supplies encrypted default DNS and protects proxy queries', () {
|
||||
final p = ProxyProfile();
|
||||
expect(p.runtime()['dns_protection'], true);
|
||||
expect(p.validateConnection, throwsFormatException);
|
||||
p.nodes = importProxyNodes('socks://127.0.0.1:1080').nodes;
|
||||
p.selectedId = p.nodes.single.id;
|
||||
p.proxyDnsServer = 'tls://resolver.example';
|
||||
expect(p.validateConnection, returnsNormally);
|
||||
p.proxyDnsServer = '';
|
||||
expect(p.runtime()['proxy_dns_server'], ProxyProfile.defaultProxyDns);
|
||||
expect(p.validateConnection, returnsNormally);
|
||||
p.mode = 'direct';
|
||||
expect(p.validateConnection, returnsNormally);
|
||||
p.mode = 'global';
|
||||
p.feature = 'mesh';
|
||||
expect(p.validateConnection, returnsNormally);
|
||||
});
|
||||
|
||||
test('proxy requires a selected node, while direct and mesh do not', () {
|
||||
final p = ProxyProfile()..proxyDnsServer = 'tls://resolver.example';
|
||||
for (final mode in ['rule', 'global', 'bypass_cn']) {
|
||||
p.mode = mode;
|
||||
expect(p.validateConnection, throwsFormatException);
|
||||
}
|
||||
p.nodes = importProxyNodes('socks://127.0.0.1:1080').nodes;
|
||||
p.selectedId = 'deleted-node';
|
||||
expect(p.validateConnection, throwsFormatException);
|
||||
p.selectedId = p.nodes.single.id;
|
||||
expect(p.validateConnection, returnsNormally);
|
||||
p.nodes.clear();
|
||||
p.mode = 'direct';
|
||||
expect(p.validateConnection, returnsNormally);
|
||||
p.mode = 'global';
|
||||
p.feature = 'mesh';
|
||||
expect(p.validateConnection, returnsNormally);
|
||||
});
|
||||
|
||||
test('China bypass mode persists without rewriting custom rules', () {
|
||||
final p = ProxyProfile()
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meshport_lab/features/runtime_diagnostics.dart';
|
||||
|
||||
void main() {
|
||||
test('diagnostics redact nested credentials and retain replaced secrets', () {
|
||||
final redactor = DiagnosticRedactor();
|
||||
redactor.remember({
|
||||
'network_secret': 'mesh-secret',
|
||||
'nodes': [
|
||||
{
|
||||
'options': {
|
||||
'username': 'proxy-user',
|
||||
'password': 'proxy-password',
|
||||
'uuid': '00000000-0000-0000-0000-000000000001',
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
redactor.remember({'password': 'replacement-password'});
|
||||
final text = redactor.sanitize(
|
||||
'mesh-secret proxy-user proxy-password replacement-password '
|
||||
'00000000-0000-0000-0000-000000000001 '
|
||||
'socks://other-user:other-pass@proxy.example:1080 '
|
||||
'https://example.test/sub?token=subscription-secret',
|
||||
);
|
||||
for (final secret in [
|
||||
'mesh-secret',
|
||||
'proxy-user',
|
||||
'proxy-password',
|
||||
'replacement-password',
|
||||
'00000000-0000-0000-0000-000000000001',
|
||||
'other-user',
|
||||
'other-pass',
|
||||
'subscription-secret',
|
||||
]) {
|
||||
expect(text, isNot(contains(secret)));
|
||||
}
|
||||
expect(text, contains('proxy.example:1080'));
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meshport_client_core/meshport_client_core.dart';
|
||||
import 'package:meshport_lab/features/lab_screen.dart';
|
||||
|
||||
void main() {
|
||||
test('sharing links show decoded Unicode names', () {
|
||||
for (final fragment in ['演示节点', '%E6%BC%94%E7%A4%BA%E8%8A%82%E7%82%B9']) {
|
||||
expect(
|
||||
importProxyNodes('socks5://127.0.0.1:1080#$fragment').nodes.single.name,
|
||||
'演示节点',
|
||||
);
|
||||
}
|
||||
});
|
||||
test('blank and legacy DNS use default while custom resolver survives', () {
|
||||
final p = ProxyProfile();
|
||||
p.addNodes(importProxyNodes('socks://127.0.0.1:1080').nodes);
|
||||
p.proxyDnsServer = ' ';
|
||||
expect(p.runtime()['proxy_dns_server'], ProxyProfile.defaultProxyDns);
|
||||
expect(p.runtime()['dns_protection'], true);
|
||||
expect(p.validateConnection, returnsNormally);
|
||||
final legacy = p.toJson();
|
||||
(legacy['runtime'] as Map)['proxy_dns_server'] = '';
|
||||
expect(
|
||||
ProxyProfile.fromJson(legacy).proxyDnsServer,
|
||||
ProxyProfile.defaultProxyDns,
|
||||
);
|
||||
p.proxyDnsServer = 'tls://resolver.example';
|
||||
expect(ProxyProfile.fromJson(p.toJson()).proxyDnsServer, p.proxyDnsServer);
|
||||
});
|
||||
|
||||
test('only initial single node is selected automatically', () {
|
||||
final p = ProxyProfile();
|
||||
p.addNodes(importProxyNodes('socks://127.0.0.1:1080').nodes);
|
||||
final selected = p.selectedId;
|
||||
expect(selected, p.nodes.single.id);
|
||||
p.addNodes(importProxyNodes('socks://127.0.0.1:1081').nodes);
|
||||
expect(p.selectedId, selected);
|
||||
final multiple = ProxyProfile();
|
||||
multiple.addNodes(
|
||||
importProxyNodes('socks://127.0.0.1:1080\nsocks://127.0.0.1:1081').nodes,
|
||||
);
|
||||
expect(multiple.selectedId, isNull);
|
||||
final subscription = ProxyProfile();
|
||||
replaceSubscription(
|
||||
subscription,
|
||||
's',
|
||||
importProxyNodes('socks://127.0.0.1:1080', source: 's'),
|
||||
DateTime.now(),
|
||||
);
|
||||
expect(subscription.selectedId, subscription.nodes.single.id);
|
||||
replaceSubscription(
|
||||
subscription,
|
||||
's',
|
||||
importProxyNodes('socks://127.0.0.1:1081', source: 's'),
|
||||
DateTime.now(),
|
||||
);
|
||||
expect(subscription.selectedId, isNull);
|
||||
});
|
||||
|
||||
const channel = MethodChannel('meshport/system_vpn');
|
||||
final binding = TestWidgetsFlutterBinding.ensureInitialized();
|
||||
tearDown(
|
||||
() =>
|
||||
binding.defaultBinaryMessenger.setMockMethodCallHandler(channel, null),
|
||||
);
|
||||
|
||||
Future<void> openProxy(WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(home: LabScreen(initializeNative: false)),
|
||||
);
|
||||
await tester.tap(find.text('代理').last);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('仅代理'), findsOneWidget);
|
||||
expect(find.text('网络入口'), findsNothing);
|
||||
expect(find.text('编辑 DNS'), findsNothing);
|
||||
}
|
||||
|
||||
Future<void> chooseMode(WidgetTester tester, String mode) async {
|
||||
final field = find.byWidgetPredicate(
|
||||
(w) =>
|
||||
w is DropdownButtonFormField<String> &&
|
||||
w.decoration.labelText == '上网模式',
|
||||
);
|
||||
await tester.ensureVisible(field);
|
||||
await tester.tap(field);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text(mode).last);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
testWidgets(
|
||||
'automatic saves serialize rapid edits and keep latest value',
|
||||
(tester) async {
|
||||
final first = Completer<void>();
|
||||
final saves = <Map<String, dynamic>>[];
|
||||
binding.defaultBinaryMessenger.setMockMethodCallHandler(channel, (
|
||||
call,
|
||||
) async {
|
||||
if (call.method == 'save_proxy_profile') {
|
||||
saves.add(
|
||||
jsonDecode(call.arguments as String) as Map<String, dynamic>,
|
||||
);
|
||||
if (saves.length == 1) await first.future;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
await openProxy(tester);
|
||||
await chooseMode(tester, '直连');
|
||||
await chooseMode(tester, '全局代理');
|
||||
expect(saves.length, 1);
|
||||
first.complete();
|
||||
await tester.pumpAndSettle();
|
||||
expect(saves.length, 2);
|
||||
expect((saves.last['runtime'] as Map)['mode'], 'global');
|
||||
expect(find.text('正在自动保存…'), findsNothing);
|
||||
expect(find.text('重试保存'), findsNothing);
|
||||
},
|
||||
skip: !Platform.isMacOS,
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'failed automatic save offers retry and clears after success',
|
||||
(tester) async {
|
||||
var fail = true;
|
||||
binding.defaultBinaryMessenger.setMockMethodCallHandler(channel, (
|
||||
call,
|
||||
) async {
|
||||
if (call.method == 'save_proxy_profile' && fail) {
|
||||
throw PlatformException(code: 'KEYCHAIN_SAVE');
|
||||
}
|
||||
return null;
|
||||
});
|
||||
await openProxy(tester);
|
||||
await chooseMode(tester, '直连');
|
||||
expect(find.text('重试保存'), findsOneWidget);
|
||||
fail = false;
|
||||
await tester.ensureVisible(find.text('重试保存'));
|
||||
await tester.tap(find.text('重试保存'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('重试保存'), findsNothing);
|
||||
expect(tester.takeException(), isNull);
|
||||
},
|
||||
skip: !Platform.isMacOS,
|
||||
);
|
||||
}
|
||||
@@ -3,6 +3,36 @@ import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meshport_lab/features/lab_screen.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('connection explains missing node and clears stale errors', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(home: LabScreen(initializeNative: false)),
|
||||
);
|
||||
await tester.tap(find.text('代理').last);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.ensureVisible(find.text('连接').last);
|
||||
await tester.tap(find.text('连接').last);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.textContaining('请先添加代理节点'), findsOneWidget);
|
||||
|
||||
await tester.ensureVisible(find.text('诊断与日志'));
|
||||
await tester.tap(find.text('诊断与日志'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.textContaining('[校验代理配置] 失败'), findsOneWidget);
|
||||
expect(find.textContaining('入口=unified_vpn'), findsOneWidget);
|
||||
await tester.pageBack();
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await tester.ensureVisible(find.text('全局代理').last);
|
||||
await tester.tap(find.text('全局代理').last);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('直连').last);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.textContaining('请先添加代理节点'), findsNothing);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('China bypass can be selected and switched to global', (
|
||||
tester,
|
||||
) async {
|
||||
@@ -14,7 +44,7 @@ void main() {
|
||||
final mode = find.byWidgetPredicate(
|
||||
(w) =>
|
||||
w is DropdownButtonFormField<String> &&
|
||||
w.decoration.labelText == '普通互联网流量模式',
|
||||
w.decoration.labelText == '上网模式',
|
||||
);
|
||||
await tester.ensureVisible(mode);
|
||||
await tester.tap(mode);
|
||||
@@ -52,7 +82,7 @@ void main() {
|
||||
);
|
||||
await tester.tap(find.text('代理').last);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('普通互联网流量模式'), findsOneWidget);
|
||||
expect(find.text('上网模式'), findsOneWidget);
|
||||
await tester.ensureVisible(find.text('导入与预览'));
|
||||
await tester.tap(find.text('导入与预览'));
|
||||
await tester.pumpAndSettle();
|
||||
@@ -67,6 +97,13 @@ void main() {
|
||||
await tester.tap(find.text('确认导入'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Preview'), findsOneWidget);
|
||||
expect(find.text('安全保存配置'), findsOneWidget);
|
||||
expect(find.byIcon(Icons.radio_button_checked), findsOneWidget);
|
||||
expect(find.text('网络入口'), findsNothing);
|
||||
expect(find.text('编辑 DNS'), findsNothing);
|
||||
await tester.ensureVisible(find.text('高级设置'));
|
||||
await tester.tap(find.text('高级设置'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('网络入口'), findsOneWidget);
|
||||
expect(find.text('编辑 DNS'), findsOneWidget);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
import 'package:integration_test/integration_test_driver.dart';
|
||||
|
||||
Future<void> main() => integrationDriver(timeout: const Duration(minutes: 15));
|
||||
Reference in New Issue
Block a user