opt.: ssh alive

This commit is contained in:
lollipopkit
2024-02-01 14:35:15 +08:00
parent 3d5ce4b863
commit 6f3c916273
2 changed files with 49 additions and 42 deletions

View File

@@ -349,7 +349,7 @@ class _SSHPageState extends State<SSHPage> with AutomaticKeepAliveClientMixin {
), ),
); );
_setupDiscontinuityTimer(); //_setupDiscontinuityTimer();
if (session == null) { if (session == null) {
_writeLn(_server?.status.err ?? 'Null session'); _writeLn(_server?.status.err ?? 'Null session');
@@ -390,45 +390,45 @@ class _SSHPageState extends State<SSHPage> with AutomaticKeepAliveClientMixin {
.listen(_terminal.write); .listen(_terminal.write);
} }
void _setupDiscontinuityTimer() { // void _setupDiscontinuityTimer() {
_discontinuityTimer = Timer.periodic( // _discontinuityTimer = Timer.periodic(
const Duration(seconds: 5), // const Duration(seconds: 5),
(_) async { // (_) async {
var throwTimeout = true; // var throwTimeout = true;
Future.delayed(const Duration(seconds: 3), () { // Future.delayed(const Duration(seconds: 3), () {
if (throwTimeout) { // if (throwTimeout) {
_catchTimeout(); // _catchTimeout();
} // }
}); // });
await _client?.ping(); // await _client?.ping();
throwTimeout = false; // throwTimeout = false;
}, // },
); // );
} // }
void _catchTimeout() { // void _catchTimeout() {
_discontinuityTimer?.cancel(); // _discontinuityTimer?.cancel();
if (!mounted) return; // if (!mounted) return;
_writeLn('\n\nConnection lost\r\n'); // _writeLn('\n\nConnection lost\r\n');
context.showRoundDialog( // context.showRoundDialog(
title: Text(l10n.attention), // title: Text(l10n.attention),
child: Text('${l10n.disconnected}\n${l10n.goBackQ}'), // child: Text('${l10n.disconnected}\n${l10n.goBackQ}'),
barrierDismiss: false, // barrierDismiss: false,
actions: [ // actions: [
TextButton( // TextButton(
onPressed: () { // onPressed: () {
if (mounted) { // if (mounted) {
context.pop(); // context.pop();
if (widget.pop) { // if (widget.pop) {
context.pop(); // context.pop();
} // }
} // }
}, // },
child: Text(l10n.ok), // child: Text(l10n.ok),
), // ),
], // ],
); // );
} // }
@override @override
bool get wantKeepAlive => true; bool get wantKeepAlive => true;

View File

@@ -69,11 +69,18 @@ class ServerFuncBtns extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final btns = () {
try {
return Stores.setting.serverFuncBtns
.fetch()
.map((e) => ServerFuncBtn.values[e]);
} catch (e) {
return ServerFuncBtn.values;
}
}();
return Row( return Row(
mainAxisAlignment: MainAxisAlignment.spaceAround, mainAxisAlignment: MainAxisAlignment.spaceAround,
children: Stores.setting.serverFuncBtns children: btns
.fetch()
.map((e) => ServerFuncBtn.values[e])
.map( .map(
(e) => Stores.setting.moveOutServerTabFuncBtns.fetch() (e) => Stores.setting.moveOutServerTabFuncBtns.fetch()
? IconButton( ? IconButton(