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

View File

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