feat: set envs in term (#485)

This commit is contained in:
lollipopkit🏳️‍⚧️
2024-07-23 21:34:34 +08:00
committed by GitHub
parent 426e5689f8
commit e4dbc3ba12
18 changed files with 124 additions and 59 deletions

View File

@@ -42,6 +42,10 @@ class ServerPrivateInfo {
@HiveField(11)
final WakeOnLanCfg? wolCfg;
/// It only applies to SSH terminal.
@HiveField(12)
final Map<String, String>? envs;
final String id;
const ServerPrivateInfo({
@@ -57,6 +61,7 @@ class ServerPrivateInfo {
this.jumpId,
this.custom,
this.wolCfg,
this.envs,
}) : id = '$user@$ip:$port';
static ServerPrivateInfo fromJson(Map<String, dynamic> json) {
@@ -76,6 +81,15 @@ class ServerPrivateInfo {
final wolCfg = json["wolCfg"] == null
? null
: WakeOnLanCfg.fromJson(json["wolCfg"].cast<String, dynamic>());
final envs_ = json["envs"] as Map<String, dynamic>?;
final envs = <String, String>{};
if (envs_ != null) {
envs_.forEach((key, value) {
if (value is String) {
envs[key] = value;
}
});
}
return ServerPrivateInfo(
name: name,
@@ -90,6 +104,7 @@ class ServerPrivateInfo {
jumpId: jumpId,
custom: custom,
wolCfg: wolCfg,
envs: envs.isEmpty ? null : envs,
);
}
@@ -123,6 +138,9 @@ class ServerPrivateInfo {
if (wolCfg != null) {
data["wolCfg"] = wolCfg?.toJson();
}
if (envs != null) {
data["envs"] = envs;
}
return data;
}

View File

@@ -29,13 +29,14 @@ class ServerPrivateInfoAdapter extends TypeAdapter<ServerPrivateInfo> {
jumpId: fields[9] as String?,
custom: fields[10] as ServerCustom?,
wolCfg: fields[11] as WakeOnLanCfg?,
envs: (fields[12] as Map?)?.cast<String, String>(),
);
}
@override
void write(BinaryWriter writer, ServerPrivateInfo obj) {
writer
..writeByte(12)
..writeByte(13)
..writeByte(0)
..write(obj.name)
..writeByte(1)
@@ -59,7 +60,9 @@ class ServerPrivateInfoAdapter extends TypeAdapter<ServerPrivateInfo> {
..writeByte(10)
..write(obj.custom)
..writeByte(11)
..write(obj.wolCfg);
..write(obj.wolCfg)
..writeByte(12)
..write(obj.envs);
}
@override