Skip to content

Commit

Permalink
增加流量统计、支持ws
Browse files Browse the repository at this point in the history
  • Loading branch information
vnt-dev committed Jul 7, 2024
1 parent 194f298 commit dcc7e5b
Show file tree
Hide file tree
Showing 25 changed files with 1,827 additions and 278 deletions.
2 changes: 1 addition & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ android {
ndk {
abiFilters "armeabi-v7a", "arm64-v8a", "x86", "x86_64"
}
versionName "1.2.10"
versionName "1.2.11"
}

buildTypes {
Expand Down
Binary file modified android/app/src/main/jniLibs/arm64-v8a/librust_lib_vnt_app.so
Binary file not shown.
Binary file modified android/app/src/main/jniLibs/armeabi-v7a/librust_lib_vnt_app.so
Binary file not shown.
Binary file modified android/app/src/main/jniLibs/x86/librust_lib_vnt_app.so
Binary file not shown.
Binary file modified android/app/src/main/jniLibs/x86_64/librust_lib_vnt_app.so
Binary file not shown.
2 changes: 1 addition & 1 deletion lib/about_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class AboutPage extends StatelessWidget {
),
const SizedBox(height: 20),
const Text(
'版本号: 1.2.10-测试版',
'版本号: 1.2.11-预发布版',
style: TextStyle(fontSize: 16),
textAlign: TextAlign.center,
),
Expand Down
76 changes: 53 additions & 23 deletions lib/connected_page.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import 'dart:async';
import 'dart:io';

import 'package:flutter/material.dart';
import 'connect_log.dart';
import 'network_config.dart';
Expand All @@ -6,6 +9,7 @@ import 'src/rust/api/vnt_api.dart';
import 'package:json2yaml/json2yaml.dart';

import 'vnt/vnt_manager.dart';
import 'widgets/dual_bar_chart.dart';

class ConnectDetailPage extends StatefulWidget {
final NetworkConfig config;
Expand All @@ -19,34 +23,50 @@ class ConnectDetailPage extends StatefulWidget {
}

class _ConnectDetailPageState extends State<ConnectDetailPage> {
final GlobalKey<StatisticsChartState> _keyChart =
GlobalKey<StatisticsChartState>();

int _selectedIndex = 0;
List<Map<String, String>> deviceList = [];
List<Map<String, String>> routeList = [];

Timer? _timer;
@override
void initState() {
super.initState();
_loadData();
_loadData(false);
_timer = Timer.periodic(const Duration(seconds: 5), (Timer timer) {
_loadData(true);
});
}

@override
void dispose() {
_timer?.cancel(); // 取消定时器以防止内存泄漏
super.dispose();
}

void _onItemTapped(int index) {
setState(() {
_selectedIndex = index;
_loadData();
_loadData(false);
});
}

Future<void> _loadData() async {
Future<void> _loadData(bool timer) async {
if (_selectedIndex == 0) {
deviceList = _fetchDeviceList();
setState(() {
deviceList = deviceList;
deviceList = _fetchDeviceList();
});
} else {
routeList = _fetchRouteList();
} else if (_selectedIndex == 1) {
setState(() {
routeList = routeList;
routeList = _fetchRouteList();
});
} else {
if (timer) {
_keyChart.currentState?.updateData();
} else {
_keyChart.currentState?.updateBarChart();
}
}
}

Expand Down Expand Up @@ -93,20 +113,21 @@ class _ConnectDetailPageState extends State<ConnectDetailPage> {
title: const Text('组网', style: TextStyle(color: Colors.white)),
backgroundColor: Colors.teal,
actions: [
Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0),
child: IconButton(
icon: const Text('日志', style: TextStyle(color: Colors.white)),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => LogPage(),
),
);
},
if (!Platform.isAndroid)
Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0),
child: IconButton(
icon: const Text('日志', style: TextStyle(color: Colors.white)),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => LogPage(),
),
);
},
),
),
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0),
child: IconButton(
Expand Down Expand Up @@ -173,6 +194,10 @@ class _ConnectDetailPageState extends State<ConnectDetailPage> {
icon: Icon(Icons.router),
label: '路由',
),
BottomNavigationBarItem(
icon: Icon(Icons.signal_cellular_alt),
label: '统计',
),
],
currentIndex: _selectedIndex,
selectedItemColor: Colors.amber[800],
Expand All @@ -182,12 +207,17 @@ class _ConnectDetailPageState extends State<ConnectDetailPage> {
}

List<Widget> _buildWidgetOptions() {
// var chartAList = _chartAList();
return [
DeviceList(
deviceList: deviceList,
vntBox: widget.vntBox,
),
RouteList(routeList: routeList),
StatisticsChart(
key: _keyChart,
vntBox: widget.vntBox,
)
];
}

