mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 07:14:28 +01:00
feat: custom net dev (#543)
This commit is contained in:
@@ -2,7 +2,6 @@ import 'package:fl_lib/fl_lib.dart';
|
||||
import 'package:hive_flutter/hive_flutter.dart';
|
||||
import 'package:server_box/core/extension/context/locale.dart';
|
||||
import 'package:server_box/data/model/server/server.dart';
|
||||
import 'package:server_box/data/res/store.dart';
|
||||
|
||||
part 'net_view.g.dart';
|
||||
|
||||
@@ -27,36 +26,43 @@ enum NetViewType {
|
||||
NetViewType.speed => l10n.speed,
|
||||
};
|
||||
|
||||
(String, String) build(ServerStatus ss) {
|
||||
final ignoreLocal = Stores.setting.ignoreLocalNet.fetch();
|
||||
switch (this) {
|
||||
case NetViewType.conn:
|
||||
return (
|
||||
'${l10n.conn}:\n${ss.tcp.maxConn}',
|
||||
'${libL10n.fail}:\n${ss.tcp.fail}',
|
||||
);
|
||||
case NetViewType.speed:
|
||||
if (ignoreLocal) {
|
||||
/// If no device is specified, return the cached value (only real devices,
|
||||
/// such as ethX, wlanX...).
|
||||
(String, String) build(ServerStatus ss, {String? dev}) {
|
||||
final notSepcifyDev = dev == null || dev.isEmpty;
|
||||
try {
|
||||
switch (this) {
|
||||
case NetViewType.conn:
|
||||
return (
|
||||
'↓:\n${ss.netSpeed.cachedRealVals.speedIn}',
|
||||
'↑:\n${ss.netSpeed.cachedRealVals.speedOut}',
|
||||
'${l10n.conn}:\n${ss.tcp.maxConn}',
|
||||
'${libL10n.fail}:\n${ss.tcp.fail}',
|
||||
);
|
||||
}
|
||||
return (
|
||||
'↓:\n${ss.netSpeed.speedIn()}',
|
||||
'↑:\n${ss.netSpeed.speedOut()}',
|
||||
);
|
||||
case NetViewType.traffic:
|
||||
if (ignoreLocal) {
|
||||
case NetViewType.speed:
|
||||
if (notSepcifyDev) {
|
||||
return (
|
||||
'↓:\n${ss.netSpeed.cachedVals.speedIn}',
|
||||
'↑:\n${ss.netSpeed.cachedVals.speedOut}',
|
||||
);
|
||||
}
|
||||
return (
|
||||
'↓:\n${ss.netSpeed.cachedRealVals.sizeIn}',
|
||||
'↑:\n${ss.netSpeed.cachedRealVals.sizeOut}',
|
||||
'↓:\n${ss.netSpeed.speedIn(device: dev)}',
|
||||
'↑:\n${ss.netSpeed.speedOut(device: dev)}',
|
||||
);
|
||||
}
|
||||
return (
|
||||
'↓:\n${ss.netSpeed.sizeIn()}',
|
||||
'↑:\n${ss.netSpeed.sizeOut()}',
|
||||
);
|
||||
case NetViewType.traffic:
|
||||
if (notSepcifyDev) {
|
||||
return (
|
||||
'↓:\n${ss.netSpeed.cachedVals.sizeIn}',
|
||||
'↑:\n${ss.netSpeed.cachedVals.sizeOut}',
|
||||
);
|
||||
}
|
||||
return (
|
||||
'↓:\n${ss.netSpeed.sizeIn(device: dev)}',
|
||||
'↑:\n${ss.netSpeed.sizeOut(device: dev)}',
|
||||
);
|
||||
}
|
||||
} catch (e, s) {
|
||||
Loggers.app.warning('NetViewType.build', e, s);
|
||||
return ('N/A', 'N/A');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,14 @@ final class ServerCustom {
|
||||
@HiveField(5)
|
||||
final String? logoUrl;
|
||||
|
||||
/// The device name of the network interface displayed in the home server card.
|
||||
@HiveField(6)
|
||||
final String? netDev;
|
||||
|
||||
/// The directory where the script is stored.
|
||||
@HiveField(7)
|
||||
final String? scriptDir;
|
||||
|
||||
const ServerCustom({
|
||||
//this.temperature,
|
||||
this.pveAddr,
|
||||
@@ -28,6 +36,8 @@ final class ServerCustom {
|
||||
this.cmds,
|
||||
this.preferTempDev,
|
||||
this.logoUrl,
|
||||
this.netDev,
|
||||
this.scriptDir,
|
||||
});
|
||||
|
||||
factory ServerCustom.fromJson(Map<String, dynamic> json) =>
|
||||
@@ -35,12 +45,6 @@ final class ServerCustom {
|
||||
|
||||
Map<String, dynamic> toJson() => _$ServerCustomToJson(this);
|
||||
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return toJson().toString();
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return other is ServerCustom &&
|
||||
@@ -49,7 +53,9 @@ final class ServerCustom {
|
||||
other.pveIgnoreCert == pveIgnoreCert &&
|
||||
other.cmds == cmds &&
|
||||
other.preferTempDev == preferTempDev &&
|
||||
other.logoUrl == logoUrl;
|
||||
other.logoUrl == logoUrl &&
|
||||
other.netDev == netDev &&
|
||||
other.scriptDir == scriptDir;
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -59,5 +65,7 @@ final class ServerCustom {
|
||||
pveIgnoreCert.hashCode ^
|
||||
cmds.hashCode ^
|
||||
preferTempDev.hashCode ^
|
||||
logoUrl.hashCode;
|
||||
logoUrl.hashCode ^
|
||||
netDev.hashCode ^
|
||||
scriptDir.hashCode;
|
||||
}
|
||||
|
||||
@@ -22,13 +22,15 @@ class ServerCustomAdapter extends TypeAdapter<ServerCustom> {
|
||||
cmds: (fields[3] as Map?)?.cast<String, String>(),
|
||||
preferTempDev: fields[4] as String?,
|
||||
logoUrl: fields[5] as String?,
|
||||
netDev: fields[6] as String?,
|
||||
scriptDir: fields[7] as String?,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void write(BinaryWriter writer, ServerCustom obj) {
|
||||
writer
|
||||
..writeByte(5)
|
||||
..writeByte(7)
|
||||
..writeByte(1)
|
||||
..write(obj.pveAddr)
|
||||
..writeByte(2)
|
||||
@@ -38,7 +40,11 @@ class ServerCustomAdapter extends TypeAdapter<ServerCustom> {
|
||||
..writeByte(4)
|
||||
..write(obj.preferTempDev)
|
||||
..writeByte(5)
|
||||
..write(obj.logoUrl);
|
||||
..write(obj.logoUrl)
|
||||
..writeByte(6)
|
||||
..write(obj.netDev)
|
||||
..writeByte(7)
|
||||
..write(obj.scriptDir);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -64,6 +70,8 @@ ServerCustom _$ServerCustomFromJson(Map<String, dynamic> json) => ServerCustom(
|
||||
),
|
||||
preferTempDev: json['preferTempDev'] as String?,
|
||||
logoUrl: json['logoUrl'] as String?,
|
||||
netDev: json['netDev'] as String?,
|
||||
scriptDir: json['scriptDir'] as String?,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$ServerCustomToJson(ServerCustom instance) =>
|
||||
@@ -73,4 +81,6 @@ Map<String, dynamic> _$ServerCustomToJson(ServerCustom instance) =>
|
||||
'cmds': instance.cmds,
|
||||
'preferTempDev': instance.preferTempDev,
|
||||
'logoUrl': instance.logoUrl,
|
||||
'netDev': instance.netDev,
|
||||
'scriptDir': instance.scriptDir,
|
||||
};
|
||||
|
||||
@@ -14,6 +14,13 @@ class NetSpeedPart extends TimeSeqIface<NetSpeedPart> {
|
||||
bool same(NetSpeedPart other) => device == other.device;
|
||||
}
|
||||
|
||||
typedef CachedNetVals = ({
|
||||
String sizeIn,
|
||||
String sizeOut,
|
||||
String speedIn,
|
||||
String speedOut,
|
||||
});
|
||||
|
||||
class NetSpeed extends TimeSeq<List<NetSpeedPart>> {
|
||||
NetSpeed(super.init1, super.init2);
|
||||
|
||||
@@ -24,14 +31,14 @@ class NetSpeed extends TimeSeq<List<NetSpeedPart>> {
|
||||
|
||||
realIfaces.clear();
|
||||
realIfaces.addAll(devices
|
||||
.where((e) => realIfacePrefixs.any((prefix) => e.startsWith(prefix)))
|
||||
.toList());
|
||||
.where((e) => realIfacePrefixs.any((prefix) => e.startsWith(prefix))));
|
||||
|
||||
final sizeIn = this.sizeIn();
|
||||
final sizeOut = this.sizeOut();
|
||||
final speedIn = this.speedIn();
|
||||
final speedOut = this.speedOut();
|
||||
cachedRealVals = (
|
||||
|
||||
cachedVals = (
|
||||
sizeIn: sizeIn,
|
||||
sizeOut: sizeOut,
|
||||
speedIn: speedIn,
|
||||
@@ -49,12 +56,7 @@ class NetSpeed extends TimeSeq<List<NetSpeedPart>> {
|
||||
/// Cached non-virtual network device prefix
|
||||
final realIfaces = <String>[];
|
||||
|
||||
({
|
||||
String sizeIn,
|
||||
String sizeOut,
|
||||
String speedIn,
|
||||
String speedOut,
|
||||
}) cachedRealVals =
|
||||
CachedNetVals cachedVals =
|
||||
(sizeIn: '0kb', sizeOut: '0kb', speedIn: '0kb/s', speedOut: '0kb/s');
|
||||
|
||||
/// Time diff between [pre] and [now]
|
||||
@@ -67,7 +69,8 @@ class NetSpeed extends TimeSeq<List<NetSpeedPart>> {
|
||||
BigInt sizeOutBytes(int i) => now[i].bytesOut;
|
||||
|
||||
String speedIn({String? device}) {
|
||||
if (pre[0].device == '' || now[0].device == '') return '0kb/s';
|
||||
if (pre.isEmpty || now.isEmpty) return 'N/A';
|
||||
if (pre.length != now.length) return 'N/A';
|
||||
if (device == null) {
|
||||
var speed = 0.0;
|
||||
for (final device in devices) {
|
||||
@@ -84,7 +87,8 @@ class NetSpeed extends TimeSeq<List<NetSpeedPart>> {
|
||||
}
|
||||
|
||||
String sizeIn({String? device}) {
|
||||
if (pre[0].device == '' || now[0].device == '') return '0kb';
|
||||
if (pre.isEmpty || now.isEmpty) return 'N/A';
|
||||
if (pre.length != now.length) return 'N/A';
|
||||
if (device == null) {
|
||||
var size = BigInt.from(0);
|
||||
for (final device in devices) {
|
||||
@@ -101,7 +105,8 @@ class NetSpeed extends TimeSeq<List<NetSpeedPart>> {
|
||||
}
|
||||
|
||||
String speedOut({String? device}) {
|
||||
if (pre[0].device == '' || now[0].device == '') return '0kb/s';
|
||||
if (pre.isEmpty || now.isEmpty) return 'N/A';
|
||||
if (pre.length != now.length) return 'N/A';
|
||||
if (device == null) {
|
||||
var speed = 0.0;
|
||||
for (final device in devices) {
|
||||
@@ -118,7 +123,8 @@ class NetSpeed extends TimeSeq<List<NetSpeedPart>> {
|
||||
}
|
||||
|
||||
String sizeOut({String? device}) {
|
||||
if (pre[0].device == '' || now[0].device == '') return '0kb';
|
||||
if (pre.isEmpty || now.isEmpty) return 'N/A';
|
||||
if (pre.length != now.length) return 'N/A';
|
||||
if (device == null) {
|
||||
var size = BigInt.from(0);
|
||||
for (final device in devices) {
|
||||
|
||||
@@ -75,8 +75,7 @@ class Spi {
|
||||
this.envs,
|
||||
}) : id = '$user@$ip:$port';
|
||||
|
||||
factory Spi.fromJson(Map<String, dynamic> json) =>
|
||||
_$SpiFromJson(json);
|
||||
factory Spi.fromJson(Map<String, dynamic> json) => _$SpiFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$SpiToJson(this);
|
||||
|
||||
|
||||
@@ -34,7 +34,8 @@ class Snippet implements TagPickable {
|
||||
this.autoRunOn,
|
||||
});
|
||||
|
||||
factory Snippet.fromJson(Map<String, dynamic> json) => _$SnippetFromJson(json);
|
||||
factory Snippet.fromJson(Map<String, dynamic> json) =>
|
||||
_$SnippetFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$SnippetToJson(this);
|
||||
|
||||
|
||||
@@ -3,6 +3,6 @@
|
||||
|
||||
class BuildData {
|
||||
static const String name = "ServerBox";
|
||||
static const int build = 1060;
|
||||
static const int build = 1068;
|
||||
static const int script = 57;
|
||||
}
|
||||
|
||||
@@ -180,7 +180,7 @@ class SettingStore extends PersistentStore {
|
||||
|
||||
/// Ignore local network device (eg: br-xxx, ovs-system...)
|
||||
/// when building traffic view on server tab
|
||||
late final ignoreLocalNet = property('ignoreLocalNet', true);
|
||||
//late final ignoreLocalNet = property('ignoreLocalNet', true);
|
||||
|
||||
/// Remerber pwd in memory
|
||||
/// Used for [DialogX.showPwdDialog]
|
||||
|
||||
Reference in New Issue
Block a user