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:
@@ -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 回退。'),
|
||||
]),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user