mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 07:14:28 +01:00
feat: set envs in term (#485)
This commit is contained in:
@@ -250,6 +250,9 @@ class AppRoutes {
|
||||
}
|
||||
|
||||
static AppRoutes kvEditor({Key? key, required Map<String, String> data}) {
|
||||
return AppRoutes(KvEditor(key: key, data: data), 'kv_editor');
|
||||
return AppRoutes(
|
||||
KvEditor(key: key, args: KvEditorArgs(data: data)),
|
||||
'kv_editor',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -92,6 +92,7 @@
|
||||
"editor": "Editor",
|
||||
"editorHighlightTip": "Die Leistung der aktuellen Codehervorhebung ist schlechter und kann zur Verbesserung optional ausgeschaltet werden.",
|
||||
"encode": "Encode",
|
||||
"envVars": "Umgebungsvariable",
|
||||
"error": "Fehler",
|
||||
"exampleName": "Servername",
|
||||
"experimentalFeature": "Experimentelles Feature",
|
||||
|
||||
@@ -92,6 +92,7 @@
|
||||
"editor": "Editor",
|
||||
"editorHighlightTip": "The current code highlighting performance is not ideal and can be optionally turned off to improve.",
|
||||
"encode": "Encode",
|
||||
"envVars": "Environment variable",
|
||||
"error": "Error",
|
||||
"exampleName": "Example name",
|
||||
"experimentalFeature": "Experimental feature",
|
||||
|
||||
@@ -92,6 +92,7 @@
|
||||
"editor": "Editor",
|
||||
"editorHighlightTip": "El rendimiento del resaltado de código es bastante pobre actualmente, puedes elegir desactivarlo para mejorar.",
|
||||
"encode": "Codificar",
|
||||
"envVars": "Variable de entorno",
|
||||
"error": "Error",
|
||||
"exampleName": "Ejemplo de nombre",
|
||||
"experimentalFeature": "Función experimental",
|
||||
|
||||
@@ -92,6 +92,7 @@
|
||||
"editor": "Éditeur",
|
||||
"editorHighlightTip": "La performance actuelle de mise en surbrillance du code est pire et peut être désactivée en option pour s'améliorer.",
|
||||
"encode": "Encoder",
|
||||
"envVars": "Variable d’environnement",
|
||||
"error": "Erreur",
|
||||
"exampleName": "Nom de l'exemple",
|
||||
"experimentalFeature": "Fonctionnalité expérimentale",
|
||||
|
||||
@@ -92,6 +92,7 @@
|
||||
"editor": "Editor",
|
||||
"editorHighlightTip": "Performa penyorotan kode saat ini lebih buruk, dan dapat dimatikan secara opsional untuk perbaikan.",
|
||||
"encode": "Menyandi",
|
||||
"envVars": "Variabel lingkungan",
|
||||
"error": "Kesalahan",
|
||||
"exampleName": "Nama contoh",
|
||||
"experimentalFeature": "Fitur eksperimental",
|
||||
|
||||
@@ -92,6 +92,7 @@
|
||||
"editor": "エディター",
|
||||
"editorHighlightTip": "現在のコードハイライトのパフォーマンスはかなり悪いため、改善するために無効にすることを選択できます。",
|
||||
"encode": "エンコード",
|
||||
"envVars": "環境変数",
|
||||
"error": "エラー",
|
||||
"exampleName": "名前例",
|
||||
"experimentalFeature": "実験的な機能",
|
||||
|
||||
@@ -92,6 +92,7 @@
|
||||
"editor": "Editor",
|
||||
"editorHighlightTip": "De huidige codehighlighting-prestaties zijn slechter en kunnen optioneel worden uitgeschakeld om te verbeteren.",
|
||||
"encode": "Coderen",
|
||||
"envVars": "Omgevingsvariabele",
|
||||
"error": "Fout",
|
||||
"exampleName": "Voorbeeldnaam",
|
||||
"experimentalFeature": "Experimentele functie",
|
||||
|
||||
@@ -92,6 +92,7 @@
|
||||
"editor": "Editor",
|
||||
"editorHighlightTip": "O desempenho do destaque de código atualmente é ruim, pode optar por desativá-lo para melhorar.",
|
||||
"encode": "Codificar",
|
||||
"envVars": "Variável de ambiente",
|
||||
"error": "Erro",
|
||||
"exampleName": "Exemplo de nome",
|
||||
"experimentalFeature": "Recurso experimental",
|
||||
|
||||
@@ -92,6 +92,7 @@
|
||||
"editor": "редактор",
|
||||
"editorHighlightTip": "Текущая производительность подсветки кода неудовлетворительна, можно отключить для улучшения.",
|
||||
"encode": "кодировать",
|
||||
"envVars": "Переменная окружения",
|
||||
"error": "ошибка",
|
||||
"exampleName": "пример имени",
|
||||
"experimentalFeature": "экспериментальная функция",
|
||||
|
||||
@@ -92,6 +92,7 @@
|
||||
"editor": "编辑器",
|
||||
"editorHighlightTip": "目前的代码高亮性能较为糟糕,可以选择关闭以改善。",
|
||||
"encode": "编码",
|
||||
"envVars": "环境变量",
|
||||
"error": "错误",
|
||||
"exampleName": "名称示例",
|
||||
"experimentalFeature": "实验性功能",
|
||||
|
||||
@@ -92,6 +92,7 @@
|
||||
"editor": "編輯器",
|
||||
"editorHighlightTip": "目前的代碼高亮性能較為糟糕,可以選擇關閉以改善。",
|
||||
"encode": "編碼",
|
||||
"envVars": "環境變量",
|
||||
"error": "錯誤",
|
||||
"exampleName": "名稱範例",
|
||||
"experimentalFeature": "實驗性功能",
|
||||
|
||||
@@ -22,7 +22,7 @@ class ServerEditPage extends StatefulWidget {
|
||||
State<ServerEditPage> createState() => _ServerEditPageState();
|
||||
}
|
||||
|
||||
class _ServerEditPageState extends State<ServerEditPage> {
|
||||
class _ServerEditPageState extends State<ServerEditPage> with AfterLayoutMixin {
|
||||
final _nameController = TextEditingController();
|
||||
final _ipController = TextEditingController();
|
||||
final _altUrlController = TextEditingController();
|
||||
@@ -49,58 +49,10 @@ class _ServerEditPageState extends State<ServerEditPage> {
|
||||
final _autoConnect = ValueNotifier(true);
|
||||
final _jumpServer = ValueNotifier<String?>(null);
|
||||
final _pveIgnoreCert = ValueNotifier(false);
|
||||
final _env = <String, String>{}.vn;
|
||||
|
||||
var _tags = <String>[];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
final spi = widget.spi;
|
||||
if (spi != null) {
|
||||
_nameController.text = spi.name;
|
||||
_ipController.text = spi.ip;
|
||||
_portController.text = spi.port.toString();
|
||||
_usernameController.text = spi.user;
|
||||
if (spi.keyId == null) {
|
||||
_passwordController.text = spi.pwd ?? '';
|
||||
} else {
|
||||
_keyIdx.value = Pros.key.pkis.indexWhere(
|
||||
(e) => e.id == widget.spi!.keyId,
|
||||
);
|
||||
}
|
||||
|
||||
/// List in dart is passed by pointer, so you need to copy it here
|
||||
_tags.addAll(spi.tags ?? []);
|
||||
|
||||
_altUrlController.text = spi.alterUrl ?? '';
|
||||
_autoConnect.value = spi.autoConnect ?? true;
|
||||
_jumpServer.value = spi.jumpId;
|
||||
|
||||
final custom = spi.custom;
|
||||
if (custom != null) {
|
||||
_pveAddrCtrl.text = custom.pveAddr ?? '';
|
||||
_pveIgnoreCert.value = custom.pveIgnoreCert;
|
||||
try {
|
||||
// Add a null check here to prevent setting `null` to the controller
|
||||
final encoded = json.encode(custom.cmds!);
|
||||
if (encoded.isNotEmpty) {
|
||||
_customCmdCtrl.text = encoded;
|
||||
}
|
||||
} catch (_) {}
|
||||
_preferTempDevCtrl.text = custom.preferTempDev ?? '';
|
||||
_logoUrlCtrl.text = custom.logoUrl ?? '';
|
||||
}
|
||||
|
||||
final wol = spi.wolCfg;
|
||||
if (wol != null) {
|
||||
_wolMacCtrl.text = wol.mac;
|
||||
_wolIpCtrl.text = wol.ip;
|
||||
_wolPwdCtrl.text = wol.pwd ?? '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
@@ -246,6 +198,7 @@ class _ServerEditPageState extends State<ServerEditPage> {
|
||||
),
|
||||
),
|
||||
_buildAuth(),
|
||||
_buildEnvs(),
|
||||
_buildJumpServer(),
|
||||
_buildMore(),
|
||||
];
|
||||
@@ -302,12 +255,13 @@ class _ServerEditPageState extends State<ServerEditPage> {
|
||||
}
|
||||
|
||||
Widget _buildKeyAuth() {
|
||||
const padding = EdgeInsets.only(left: 23, right: 13);
|
||||
return Consumer<PrivateKeyProvider>(
|
||||
builder: (_, key, __) {
|
||||
final tiles = List<Widget>.generate(key.pkis.length, (index) {
|
||||
final e = key.pkis[index];
|
||||
return ListTile(
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 17),
|
||||
contentPadding: padding,
|
||||
leading: Text(
|
||||
'#${index + 1}',
|
||||
style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 15),
|
||||
@@ -329,7 +283,7 @@ class _ServerEditPageState extends State<ServerEditPage> {
|
||||
tiles.add(
|
||||
ListTile(
|
||||
title: Text(l10n.addPrivateKey),
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 17),
|
||||
contentPadding: padding,
|
||||
trailing: const Padding(
|
||||
padding: EdgeInsets.only(right: 13),
|
||||
child: Icon(Icons.add),
|
||||
@@ -347,6 +301,31 @@ class _ServerEditPageState extends State<ServerEditPage> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildEnvs() {
|
||||
return _env.listenVal((val) {
|
||||
final subtitle = val.isEmpty
|
||||
? null
|
||||
: Text(val.keys.join(','), style: UIs.textGrey);
|
||||
return ListTile(
|
||||
leading: const Padding(
|
||||
padding: EdgeInsets.only(left: 10),
|
||||
child: Icon(HeroIcons.variable),
|
||||
),
|
||||
subtitle: subtitle,
|
||||
title: Text(l10n.envVars),
|
||||
trailing: const Icon(Icons.keyboard_arrow_right),
|
||||
onTap: () async {
|
||||
final res = await KvEditor.route.go(
|
||||
context,
|
||||
args: KvEditorArgs(data: widget.spi?.envs ?? {}),
|
||||
);
|
||||
if (res == null) return;
|
||||
_env.value = res;
|
||||
},
|
||||
).cardx;
|
||||
});
|
||||
}
|
||||
|
||||
Widget _buildMore() {
|
||||
return ExpandTile(
|
||||
title: Text(l10n.more),
|
||||
@@ -630,6 +609,7 @@ class _ServerEditPageState extends State<ServerEditPage> {
|
||||
jumpId: _jumpServer.value,
|
||||
custom: custom,
|
||||
wolCfg: wol,
|
||||
envs: _env.value.isEmpty ? null : _env.value,
|
||||
);
|
||||
|
||||
if (widget.spi == null) {
|
||||
@@ -655,4 +635,53 @@ class _ServerEditPageState extends State<ServerEditPage> {
|
||||
trailing: const Icon(Icons.keyboard_arrow_right),
|
||||
).cardx;
|
||||
}
|
||||
|
||||
@override
|
||||
void afterFirstLayout(BuildContext context) {
|
||||
final spi = widget.spi;
|
||||
if (spi != null) {
|
||||
_nameController.text = spi.name;
|
||||
_ipController.text = spi.ip;
|
||||
_portController.text = spi.port.toString();
|
||||
_usernameController.text = spi.user;
|
||||
if (spi.keyId == null) {
|
||||
_passwordController.text = spi.pwd ?? '';
|
||||
} else {
|
||||
_keyIdx.value = Pros.key.pkis.indexWhere(
|
||||
(e) => e.id == widget.spi!.keyId,
|
||||
);
|
||||
}
|
||||
|
||||
/// List in dart is passed by pointer, so you need to copy it here
|
||||
_tags.addAll(spi.tags ?? []);
|
||||
|
||||
_altUrlController.text = spi.alterUrl ?? '';
|
||||
_autoConnect.value = spi.autoConnect ?? true;
|
||||
_jumpServer.value = spi.jumpId;
|
||||
|
||||
final custom = spi.custom;
|
||||
if (custom != null) {
|
||||
_pveAddrCtrl.text = custom.pveAddr ?? '';
|
||||
_pveIgnoreCert.value = custom.pveIgnoreCert;
|
||||
try {
|
||||
// Add a null check here to prevent setting `null` to the controller
|
||||
final encoded = json.encode(custom.cmds!);
|
||||
if (encoded.isNotEmpty) {
|
||||
_customCmdCtrl.text = encoded;
|
||||
}
|
||||
} catch (_) {}
|
||||
_preferTempDevCtrl.text = custom.preferTempDev ?? '';
|
||||
_logoUrlCtrl.text = custom.logoUrl ?? '';
|
||||
}
|
||||
|
||||
final wol = spi.wolCfg;
|
||||
if (wol != null) {
|
||||
_wolMacCtrl.text = wol.mac;
|
||||
_wolIpCtrl.text = wol.ip;
|
||||
_wolPwdCtrl.text = wol.pwd ?? '';
|
||||
}
|
||||
|
||||
_env.value = spi.envs ?? {};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -393,12 +393,13 @@ class SSHPageState extends State<SSHPage>
|
||||
width: _terminal.viewWidth,
|
||||
height: _terminal.viewHeight,
|
||||
),
|
||||
environment: widget.spi.envs,
|
||||
);
|
||||
|
||||
//_setupDiscontinuityTimer();
|
||||
|
||||
if (session == null) {
|
||||
_writeLn('Null session');
|
||||
_writeLn('Null session, please back and retry\r\n');
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -385,8 +385,8 @@ packages:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
path: "."
|
||||
ref: "v1.0.82"
|
||||
resolved-ref: "424b976ff383222f49cd6053c79340597a5a8429"
|
||||
ref: "v1.0.84"
|
||||
resolved-ref: "4069be5204fb1866ca72b702df47fa334b189d1a"
|
||||
url: "https://github.com/lppcg/fl_lib"
|
||||
source: git
|
||||
version: "0.0.1"
|
||||
|
||||
@@ -61,7 +61,7 @@ dependencies:
|
||||
fl_lib:
|
||||
git:
|
||||
url: https://github.com/lppcg/fl_lib
|
||||
ref: v1.0.82
|
||||
ref: v1.0.84
|
||||
|
||||
dependency_overrides:
|
||||
# dartssh2:
|
||||
|
||||
Reference in New Issue
Block a user