feat: custom net dev (#543)

This commit is contained in:
lollipopkit🏳️‍⚧️
2024-08-17 21:57:39 +08:00
committed by GitHub
parent b5329e2692
commit d7ae8b75b8
13 changed files with 115 additions and 91 deletions

View File

@@ -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;
}

View File

@@ -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,
};

View File

@@ -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) {

View File

@@ -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);

View File

@@ -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);