Expand Down Expand Up @@ -306,7 +336,7 @@ class DeviceList extends StatelessWidget {
}
if (routeList != null) {
var route = routeList.map((v) {
return '${v.isTcp ? "TCP" : "UDP"}-${v.metric <= 1 ? "P2P" : "Relay"}-${v.addr} rt=${v.rt}';
return '$v-${v.metric <= 1 ? "P2P" : "Relay"}-${v.addr} rt=${v.rt}';
}).toList();
map.addAll({
'route': route,
Expand Down
2 changes: 1 addition & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -506,9 +506,9 @@ class _HomePageState extends State<HomePage> with WindowListener {
actions: [
TextButton(
onPressed: () async {
Navigator.of(context).pop();
await vntManager.removeAll();
loadConnectState();
Navigator.of(context).pop();
},
style: TextButton.styleFrom(
foregroundColor: Colors.white,
Expand Down
10 changes: 5 additions & 5 deletions lib/network_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class NetworkConfig {
List<String> portMappings;
String groupPassword;
bool isServerEncrypted;
bool isTcp;
String protocol;
bool dataFingerprintVerification;
String encryptionAlgorithm;
String deviceID;
Expand Down Expand Up @@ -40,7 +40,7 @@ class NetworkConfig {
required this.portMappings,
required this.groupPassword,
required this.isServerEncrypted,
required this.isTcp,
required this.protocol,
required this.dataFingerprintVerification,
required this.encryptionAlgorithm,
required this.deviceID,
Expand Down Expand Up @@ -70,7 +70,7 @@ class NetworkConfig {
'mapping': portMappings,
'password': groupPassword,
'server_encrypt': isServerEncrypted,
'tcp': isTcp,
'tcp': protocol,
'finger': dataFingerprintVerification,
'cipher_model': encryptionAlgorithm,
'device_id': deviceID,
Expand Down Expand Up @@ -101,7 +101,7 @@ class NetworkConfig {
if (portMappings.isNotEmpty) 'mapping': portMappings,
if (groupPassword.isNotEmpty) 'password': groupPassword,
if (isServerEncrypted) 'server_encrypt': isServerEncrypted,
if (isTcp) 'tcp': isTcp,
if (protocol.isNotEmpty) 'protocol': protocol,
if (dataFingerprintVerification) 'finger': dataFingerprintVerification,
if (encryptionAlgorithm.isNotEmpty) 'cipher_model': encryptionAlgorithm,
if (deviceID.isNotEmpty) 'device_id': deviceID,
Expand Down Expand Up @@ -134,7 +134,7 @@ class NetworkConfig {
portMappings: List<String>.from(json['mapping']),
groupPassword: json['password'],
isServerEncrypted: json['server_encrypt'],
isTcp: json['tcp'],
protocol: json['protocol']??'UDP',
dataFingerprintVerification: json['finger'],
encryptionAlgorithm: json['cipher_model'],
deviceID: json['device_id'],
Expand Down
17 changes: 12 additions & 5 deletions lib/network_config_input_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class _NetworkConfigInputPageState extends State<NetworkConfigInputPage> {
}
_groupPasswordController.text = config.groupPassword;
_isServerEncrypted = config.isServerEncrypted ? 'OPEN' : 'CLOSE';
_communicationMethod = config.isTcp ? 'TCP' : 'UDP';
_communicationMethod = config.protocol;
_dataFingerprintVerification =
config.dataFingerprintVerification ? 'OPEN' : 'CLOSE';
_encryptionAlgorithm = config.encryptionAlgorithm;
Expand Down Expand Up @@ -196,7 +196,7 @@ class _NetworkConfigInputPageState extends State<NetworkConfigInputPage> {
.toList(),
groupPassword: _groupPasswordController.text,
isServerEncrypted: _isServerEncrypted == 'OPEN',
isTcp: _communicationMethod == 'TCP',
protocol: _communicationMethod,
dataFingerprintVerification: _dataFingerprintVerification == 'OPEN',
encryptionAlgorithm: _encryptionAlgorithm,
deviceID: _deviceIDController.text,
Expand Down Expand Up @@ -357,15 +357,17 @@ class _NetworkConfigInputPageState extends State<NetworkConfigInputPage> {
last = stripPrefix(value, 'wss://');
if (last != null) {
_communicationMethod = 'WSS';
} else {
_communicationMethod = 'UDP';
}
}
}
}
setState(() {
_communicationMethod;
});
if (last != null) {
value = last;
setState(() {
_communicationMethod;
});
}
final txtRegex = RegExp(r'^txt:');
final addressPortRegex = RegExp(r'^(.+):(\d{1,5})$');
Expand All @@ -384,6 +386,11 @@ class _NetworkConfigInputPageState extends State<NetworkConfigInputPage> {
} else {
final match = addressPortRegex.firstMatch(value);
if (match != null) {
final domainRegex =
RegExp(r'^[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$');
if (!domainRegex.hasMatch(match.group(1)!)) {
return '地址格式错误';
}
final port = int.tryParse(match.group(2)!);
if (port != null && port >= 1 && port <= 65535) {
return null;
Expand Down
27 changes: 14 additions & 13 deletions lib/settings_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -305,20 +305,21 @@ class _SettingsPageState extends State<SettingsPage> {
},
),
),
ListTile(
title: const Text('应用日志'),
trailing: IconButton(
icon: const Icon(Icons.sms_failed),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => LogPage(),
),
);
},
if (!Platform.isAndroid)
ListTile(
title: const Text('应用日志'),
trailing: IconButton(
icon: const Icon(Icons.sms_failed),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => LogPage(),
),
);
},
),
),
),
],
),
);
Expand Down
Loading

0 comments on commit dcc7e5b

Please sign in to comment.