new: VersionRelated

This commit is contained in:
lollipopkit
2024-03-20 20:26:22 -06:00
parent d5ce11c788
commit fae3a20a9e
12 changed files with 166 additions and 95 deletions

View File

@@ -21,29 +21,27 @@ enum ServerFuncBtn {
snippet,
@HiveField(6)
iperf,
@HiveField(7)
pve,
// @HiveField(7)
// pve,
;
static const defaultFuncs = [
static final defaultIdxs = [
terminal,
sftp,
container,
process,
pkg,
snippet,
pve,
];
].map((e) => e.index).toList();
Icon get icon => switch (this) {
sftp => const Icon(Icons.insert_drive_file, size: 15),
snippet => const Icon(Icons.code, size: 15),
pkg => const Icon(Icons.system_security_update, size: 15),
container => const Icon(FontAwesome.docker_brand, size: 14),
process => const Icon(Icons.list_alt_outlined, size: 15),
terminal => const Icon(Icons.terminal, size: 15),
iperf => const Icon(Icons.speed, size: 15),
pve => const Icon(FontAwesome.server_solid, size: 13),
Icon icon([double? sizeDiff]) => switch (this) {
sftp => Icon(Icons.insert_drive_file, size: 15 + (sizeDiff ?? 0)),
snippet => Icon(Icons.code, size: 15 + (sizeDiff ?? 0)),
pkg => Icon(Icons.system_security_update, size: 15 + (sizeDiff ?? 0)),
container => Icon(FontAwesome.docker_brand, size: 14 + (sizeDiff ?? 0)),
process => Icon(Icons.list_alt_outlined, size: 15 + (sizeDiff ?? 0)),
terminal => Icon(Icons.terminal, size: 15 + (sizeDiff ?? 0)),
iperf => Icon(Icons.speed, size: 15 + (sizeDiff ?? 0)),
};
String get toStr => switch (this) {
@@ -54,10 +52,5 @@ enum ServerFuncBtn {
process => l10n.process,
terminal => l10n.terminal,
iperf => 'iperf',
pve => 'PVE',
};
int toJson() => index;
static ServerFuncBtn fromJson(int i) => values[i];
}

View File

@@ -27,8 +27,6 @@ class ServerFuncBtnAdapter extends TypeAdapter<ServerFuncBtn> {
return ServerFuncBtn.snippet;
case 6:
return ServerFuncBtn.iperf;
case 7:
return ServerFuncBtn.pve;
default:
return ServerFuncBtn.terminal;
}
@@ -58,9 +56,6 @@ class ServerFuncBtnAdapter extends TypeAdapter<ServerFuncBtn> {
case ServerFuncBtn.iperf:
writer.writeByte(6);
break;
case ServerFuncBtn.pve:
writer.writeByte(7);
break;
}
}

View File

@@ -0,0 +1,56 @@
import 'package:toolbox/core/extension/context/locale.dart';
import 'package:toolbox/core/extension/listx.dart';
import 'package:toolbox/data/model/app/version_related.dart';
import 'package:toolbox/data/res/store.dart';
enum ServerDetailCards implements VersionRelated {
about,
cpu,
mem,
swap,
gpu,
disk,
net,
sensor,
temp,
battery,
pve(sinceBuild: 818),
;
@override
final int? sinceBuild;
const ServerDetailCards({this.sinceBuild});
static ServerDetailCards? fromName(String str) =>
ServerDetailCards.values.firstWhereOrNull((e) => e.name == str);
static final names = values.map((e) => e.name).toList();
String get toStr => switch (this) {
about => l10n.about,
cpu => 'CPU',
mem => 'RAM',
swap => 'Swap',
gpu => 'GPU',
disk => l10n.disk,
net => l10n.net,
sensor => l10n.sensors,
temp => l10n.temperature,
battery => l10n.battery,
pve => 'PVE',
};
/// If:
/// Version 1 => user set [about], default is [about, cpu]
/// Version 2 => default is [about, cpu, mem] => auto add [mem] to user's setting
static void autoAddNewCards(int cur) {
if (cur >= pve.sinceBuild!) {
final prop = Stores.setting.detailCardOrder;
final list = prop.fetch();
if (list.contains(pve.name)) return;
list.add(pve.name);
prop.put(list);
}
}
}

View File

@@ -0,0 +1,9 @@
import 'package:toolbox/data/model/app/server_detail_card.dart';
abstract interface class VersionRelated {
int? get sinceBuild;
static final funcs = <void Function(int cur)>[
ServerDetailCards.autoAddNewCards,
];
}

View File

@@ -54,6 +54,23 @@ enum VirtKey {
}
}
static final defaultOrder = [
VirtKey.esc,
VirtKey.alt,
VirtKey.home,
VirtKey.up,
VirtKey.end,
VirtKey.sftp,
VirtKey.snippet,
VirtKey.tab,
VirtKey.ctrl,
VirtKey.left,
VirtKey.down,
VirtKey.right,
VirtKey.clipboard,
VirtKey.ime,
];
TerminalKey? get key {
switch (this) {
case VirtKey.esc: