发布网络质量探测 1.1.2:更新客户端界面与版本文件
署名:言灸
This commit is contained in:
1 parent
3a6356f4d9
commit
c1a60eef43
4 files changed
+415
-67
No files matched your search
@@ -4,6 +4,7 @@ import 'dart:io';
|
|||||||
|
|
||||||
import '../metrics/sample_book.dart';
|
import '../metrics/sample_book.dart';
|
||||||
import '../models/session_config.dart';
|
import '../models/session_config.dart';
|
||||||
|
import '../ui/address_text.dart';
|
||||||
|
|
||||||
class RemoteProbe {
|
class RemoteProbe {
|
||||||
HttpClient? _client;
|
HttpClient? _client;
|
||||||
@@ -16,6 +17,7 @@ class RemoteProbe {
|
|||||||
required ProbeBody body,
|
required ProbeBody body,
|
||||||
required void Function(ProbeSample sample) onSample,
|
required void Function(ProbeSample sample) onSample,
|
||||||
required bool Function() cancelled,
|
required bool Function() cancelled,
|
||||||
|
void Function(List<ResolvedAddress> resolved)? onResolved,
|
||||||
}) async {
|
}) async {
|
||||||
final normalized = normalizeNodeUrl(baseUrl);
|
final normalized = normalizeNodeUrl(baseUrl);
|
||||||
if (normalized == null) {
|
if (normalized == null) {
|
||||||
@@ -52,6 +54,7 @@ class RemoteProbe {
|
|||||||
throw RemoteException('节点返回的任务无效');
|
throw RemoteException('节点返回的任务无效');
|
||||||
}
|
}
|
||||||
_jobId = parsed['jobId'] as String;
|
_jobId = parsed['jobId'] as String;
|
||||||
|
onResolved?.call(readResolvedList(parsed));
|
||||||
if (cancelled()) {
|
if (cancelled()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -86,7 +89,13 @@ class RemoteProbe {
|
|||||||
_jobId = null;
|
_jobId = null;
|
||||||
if (client != null && id != null && base != null) {
|
if (client != null && id != null && base != null) {
|
||||||
try {
|
try {
|
||||||
await _send(client, 'DELETE', base.resolve('/v1/jobs/$id'), nodeToken, const []);
|
await _send(
|
||||||
|
client,
|
||||||
|
'DELETE',
|
||||||
|
base.resolve('/v1/jobs/$id'),
|
||||||
|
nodeToken,
|
||||||
|
const [],
|
||||||
|
);
|
||||||
} on Object {
|
} on Object {
|
||||||
// The stream ending already asks the node to drop the job.
|
// The stream ending already asks the node to drop the job.
|
||||||
}
|
}
|
||||||
@@ -101,7 +110,9 @@ class RemoteProbe {
|
|||||||
void Function(ProbeSample sample) onSample,
|
void Function(ProbeSample sample) onSample,
|
||||||
bool Function() cancelled,
|
bool Function() cancelled,
|
||||||
) async {
|
) async {
|
||||||
final request = await client.getUrl(_base!.resolve('/v1/jobs/$_jobId/stream'));
|
final request = await client.getUrl(
|
||||||
|
_base!.resolve('/v1/jobs/$_jobId/stream'),
|
||||||
|
);
|
||||||
request.followRedirects = false;
|
request.followRedirects = false;
|
||||||
_auth(request, nodeToken);
|
_auth(request, nodeToken);
|
||||||
final response = await request.close().timeout(const Duration(seconds: 20));
|
final response = await request.close().timeout(const Duration(seconds: 20));
|
||||||
@@ -194,7 +205,9 @@ Future<NodeInfo> fetchNodeInfo(String baseUrl) async {
|
|||||||
}
|
}
|
||||||
final client = HttpClient();
|
final client = HttpClient();
|
||||||
try {
|
try {
|
||||||
final request = await client.getUrl(Uri.parse(normalized).resolve('/v1/info'));
|
final request = await client.getUrl(
|
||||||
|
Uri.parse(normalized).resolve('/v1/info'),
|
||||||
|
);
|
||||||
request.followRedirects = false;
|
request.followRedirects = false;
|
||||||
final response = await request.close().timeout(const Duration(seconds: 8));
|
final response = await request.close().timeout(const Duration(seconds: 8));
|
||||||
final body = await response.transform(utf8.decoder).join();
|
final body = await response.transform(utf8.decoder).join();
|
||||||
@@ -206,7 +219,9 @@ Future<NodeInfo> fetchNodeInfo(String baseUrl) async {
|
|||||||
throw RemoteException('节点信息无效');
|
throw RemoteException('节点信息无效');
|
||||||
}
|
}
|
||||||
return NodeInfo(
|
return NodeInfo(
|
||||||
visibility: json['visibility'] is String ? json['visibility'] as String : '',
|
visibility: json['visibility'] is String
|
||||||
|
? json['visibility'] as String
|
||||||
|
: '',
|
||||||
authRequired: json['authRequired'] == true,
|
authRequired: json['authRequired'] == true,
|
||||||
);
|
);
|
||||||
} on RemoteException {
|
} on RemoteException {
|
||||||
|
|||||||
+269
-46
@@ -2,6 +2,8 @@ import 'dart:async';
|
|||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
import '../models/node_edit.dart';
|
||||||
|
import '../models/port_field.dart';
|
||||||
import '../models/probe_profile.dart';
|
import '../models/probe_profile.dart';
|
||||||
import '../models/session_config.dart';
|
import '../models/session_config.dart';
|
||||||
import '../probe/endpoint_picker.dart';
|
import '../probe/endpoint_picker.dart';
|
||||||
@@ -9,7 +11,11 @@ import '../probe/probe_controller.dart';
|
|||||||
import '../probe/remote_client.dart';
|
import '../probe/remote_client.dart';
|
||||||
import '../storage/app_store.dart';
|
import '../storage/app_store.dart';
|
||||||
import '../storage/token_vault.dart';
|
import '../storage/token_vault.dart';
|
||||||
|
import 'address_text.dart';
|
||||||
import 'format.dart';
|
import 'format.dart';
|
||||||
|
import 'history_page.dart';
|
||||||
|
import 'metric_guide_page.dart';
|
||||||
|
import 'metrics_panel.dart';
|
||||||
import 'quality_charts.dart';
|
import 'quality_charts.dart';
|
||||||
|
|
||||||
class HomePage extends StatefulWidget {
|
class HomePage extends StatefulWidget {
|
||||||
@@ -134,7 +140,11 @@ class _HomePageState extends State<HomePage> {
|
|||||||
final nodeToken = config.node == null
|
final nodeToken = config.node == null
|
||||||
? ''
|
? ''
|
||||||
: (await _vault.read(nodeTokenKey(config.node!.id)) ?? '');
|
: (await _vault.read(nodeTokenKey(config.node!.id)) ?? '');
|
||||||
await _controller.start(config, nodeToken: nodeToken, echoToken: _echo.text);
|
await _controller.start(
|
||||||
|
config,
|
||||||
|
nodeToken: nodeToken,
|
||||||
|
echoToken: _echo.text,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _changeProfile(String? id) {
|
void _changeProfile(String? id) {
|
||||||
@@ -144,9 +154,11 @@ class _HomePageState extends State<HomePage> {
|
|||||||
final previous = ProbeProfile.byId(_profileId);
|
final previous = ProbeProfile.byId(_profileId);
|
||||||
final next = ProbeProfile.byId(id);
|
final next = ProbeProfile.byId(id);
|
||||||
setState(() {
|
setState(() {
|
||||||
if (_port.text.trim() == '${previous.port}') {
|
_port.text = portAfterProfileChange(
|
||||||
_port.text = '${next.port}';
|
current: _port.text,
|
||||||
}
|
previousDefault: previous.port,
|
||||||
|
nextDefault: next.port,
|
||||||
|
);
|
||||||
_profileId = id;
|
_profileId = id;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -160,6 +172,22 @@ class _HomePageState extends State<HomePage> {
|
|||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: const Text('网络质量探测'),
|
title: const Text('网络质量探测'),
|
||||||
backgroundColor: const Color(0xFFF3F1EC),
|
backgroundColor: const Color(0xFFF3F1EC),
|
||||||
|
actions: [
|
||||||
|
PopupMenuButton<String>(
|
||||||
|
tooltip: '说明',
|
||||||
|
onSelected: (value) {
|
||||||
|
final page = value == 'history'
|
||||||
|
? const HistoryPage()
|
||||||
|
: const MetricGuidePage();
|
||||||
|
Navigator.of(context)
|
||||||
|
.push(MaterialPageRoute<void>(builder: (_) => page));
|
||||||
|
},
|
||||||
|
itemBuilder: (context) => const [
|
||||||
|
PopupMenuItem(value: 'metrics', child: Text('指标说明')),
|
||||||
|
PopupMenuItem(value: 'history', child: Text('更新历史')),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
body: SafeArea(
|
body: SafeArea(
|
||||||
child: Align(
|
child: Align(
|
||||||
@@ -167,12 +195,14 @@ class _HomePageState extends State<HomePage> {
|
|||||||
child: ConstrainedBox(
|
child: ConstrainedBox(
|
||||||
constraints: const BoxConstraints(maxWidth: 880),
|
constraints: const BoxConstraints(maxWidth: 880),
|
||||||
child: ListView(
|
child: ListView(
|
||||||
padding: EdgeInsets.fromLTRB(wide ? 24 : 12, 8, wide ? 24 : 12, 28),
|
padding: EdgeInsets.fromLTRB(
|
||||||
children: [
|
wide ? 24 : 12,
|
||||||
_card(
|
8,
|
||||||
title: '探测来源',
|
wide ? 24 : 12,
|
||||||
child: _source(view, wide),
|
28,
|
||||||
),
|
),
|
||||||
|
children: [
|
||||||
|
_card(title: '探测来源', child: _source(view, wide)),
|
||||||
_card(
|
_card(
|
||||||
title: '目标',
|
title: '目标',
|
||||||
child: Column(
|
child: Column(
|
||||||
@@ -181,7 +211,13 @@ class _HomePageState extends State<HomePage> {
|
|||||||
_pair(
|
_pair(
|
||||||
wide,
|
wide,
|
||||||
_field(_host, '目标地址', '域名或 IP'),
|
_field(_host, '目标地址', '域名或 IP'),
|
||||||
_field(_port, '端口', '1–65535'),
|
_field(
|
||||||
|
_port,
|
||||||
|
'端口',
|
||||||
|
portHint(profile),
|
||||||
|
fieldKey: const Key('port-field'),
|
||||||
|
helper: portHelperText,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 12),
|
const SizedBox(height: 12),
|
||||||
DropdownButtonFormField<String>(
|
DropdownButtonFormField<String>(
|
||||||
@@ -190,12 +226,18 @@ class _HomePageState extends State<HomePage> {
|
|||||||
decoration: const InputDecoration(labelText: '探测类型'),
|
decoration: const InputDecoration(labelText: '探测类型'),
|
||||||
items: [
|
items: [
|
||||||
for (final item in ProbeProfile.all)
|
for (final item in ProbeProfile.all)
|
||||||
DropdownMenuItem(value: item.id, child: Text(item.label)),
|
DropdownMenuItem(
|
||||||
|
value: item.id,
|
||||||
|
child: Text(item.label),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
onChanged: view.running ? null : _changeProfile,
|
onChanged: view.running ? null : _changeProfile,
|
||||||
),
|
),
|
||||||
const SizedBox(height: 8),
|
const SizedBox(height: 8),
|
||||||
Text(profile.blurb, style: const TextStyle(color: muted, fontSize: 13)),
|
Text(
|
||||||
|
profile.blurb,
|
||||||
|
style: const TextStyle(color: muted, fontSize: 13),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -206,7 +248,11 @@ class _HomePageState extends State<HomePage> {
|
|||||||
children: [
|
children: [
|
||||||
_pair(
|
_pair(
|
||||||
wide,
|
wide,
|
||||||
_field(_interval, '间隔(毫秒)', _remote ? '至少 200' : '至少 100'),
|
_field(
|
||||||
|
_interval,
|
||||||
|
'间隔(毫秒)',
|
||||||
|
_remote ? '至少 200' : '至少 100',
|
||||||
|
),
|
||||||
_field(_timeout, '超时(毫秒)', '100–15000'),
|
_field(_timeout, '超时(毫秒)', '100–15000'),
|
||||||
),
|
),
|
||||||
if (profile.needsPacketSize) ...[
|
if (profile.needsPacketSize) ...[
|
||||||
@@ -252,11 +298,44 @@ class _HomePageState extends State<HomePage> {
|
|||||||
_banner(view.banner!),
|
_banner(view.banner!),
|
||||||
],
|
],
|
||||||
const SizedBox(height: 12),
|
const SizedBox(height: 12),
|
||||||
_card(title: '结果', child: _result(view)),
|
_card(
|
||||||
|
title: '结果',
|
||||||
|
child: _result(
|
||||||
|
view,
|
||||||
|
view.profileId.isEmpty ? profile.id : view.profileId,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
if (view.report != null)
|
||||||
|
SessionSummaryCard(
|
||||||
|
report: view.report!,
|
||||||
|
profileId: view.report!.profileId,
|
||||||
|
),
|
||||||
QualityCharts(
|
QualityCharts(
|
||||||
samples: view.samples,
|
samples: view.samples,
|
||||||
rateLabel: view.rateLabel,
|
rateLabel: view.rateLabel,
|
||||||
running: view.running,
|
running: view.running,
|
||||||
|
sessionId: view.sessionId,
|
||||||
|
),
|
||||||
|
Wrap(
|
||||||
|
spacing: 8,
|
||||||
|
children: [
|
||||||
|
TextButton(
|
||||||
|
onPressed: () => Navigator.of(context).push(
|
||||||
|
MaterialPageRoute<void>(
|
||||||
|
builder: (_) => const MetricGuidePage(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
child: const Text('指标说明'),
|
||||||
|
),
|
||||||
|
TextButton(
|
||||||
|
onPressed: () => Navigator.of(context).push(
|
||||||
|
MaterialPageRoute<void>(
|
||||||
|
builder: (_) => const HistoryPage(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
child: const Text('更新历史'),
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
const Text(
|
const Text(
|
||||||
'延迟用发包一侧的单调时钟计算。远程探测时,这个时间在节点上量好再传回来,不包含手机到节点的控制通道耗时。TCP 超时不是物理丢包。没有协议应答的 UDP 记为无应答/未知,不会在探测完成前显示 100%。',
|
'延迟用发包一侧的单调时钟计算。远程探测时,这个时间在节点上量好再传回来,不包含手机到节点的控制通道耗时。TCP 超时不是物理丢包。没有协议应答的 UDP 记为无应答/未知,不会在探测完成前显示 100%。',
|
||||||
@@ -271,17 +350,25 @@ class _HomePageState extends State<HomePage> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Widget _source(ProbeView view, bool wide) {
|
Widget _source(ProbeView view, bool wide) {
|
||||||
final selected = _nodes.cast<RemoteNode?>().followedBy(const [null]).firstWhere(
|
final selected = _nodes
|
||||||
(node) => node?.id == _nodeId,
|
.cast<RemoteNode?>()
|
||||||
orElse: () => null,
|
.followedBy(const [null])
|
||||||
);
|
.firstWhere((node) => node?.id == _nodeId, orElse: () => null);
|
||||||
return Column(
|
return Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
children: [
|
children: [
|
||||||
SegmentedButton<bool>(
|
SegmentedButton<bool>(
|
||||||
segments: const [
|
segments: const [
|
||||||
ButtonSegment(value: false, label: Text('本机'), icon: Icon(Icons.phone_android)),
|
ButtonSegment(
|
||||||
ButtonSegment(value: true, label: Text('远程节点'), icon: Icon(Icons.dns_outlined)),
|
value: false,
|
||||||
|
label: Text('本机'),
|
||||||
|
icon: Icon(Icons.phone_android),
|
||||||
|
),
|
||||||
|
ButtonSegment(
|
||||||
|
value: true,
|
||||||
|
label: Text('远程节点'),
|
||||||
|
icon: Icon(Icons.dns_outlined),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
selected: {_remote},
|
selected: {_remote},
|
||||||
onSelectionChanged: view.running
|
onSelectionChanged: view.running
|
||||||
@@ -290,9 +377,7 @@ class _HomePageState extends State<HomePage> {
|
|||||||
),
|
),
|
||||||
const SizedBox(height: 8),
|
const SizedBox(height: 8),
|
||||||
Text(
|
Text(
|
||||||
_remote
|
_remote ? '由选中的节点向目标发包,这台设备只负责控制和显示。' : '由这台设备直接向目标发包。可以探测本机上的反射器。',
|
||||||
? '由选中的节点向目标发包,这台设备只负责控制和显示。'
|
|
||||||
: '由这台设备直接向目标发包。可以探测本机上的反射器。',
|
|
||||||
style: const TextStyle(color: muted, fontSize: 13),
|
style: const TextStyle(color: muted, fontSize: 13),
|
||||||
),
|
),
|
||||||
if (_remote) ...[
|
if (_remote) ...[
|
||||||
@@ -338,13 +423,18 @@ class _HomePageState extends State<HomePage> {
|
|||||||
return '${node.name} · $vis';
|
return '${node.name} · $vis';
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _result(ProbeView view) {
|
Widget _result(ProbeView view, String profileId) {
|
||||||
final summary = view.summary;
|
final summary = view.summary;
|
||||||
final rate = view.rateLabel == '探测无应答'
|
final address = describeAddress(
|
||||||
? summary.probeLossPct
|
resolved: view.resolved,
|
||||||
: view.rateLabel == '失败率'
|
usedAddress: view.usedAddress,
|
||||||
? summary.failurePct
|
usedFamily: view.usedFamily,
|
||||||
: summary.unknownPct;
|
tryingAddress: view.tryingAddress,
|
||||||
|
tryingFamily: view.tryingFamily,
|
||||||
|
fallbackText: view.fallbackText,
|
||||||
|
addressUnreported: view.addressUnreported,
|
||||||
|
usedIsFake: view.usedIsFake,
|
||||||
|
);
|
||||||
final motd = view.detail['motd'];
|
final motd = view.detail['motd'];
|
||||||
final version = view.detail['version'];
|
final version = view.detail['version'];
|
||||||
final players = view.detail['players'];
|
final players = view.detail['players'];
|
||||||
@@ -357,13 +447,42 @@ class _HomePageState extends State<HomePage> {
|
|||||||
children: [
|
children: [
|
||||||
_chip(view.phase),
|
_chip(view.phase),
|
||||||
_chip('来源 ${view.sourceLabel}'),
|
_chip('来源 ${view.sourceLabel}'),
|
||||||
if (view.targetAddress != null) _chip('发往 ${view.targetAddress}'),
|
if (view.targetHost.isNotEmpty) _chip(view.targetHost),
|
||||||
_chip('延迟 ${formatMs(summary.rttMs)}'),
|
|
||||||
_chip('抖动 ${formatMs(summary.jitterMs)}'),
|
|
||||||
_chip('${view.rateLabel} ${formatPct(rate)}'),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
if (view.targetIsFake) ...[
|
const SizedBox(height: 8),
|
||||||
|
MetricsPanel(
|
||||||
|
summary: summary,
|
||||||
|
profileId: profileId,
|
||||||
|
elapsed: view.elapsed,
|
||||||
|
),
|
||||||
|
if (address.trying != null) ...[
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
Text(address.trying!, style: const TextStyle(color: ink)),
|
||||||
|
],
|
||||||
|
if (address.used != null) ...[
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
Text(address.used!, style: const TextStyle(color: ink)),
|
||||||
|
],
|
||||||
|
if (address.resolved != null) ...[
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
Text(
|
||||||
|
address.resolved!,
|
||||||
|
style: const TextStyle(color: muted, fontSize: 13),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
if (address.unreported != null) ...[
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
Text(
|
||||||
|
address.unreported!,
|
||||||
|
style: const TextStyle(color: Color(0xFF9A3412)),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
if (address.fallback != null) ...[
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
Text(address.fallback!, style: const TextStyle(color: ink)),
|
||||||
|
],
|
||||||
|
if (address.fake) ...[
|
||||||
const SizedBox(height: 8),
|
const SizedBox(height: 8),
|
||||||
const Text(
|
const Text(
|
||||||
clashFakeIpNote,
|
clashFakeIpNote,
|
||||||
@@ -386,7 +505,10 @@ class _HomePageState extends State<HomePage> {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
const SizedBox(height: 8),
|
const SizedBox(height: 8),
|
||||||
Text(summaryLine(summary), style: const TextStyle(color: muted, fontSize: 13)),
|
Text(
|
||||||
|
summaryLine(summary),
|
||||||
|
style: const TextStyle(color: muted, fontSize: 13),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -434,6 +556,7 @@ class _NodeDialogState extends State<_NodeDialog> {
|
|||||||
final _name = TextEditingController();
|
final _name = TextEditingController();
|
||||||
final _url = TextEditingController();
|
final _url = TextEditingController();
|
||||||
final _token = TextEditingController();
|
final _token = TextEditingController();
|
||||||
|
String? _editingId;
|
||||||
String? _hint;
|
String? _hint;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -450,6 +573,41 @@ class _NodeDialogState extends State<_NodeDialog> {
|
|||||||
setState(() => _hint = '请填写名称,以及不带口令的 http 或 https 地址');
|
setState(() => _hint = '请填写名称,以及不带口令的 http 或 https 地址');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
final editing = _editingId;
|
||||||
|
if (editing != null) {
|
||||||
|
RemoteNode? previous;
|
||||||
|
for (final node in _nodes) {
|
||||||
|
if (node.id == editing) {
|
||||||
|
previous = node;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (previous == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final next = applyNodeEdit(
|
||||||
|
previous,
|
||||||
|
name: _name.text.trim(),
|
||||||
|
baseUrl: url,
|
||||||
|
);
|
||||||
|
final replaced = await saveEditedNodeToken(
|
||||||
|
widget.vault,
|
||||||
|
editing,
|
||||||
|
_token.text,
|
||||||
|
);
|
||||||
|
setState(() {
|
||||||
|
_nodes = [
|
||||||
|
for (final node in _nodes)
|
||||||
|
if (node.id == editing) next else node,
|
||||||
|
];
|
||||||
|
_editingId = null;
|
||||||
|
_hint = replaced ? '已更新,口令已替换,仍只留在本机。' : '已更新。口令留空,原来的口令未改。';
|
||||||
|
_name.clear();
|
||||||
|
_url.clear();
|
||||||
|
_token.clear();
|
||||||
|
});
|
||||||
|
widget.onChanged(_nodes, editing);
|
||||||
|
return;
|
||||||
|
}
|
||||||
final id = DateTime.now().microsecondsSinceEpoch.toString();
|
final id = DateTime.now().microsecondsSinceEpoch.toString();
|
||||||
final node = RemoteNode(id: id, name: _name.text.trim(), baseUrl: url);
|
final node = RemoteNode(id: id, name: _name.text.trim(), baseUrl: url);
|
||||||
await widget.vault.write(nodeTokenKey(id), _token.text.trim());
|
await widget.vault.write(nodeTokenKey(id), _token.text.trim());
|
||||||
@@ -463,6 +621,26 @@ class _NodeDialogState extends State<_NodeDialog> {
|
|||||||
widget.onChanged(_nodes, id);
|
widget.onChanged(_nodes, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _beginEdit(RemoteNode node) {
|
||||||
|
setState(() {
|
||||||
|
_editingId = node.id;
|
||||||
|
_name.text = node.name;
|
||||||
|
_url.text = node.baseUrl;
|
||||||
|
_token.clear();
|
||||||
|
_hint = '正在修改「${node.name}」。口令留空则保留已保存的口令,不会显示原口令。';
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void _cancelEdit() {
|
||||||
|
setState(() {
|
||||||
|
_editingId = null;
|
||||||
|
_name.clear();
|
||||||
|
_url.clear();
|
||||||
|
_token.clear();
|
||||||
|
_hint = null;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> _check(RemoteNode node) async {
|
Future<void> _check(RemoteNode node) async {
|
||||||
try {
|
try {
|
||||||
final info = await fetchNodeInfo(node.baseUrl);
|
final info = await fetchNodeInfo(node.baseUrl);
|
||||||
@@ -487,7 +665,10 @@ class _NodeDialogState extends State<_NodeDialog> {
|
|||||||
|
|
||||||
Future<void> _delete(RemoteNode node) async {
|
Future<void> _delete(RemoteNode node) async {
|
||||||
await widget.vault.delete(nodeTokenKey(node.id));
|
await widget.vault.delete(nodeTokenKey(node.id));
|
||||||
final next = [for (final item in _nodes) if (item.id != node.id) item];
|
final next = [
|
||||||
|
for (final item in _nodes)
|
||||||
|
if (item.id != node.id) item,
|
||||||
|
];
|
||||||
setState(() => _nodes = next);
|
setState(() => _nodes = next);
|
||||||
widget.onChanged(next, null);
|
widget.onChanged(next, null);
|
||||||
}
|
}
|
||||||
@@ -510,22 +691,41 @@ class _NodeDialogState extends State<_NodeDialog> {
|
|||||||
for (final node in _nodes)
|
for (final node in _nodes)
|
||||||
ListTile(
|
ListTile(
|
||||||
contentPadding: EdgeInsets.zero,
|
contentPadding: EdgeInsets.zero,
|
||||||
title: Text(_nodes.isEmpty ? '' : '${node.name} · ${visibilityLabel(node.visibility)}'),
|
title: Text(
|
||||||
subtitle: Text(node.baseUrl, maxLines: 1, overflow: TextOverflow.ellipsis),
|
'${node.name} · ${visibilityLabel(node.visibility)}',
|
||||||
|
),
|
||||||
|
subtitle: Text(
|
||||||
|
node.baseUrl,
|
||||||
|
maxLines: 1,
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
),
|
||||||
trailing: Wrap(
|
trailing: Wrap(
|
||||||
spacing: 4,
|
spacing: 4,
|
||||||
children: [
|
children: [
|
||||||
TextButton(onPressed: () => _check(node), child: const Text('检查')),
|
TextButton(
|
||||||
TextButton(onPressed: () => _delete(node), child: const Text('删除')),
|
key: Key('edit-node-${node.id}'),
|
||||||
|
onPressed: () => _beginEdit(node),
|
||||||
|
child: const Text('编辑'),
|
||||||
|
),
|
||||||
|
TextButton(
|
||||||
|
onPressed: () => _check(node),
|
||||||
|
child: const Text('检查'),
|
||||||
|
),
|
||||||
|
TextButton(
|
||||||
|
onPressed: () => _delete(node),
|
||||||
|
child: const Text('删除'),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
TextField(
|
TextField(
|
||||||
|
key: const Key('node-name'),
|
||||||
controller: _name,
|
controller: _name,
|
||||||
decoration: const InputDecoration(labelText: '名称'),
|
decoration: const InputDecoration(labelText: '名称'),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 8),
|
const SizedBox(height: 8),
|
||||||
TextField(
|
TextField(
|
||||||
|
key: const Key('node-url'),
|
||||||
controller: _url,
|
controller: _url,
|
||||||
decoration: const InputDecoration(
|
decoration: const InputDecoration(
|
||||||
labelText: '节点地址',
|
labelText: '节点地址',
|
||||||
@@ -534,10 +734,14 @@ class _NodeDialogState extends State<_NodeDialog> {
|
|||||||
),
|
),
|
||||||
const SizedBox(height: 8),
|
const SizedBox(height: 8),
|
||||||
TextField(
|
TextField(
|
||||||
|
key: const Key('node-token'),
|
||||||
controller: _token,
|
controller: _token,
|
||||||
obscureText: true,
|
obscureText: true,
|
||||||
decoration: const InputDecoration(
|
decoration: InputDecoration(
|
||||||
labelText: '节点口令(公开节点留空)',
|
labelText: _editingId == null ? '节点口令(公开节点留空)' : '新口令(留空则保留)',
|
||||||
|
helperText: _editingId == null
|
||||||
|
? null
|
||||||
|
: '留空则保留已保存的口令,不会显示原口令。',
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
if (_hint != null) ...[
|
if (_hint != null) ...[
|
||||||
@@ -549,8 +753,17 @@ class _NodeDialogState extends State<_NodeDialog> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
actions: [
|
actions: [
|
||||||
TextButton(onPressed: _save, child: const Text('添加节点')),
|
if (_editingId != null)
|
||||||
TextButton(onPressed: () => Navigator.pop(context), child: const Text('完成')),
|
TextButton(onPressed: _cancelEdit, child: const Text('取消编辑')),
|
||||||
|
TextButton(
|
||||||
|
key: const Key('node-save'),
|
||||||
|
onPressed: _save,
|
||||||
|
child: Text(_editingId == null ? '添加节点' : '保存修改'),
|
||||||
|
),
|
||||||
|
TextButton(
|
||||||
|
onPressed: () => Navigator.pop(context),
|
||||||
|
child: const Text('完成'),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -568,7 +781,10 @@ Widget _card({required String title, required Widget child}) {
|
|||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
children: [
|
children: [
|
||||||
Text(title, style: const TextStyle(fontWeight: FontWeight.w700, color: ink)),
|
Text(
|
||||||
|
title,
|
||||||
|
style: const TextStyle(fontWeight: FontWeight.w700, color: ink),
|
||||||
|
),
|
||||||
const SizedBox(height: 10),
|
const SizedBox(height: 10),
|
||||||
child,
|
child,
|
||||||
],
|
],
|
||||||
@@ -582,11 +798,18 @@ Widget _field(
|
|||||||
String label,
|
String label,
|
||||||
String hint, {
|
String hint, {
|
||||||
bool secret = false,
|
bool secret = false,
|
||||||
|
Key? fieldKey,
|
||||||
|
String? helper,
|
||||||
}) {
|
}) {
|
||||||
return TextField(
|
return TextField(
|
||||||
|
key: fieldKey,
|
||||||
controller: controller,
|
controller: controller,
|
||||||
obscureText: secret,
|
obscureText: secret,
|
||||||
decoration: InputDecoration(labelText: label, hintText: hint),
|
decoration: InputDecoration(
|
||||||
|
labelText: label,
|
||||||
|
hintText: hint,
|
||||||
|
helperText: helper,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ import 'package:fl_chart/fl_chart.dart';
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import '../probe/probe_controller.dart';
|
import '../probe/probe_controller.dart';
|
||||||
|
import 'chart_selection.dart';
|
||||||
|
import 'format.dart';
|
||||||
|
|
||||||
const rttColor = Color(0xFF1F4E79);
|
const rttColor = Color(0xFF1F4E79);
|
||||||
const rateColor = Color(0xFF9A3412);
|
const rateColor = Color(0xFF9A3412);
|
||||||
@@ -9,20 +11,67 @@ const ink = Color(0xFF1C2430);
|
|||||||
const muted = Color(0xFF5E6872);
|
const muted = Color(0xFF5E6872);
|
||||||
const line = Color(0xFFE4DFD4);
|
const line = Color(0xFFE4DFD4);
|
||||||
|
|
||||||
class QualityCharts extends StatelessWidget {
|
class QualityCharts extends StatefulWidget {
|
||||||
const QualityCharts({
|
const QualityCharts({
|
||||||
super.key,
|
super.key,
|
||||||
required this.samples,
|
required this.samples,
|
||||||
required this.rateLabel,
|
required this.rateLabel,
|
||||||
required this.running,
|
required this.running,
|
||||||
|
required this.sessionId,
|
||||||
});
|
});
|
||||||
|
|
||||||
final List<ChartSample> samples;
|
final List<ChartSample> samples;
|
||||||
final String rateLabel;
|
final String rateLabel;
|
||||||
final bool running;
|
final bool running;
|
||||||
|
final int sessionId;
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<QualityCharts> createState() => _QualityChartsState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _QualityChartsState extends State<QualityCharts> {
|
||||||
|
ChartSelection? _pin;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void didUpdateWidget(QualityCharts oldWidget) {
|
||||||
|
super.didUpdateWidget(oldWidget);
|
||||||
|
final kept = nextChartSelection(
|
||||||
|
current: _pin,
|
||||||
|
sessionId: widget.sessionId,
|
||||||
|
sampleSecs: [for (final sample in widget.samples) sample.sec],
|
||||||
|
);
|
||||||
|
if (kept?.sec != _pin?.sec || kept?.sessionId != _pin?.sessionId) {
|
||||||
|
_pin = kept;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _pinAt(double sec) {
|
||||||
|
setState(() {
|
||||||
|
_pin = nextChartSelection(
|
||||||
|
current: _pin,
|
||||||
|
sessionId: widget.sessionId,
|
||||||
|
sampleSecs: [for (final sample in widget.samples) sample.sec],
|
||||||
|
tappedSec: sec,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
ChartSample? get _pinnedSample {
|
||||||
|
final pin = _pin;
|
||||||
|
if (pin == null || pin.sessionId != widget.sessionId) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
for (final sample in widget.samples) {
|
||||||
|
if ((sample.sec - pin.sec).abs() <= chartPinEpsilon) {
|
||||||
|
return sample;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
final pinned = _pinnedSample;
|
||||||
return Column(
|
return Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
children: [
|
children: [
|
||||||
@@ -34,29 +83,51 @@ class QualityCharts extends StatelessWidget {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
const SizedBox(height: 8),
|
const SizedBox(height: 8),
|
||||||
|
Text(
|
||||||
|
pinned == null
|
||||||
|
? '点曲线上的一点可以钉住该时刻,松手后仍会保留。再点另一点会更换。'
|
||||||
|
: pinnedReadout(pinned, widget.rateLabel),
|
||||||
|
key: const Key('chart-pin'),
|
||||||
|
style: const TextStyle(color: ink, fontSize: 13, height: 1.4),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 8),
|
||||||
_ChartCard(
|
_ChartCard(
|
||||||
title: '延迟',
|
title: '延迟',
|
||||||
unit: 'ms',
|
unit: 'ms',
|
||||||
samples: samples,
|
samples: widget.samples,
|
||||||
read: (sample) => sample.rttMs,
|
read: (sample) => sample.rttMs,
|
||||||
color: rttColor,
|
color: rttColor,
|
||||||
floor: 1,
|
floor: 1,
|
||||||
running: running,
|
running: widget.running,
|
||||||
|
pinnedSec: pinned?.sec,
|
||||||
|
onPin: _pinAt,
|
||||||
),
|
),
|
||||||
_ChartCard(
|
_ChartCard(
|
||||||
title: rateLabel,
|
title: widget.rateLabel,
|
||||||
unit: '%',
|
unit: '%',
|
||||||
samples: samples,
|
samples: widget.samples,
|
||||||
read: (sample) => sample.ratePct,
|
read: (sample) => sample.ratePct,
|
||||||
color: rateColor,
|
color: rateColor,
|
||||||
floor: 10,
|
floor: 10,
|
||||||
running: running,
|
running: widget.running,
|
||||||
|
pinnedSec: pinned?.sec,
|
||||||
|
onPin: _pinAt,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String pinnedReadout(ChartSample sample, String rateLabel) {
|
||||||
|
final latency = sample.rttMs == null
|
||||||
|
? '这一刻没有延迟'
|
||||||
|
: '延迟 ${formatMs(sample.rttMs)}';
|
||||||
|
final rate = sample.ratePct == null
|
||||||
|
? '$rateLabel —'
|
||||||
|
: '$rateLabel ${formatPct(sample.ratePct)}';
|
||||||
|
return '已选 ${sample.sec.toStringAsFixed(1)} 秒 · $latency · $rate';
|
||||||
|
}
|
||||||
|
|
||||||
class _Swatch extends StatelessWidget {
|
class _Swatch extends StatelessWidget {
|
||||||
const _Swatch({required this.color, required this.label});
|
const _Swatch({required this.color, required this.label});
|
||||||
|
|
||||||
@@ -92,6 +163,8 @@ class _ChartCard extends StatelessWidget {
|
|||||||
required this.color,
|
required this.color,
|
||||||
required this.floor,
|
required this.floor,
|
||||||
required this.running,
|
required this.running,
|
||||||
|
required this.pinnedSec,
|
||||||
|
required this.onPin,
|
||||||
});
|
});
|
||||||
|
|
||||||
final String title;
|
final String title;
|
||||||
@@ -101,6 +174,8 @@ class _ChartCard extends StatelessWidget {
|
|||||||
final Color color;
|
final Color color;
|
||||||
final double floor;
|
final double floor;
|
||||||
final bool running;
|
final bool running;
|
||||||
|
final double? pinnedSec;
|
||||||
|
final void Function(double sec) onPin;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@@ -132,9 +207,7 @@ class _ChartCard extends StatelessWidget {
|
|||||||
? _lineChart(spots)
|
? _lineChart(spots)
|
||||||
: Center(
|
: Center(
|
||||||
child: Text(
|
child: Text(
|
||||||
running
|
running ? '正在等待第一次完成的探测。未完成的不会画成 100%。' : '暂无已完成的探测',
|
||||||
? '正在等待第一次完成的探测。未完成的不会画成 100%。'
|
|
||||||
: '暂无已完成的探测',
|
|
||||||
style: const TextStyle(color: muted),
|
style: const TextStyle(color: muted),
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
),
|
),
|
||||||
@@ -190,7 +263,8 @@ class _ChartCard extends StatelessWidget {
|
|||||||
show: true,
|
show: true,
|
||||||
drawVerticalLine: false,
|
drawVerticalLine: false,
|
||||||
horizontalInterval: yInterval,
|
horizontalInterval: yInterval,
|
||||||
getDrawingHorizontalLine: (_) => const FlLine(color: line, strokeWidth: 1),
|
getDrawingHorizontalLine: (_) =>
|
||||||
|
const FlLine(color: line, strokeWidth: 1),
|
||||||
),
|
),
|
||||||
borderData: FlBorderData(
|
borderData: FlBorderData(
|
||||||
show: true,
|
show: true,
|
||||||
@@ -200,14 +274,19 @@ class _ChartCard extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
titlesData: FlTitlesData(
|
titlesData: FlTitlesData(
|
||||||
topTitles: const AxisTitles(sideTitles: SideTitles(showTitles: false)),
|
topTitles: const AxisTitles(
|
||||||
rightTitles: const AxisTitles(sideTitles: SideTitles(showTitles: false)),
|
sideTitles: SideTitles(showTitles: false),
|
||||||
|
),
|
||||||
|
rightTitles: const AxisTitles(
|
||||||
|
sideTitles: SideTitles(showTitles: false),
|
||||||
|
),
|
||||||
leftTitles: AxisTitles(
|
leftTitles: AxisTitles(
|
||||||
sideTitles: SideTitles(
|
sideTitles: SideTitles(
|
||||||
showTitles: true,
|
showTitles: true,
|
||||||
reservedSize: 40,
|
reservedSize: 40,
|
||||||
interval: yInterval,
|
interval: yInterval,
|
||||||
getTitlesWidget: (value, meta) => _axisLabel(_formatTick(value, maxY)),
|
getTitlesWidget: (value, meta) =>
|
||||||
|
_axisLabel(_formatTick(value, maxY)),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
bottomTitles: AxisTitles(
|
bottomTitles: AxisTitles(
|
||||||
@@ -220,15 +299,46 @@ class _ChartCard extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
lineTouchData: const LineTouchData(handleBuiltInTouches: true),
|
extraLinesData: ExtraLinesData(
|
||||||
|
verticalLines: [
|
||||||
|
if (pinnedSec != null)
|
||||||
|
VerticalLine(
|
||||||
|
x: pinnedSec!,
|
||||||
|
color: color.withValues(alpha: 0.85),
|
||||||
|
strokeWidth: 1.5,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
lineTouchData: LineTouchData(
|
||||||
|
handleBuiltInTouches: false,
|
||||||
|
touchSpotThreshold: 18,
|
||||||
|
touchCallback: (event, response) {
|
||||||
|
if (event is! FlTapUpEvent) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final spots = response?.lineBarSpots;
|
||||||
|
if (spots == null || spots.isEmpty) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
onPin(spots.first.x);
|
||||||
|
},
|
||||||
|
),
|
||||||
lineBarsData: [
|
lineBarsData: [
|
||||||
LineChartBarData(
|
LineChartBarData(
|
||||||
spots: spots,
|
spots: spots,
|
||||||
isCurved: false,
|
isCurved: false,
|
||||||
color: color,
|
color: color,
|
||||||
barWidth: 2,
|
barWidth: 2,
|
||||||
dotData: const FlDotData(show: false),
|
dotData: FlDotData(
|
||||||
belowBarData: BarAreaData(show: true, color: color.withValues(alpha: 0.10)),
|
show: pinnedSec != null,
|
||||||
|
checkToShowDot: (spot, _) =>
|
||||||
|
pinnedSec != null &&
|
||||||
|
(spot.x - pinnedSec!).abs() <= chartPinEpsilon,
|
||||||
|
),
|
||||||
|
belowBarData: BarAreaData(
|
||||||
|
show: true,
|
||||||
|
color: color.withValues(alpha: 0.10),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# 网络质量探测 · Linux 桌面客户端
|
# 网络质量探测 · Linux 桌面客户端
|
||||||
|
|
||||||
这是 1.1.1 的 Linux 64 位桌面程序,解压后可以直接运行。不需要再安装 Flutter。
|
这是 1.1.2 的 Linux 64 位桌面程序,解压后可以直接运行。不需要再安装 Flutter。
|
||||||
|
|
||||||
## 先安装系统库
|
## 先安装系统库
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user