opt.: virt keys loading

This commit is contained in:
lollipopkit🏳️‍⚧️
2024-10-05 10:18:00 +08:00
parent 393c3e6388
commit 89ec2d94d6
4 changed files with 25 additions and 16 deletions

View File

@@ -40,7 +40,7 @@ Please only download pkgs from the source that **you trust**!
## 🔖 Feature ## 🔖 Feature
- `Status chart` (CPU, Sensors, GPU...), `SSH` Term, `SFTP`, `Docker & Process & Systemd`... - `Status chart` (CPU, Sensors, GPU...), `SSH` Term, `SFTP`, `Docker & Process & Systemd`...
- Platform specific: `Bio auth``Msg push``Home widget``watchOS App`... - Platform specific: `Bio auth``Msg push``Home widget``watchOS App`...
- English, 简体中文; Deutsch [@its-tom](https://github.com/its-tom), 繁體中文 [@kalashnikov](https://github.com/kalashnikov), Indonesian [@azkadev](https://github.com/azkadev), Français [@FrancXPT](https://github.com/FrancXPT), Dutch [@QazCetelic](https://github.com/QazCetelic), Türkçe [@mikropsoft](https://github.com/mikropsoft), українська мова [@CakesTwix](https://github.com/CakesTwix); Español, Русский язык, Português, 日本語 (Generated by GPT) - English, 简体中文; Deutsch [@its-tom](https://github.com/its-tom), 繁體中文 [@kalashnikov](https://github.com/kalashnikov), Indonesian [@azkadev](https://github.com/azkadev), Français [@FrancXPT](https://github.com/FrancXPT), Dutch [@QazCetelic](https://github.com/QazCetelic), Türkçe [@mikropsoft](https://github.com/mikropsoft), Українська мова [@CakesTwix](https://github.com/CakesTwix); Español, Русский язык, Português, 日本語 (Generated by GPT)
## 🆘 Help ## 🆘 Help

View File

@@ -43,7 +43,7 @@ Linux / Windows | [GitHub](https://github.com/lollipopkit/flutter_server_box/rel
- 本地化 - 本地化
- English, 简体中文 - English, 简体中文
- Español, Русский язык, Português, 日本語 (Generated by GPT) - Español, Русский язык, Português, 日本語 (Generated by GPT)
- Deutsch [@its-tom](https://github.com/its-tom), 繁體中文 [@kalashnikov](https://github.com/kalashnikov), Indonesian [@azkadev](https://github.com/azkadev), Français [@FrancXPT](https://github.com/FrancXPT), Dutch [@QazCetelic](https://github.com/QazCetelic), Türkçe [@mikropsoft](https://github.com/mikropsoft), українська мова [@CakesTwix](https://github.com/CakesTwix); - Deutsch [@its-tom](https://github.com/its-tom), 繁體中文 [@kalashnikov](https://github.com/kalashnikov), Indonesian [@azkadev](https://github.com/azkadev), Français [@FrancXPT](https://github.com/FrancXPT), Dutch [@QazCetelic](https://github.com/QazCetelic), Türkçe [@mikropsoft](https://github.com/mikropsoft), Українська мова [@CakesTwix](https://github.com/CakesTwix);
- 感谢贡献者们! - 感谢贡献者们!

View File

@@ -1,6 +1,8 @@
import 'package:fl_lib/fl_lib.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:hive_flutter/hive_flutter.dart'; import 'package:hive_flutter/hive_flutter.dart';
import 'package:server_box/core/extension/context/locale.dart'; import 'package:server_box/core/extension/context/locale.dart';
import 'package:server_box/data/res/store.dart';
import 'package:xterm/core.dart'; import 'package:xterm/core.dart';
part 'virtual_key.g.dart'; part 'virtual_key.g.dart';
@@ -187,4 +189,18 @@ extension VirtKeyX on VirtKey {
VirtKey.ime => l10n.virtKeyHelpIME, VirtKey.ime => l10n.virtKeyHelpIME,
_ => null, _ => null,
}; };
/// - [saveDefaultIfErr] if the stored raw values is invalid, save default order to store
static List<VirtKey> loadFromStore({bool saveDefaultIfErr = true}) {
try {
final ints = Stores.setting.sshVirtKeys.fetch();
return ints.map((e) => VirtKey.values[e]).toList();
} on RangeError {
final ints = defaultOrder.map((e) => e.index).toList();
Stores.setting.sshVirtKeys.put(ints);
} catch (e, s) {
Loggers.app.warning('Failed to load sshVirtKeys', e, s);
}
return defaultOrder;
}
} }

View File

@@ -385,17 +385,7 @@ class SSHPageState extends State<SSHPage>
} }
void _initVirtKeys() { void _initVirtKeys() {
final virtKeys = () { final virtKeys = VirtKeyX.loadFromStore();
try {
return Stores.setting.sshVirtKeys
.fetch()
.map((e) => VirtKey.values[e])
.toList();
} catch (_) {
return VirtKey.values;
}
}();
for (int len = 0; len < virtKeys.length; len += 7) { for (int len = 0; len < virtKeys.length; len += 7) {
if (len + 7 > virtKeys.length) { if (len + 7 > virtKeys.length) {
_virtKeysList.add(virtKeys.sublist(len)); _virtKeysList.add(virtKeys.sublist(len));
@@ -405,15 +395,18 @@ class SSHPageState extends State<SSHPage>
} }
} }
FutureOr<List<String>?> _onKeyboardInteractive(SSHUserInfoRequest req) {
return KeybordInteractive.defaultHandle(widget.spi, ctx: context);
}
Future<void> _initTerminal() async { Future<void> _initTerminal() async {
_writeLn(libL10n.content); _writeLn(l10n.waitConnection);
_client ??= await genClient( _client ??= await genClient(
widget.spi, widget.spi,
onStatus: (p0) { onStatus: (p0) {
_writeLn(p0.toString()); _writeLn(p0.toString());
}, },
onKeyboardInteractive: (_) => onKeyboardInteractive: _onKeyboardInteractive,
KeybordInteractive.defaultHandle(widget.spi),
); );
_writeLn('${libL10n.execute}: Shell'); _writeLn('${libL10n.execute}: Shell');