发布网络质量探测 1.1.2:新增客户端源文件(二)
署名:言灸
This commit is contained in:
1 parent
bc39956b6c
commit
6dcc2c4b89
4 files changed
+297
No files matched your search
@@ -0,0 +1,32 @@
|
||||
// Copyright (C) 2026 言灸
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import 'probe_profile.dart';
|
||||
|
||||
/// Keeps a port the user typed. An empty field or a value that is still the
|
||||
/// previous profile's default follows the newly selected profile.
|
||||
String portAfterProfileChange({
|
||||
required String current,
|
||||
required int previousDefault,
|
||||
required int nextDefault,
|
||||
}) {
|
||||
final trimmed = current.trim();
|
||||
if (trimmed.isEmpty || int.tryParse(trimmed) == previousDefault) {
|
||||
return '$nextDefault';
|
||||
}
|
||||
return current;
|
||||
}
|
||||
|
||||
String portHint(ProbeProfile profile) {
|
||||
switch (profile.id) {
|
||||
case 'nq-tcp':
|
||||
return '合作反射 TCP 默认 19090';
|
||||
case 'nq-udp':
|
||||
return '合作反射 UDP 默认 19091';
|
||||
default:
|
||||
return '${profile.label} 默认 ${profile.port}';
|
||||
}
|
||||
}
|
||||
|
||||
const portHelperText =
|
||||
'合作反射 TCP 默认 19090,UDP 默认 19091。只有当前端口仍是上一种类型的默认值或为空时,切换类型才会自动更换。';
|
||||
@@ -0,0 +1,125 @@
|
||||
// Copyright (C) 2026 言灸
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import 'dart:io';
|
||||
|
||||
class ResolvedAddress {
|
||||
const ResolvedAddress({required this.address, required this.family});
|
||||
|
||||
final String address;
|
||||
final String family;
|
||||
}
|
||||
|
||||
String addressFamily(InternetAddress address) {
|
||||
return address.type == InternetAddressType.IPv6 ? 'IPv6' : 'IPv4';
|
||||
}
|
||||
|
||||
String familyOfAddress(String address) {
|
||||
final parsed = InternetAddress.tryParse(address);
|
||||
if (parsed == null) {
|
||||
return '';
|
||||
}
|
||||
return addressFamily(parsed);
|
||||
}
|
||||
|
||||
class AddressLines {
|
||||
const AddressLines({
|
||||
this.used,
|
||||
this.trying,
|
||||
this.resolved,
|
||||
this.fallback,
|
||||
this.unreported,
|
||||
this.fake = false,
|
||||
});
|
||||
|
||||
final String? used;
|
||||
final String? trying;
|
||||
final String? resolved;
|
||||
final String? fallback;
|
||||
final String? unreported;
|
||||
final bool fake;
|
||||
}
|
||||
|
||||
/// [used] is an address a probe actually connected to or sent to.
|
||||
/// [resolved] is only the lookup result and is never labeled as the address
|
||||
/// in use. A remote sample that omits the address stays unreported.
|
||||
AddressLines describeAddress({
|
||||
required List<ResolvedAddress> resolved,
|
||||
String? usedAddress,
|
||||
String? usedFamily,
|
||||
String? tryingAddress,
|
||||
String? tryingFamily,
|
||||
String fallbackText = '',
|
||||
bool addressUnreported = false,
|
||||
bool usedIsFake = false,
|
||||
}) {
|
||||
final hasUsed = usedAddress != null && usedAddress.isNotEmpty;
|
||||
String? used;
|
||||
if (hasUsed) {
|
||||
final family = (usedFamily == null || usedFamily.isEmpty)
|
||||
? familyOfAddress(usedAddress)
|
||||
: usedFamily;
|
||||
used = family.isEmpty ? '实际地址 $usedAddress' : '实际地址 $usedAddress($family)';
|
||||
}
|
||||
String? trying;
|
||||
if (!hasUsed && tryingAddress != null && tryingAddress.isNotEmpty) {
|
||||
final family = (tryingFamily == null || tryingFamily.isEmpty)
|
||||
? ''
|
||||
: '($tryingFamily)';
|
||||
trying = '正在尝试 $tryingAddress$family,还没有正式结果';
|
||||
}
|
||||
String? resolvedLine;
|
||||
if (resolved.isNotEmpty) {
|
||||
final sameSingle =
|
||||
resolved.length == 1 &&
|
||||
hasUsed &&
|
||||
resolved.single.address == usedAddress;
|
||||
if (!sameSingle) {
|
||||
final text = resolved
|
||||
.map((item) {
|
||||
final family = item.family.isEmpty ? '' : '(${item.family})';
|
||||
return '${item.address}$family';
|
||||
})
|
||||
.join('、');
|
||||
resolvedLine = '解析到 $text';
|
||||
}
|
||||
}
|
||||
return AddressLines(
|
||||
used: used,
|
||||
trying: trying,
|
||||
resolved: resolvedLine,
|
||||
fallback: fallbackText.isEmpty ? null : fallbackText,
|
||||
unreported: addressUnreported && !hasUsed ? '节点没有报告实际使用的地址' : null,
|
||||
fake: usedIsFake && hasUsed,
|
||||
);
|
||||
}
|
||||
|
||||
List<ResolvedAddress> readResolvedList(Object? parsed) {
|
||||
if (parsed is! Map) {
|
||||
return const [];
|
||||
}
|
||||
final raw = parsed['resolved'];
|
||||
if (raw is! List) {
|
||||
return const [];
|
||||
}
|
||||
final out = <ResolvedAddress>[];
|
||||
for (final item in raw) {
|
||||
if (item is! Map) {
|
||||
continue;
|
||||
}
|
||||
final address = item['address'];
|
||||
if (address is! String || address.isEmpty) {
|
||||
continue;
|
||||
}
|
||||
final family = item['family'];
|
||||
out.add(
|
||||
ResolvedAddress(
|
||||
address: address,
|
||||
family: family is String && family.isNotEmpty
|
||||
? family
|
||||
: familyOfAddress(address),
|
||||
),
|
||||
);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
// Copyright (C) 2026 言灸
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
const chartPinEpsilon = 0.0001;
|
||||
|
||||
class ChartSelection {
|
||||
const ChartSelection({required this.sec, required this.sessionId});
|
||||
|
||||
final double sec;
|
||||
final int sessionId;
|
||||
}
|
||||
|
||||
/// A tap chooses the nearest sample and keeps it after the pointer is
|
||||
/// released. A new session, an empty series, or a point that has scrolled
|
||||
/// off the front of the window clears the pin instead of jumping to another
|
||||
/// sample. [tappedSec] null means "keep the current pin if it is still valid".
|
||||
ChartSelection? nextChartSelection({
|
||||
required ChartSelection? current,
|
||||
required int sessionId,
|
||||
required List<double> sampleSecs,
|
||||
double? tappedSec,
|
||||
}) {
|
||||
if (tappedSec != null) {
|
||||
double? nearest;
|
||||
var best = double.infinity;
|
||||
for (final sec in sampleSecs) {
|
||||
final distance = (sec - tappedSec).abs();
|
||||
if (distance < best) {
|
||||
best = distance;
|
||||
nearest = sec;
|
||||
}
|
||||
}
|
||||
if (nearest == null) {
|
||||
return null;
|
||||
}
|
||||
return ChartSelection(sec: nearest, sessionId: sessionId);
|
||||
}
|
||||
if (current == null || current.sessionId != sessionId || sampleSecs.isEmpty) {
|
||||
return null;
|
||||
}
|
||||
if (current.sec + chartPinEpsilon < sampleSecs.first) {
|
||||
return null;
|
||||
}
|
||||
for (final sec in sampleSecs) {
|
||||
if ((sec - current.sec).abs() <= chartPinEpsilon) {
|
||||
return current;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
// Copyright (C) 2026 言灸
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../content/release_history.dart';
|
||||
import '../version.dart';
|
||||
import 'quality_charts.dart';
|
||||
|
||||
class HistoryPage extends StatelessWidget {
|
||||
const HistoryPage({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final wide = MediaQuery.sizeOf(context).width >= 720;
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('更新历史'),
|
||||
backgroundColor: const Color(0xFFF3F1EC),
|
||||
),
|
||||
body: SafeArea(
|
||||
child: Align(
|
||||
alignment: Alignment.topCenter,
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxWidth: 760),
|
||||
child: ListView(
|
||||
padding: EdgeInsets.fromLTRB(
|
||||
wide ? 24 : 12,
|
||||
8,
|
||||
wide ? 24 : 12,
|
||||
28,
|
||||
),
|
||||
children: [
|
||||
Text(
|
||||
'当前版本 $appVersion(构建 $appBuild) · 署名 $appAttribution · $appLicense',
|
||||
style: const TextStyle(
|
||||
color: ink,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
const Text(
|
||||
releaseHistoryNote,
|
||||
style: TextStyle(color: muted, height: 1.4),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
for (final entry in releaseHistory) _entry(entry),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _entry(ReleaseEntry entry) {
|
||||
return Card(
|
||||
margin: const EdgeInsets.only(bottom: 12),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
side: const BorderSide(color: line),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(14),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Text(
|
||||
entry.title,
|
||||
style: const TextStyle(fontWeight: FontWeight.w700, color: ink),
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
Text(
|
||||
entry.published == null
|
||||
? entry.source
|
||||
: '${entry.published} · ${entry.source}',
|
||||
style: const TextStyle(color: muted, fontSize: 13, height: 1.4),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
for (final point in entry.points)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: 6),
|
||||
child: Text('· $point', style: const TextStyle(height: 1.4)),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user