mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2026-01-31 13:25:10 +01:00
fix: ssh term (#365)
This commit is contained in:
@@ -30,7 +30,7 @@ class SSHPage extends StatefulWidget {
|
||||
final String? initCmd;
|
||||
final bool notFromTab;
|
||||
final Function()? onSessionEnd;
|
||||
final FocusNode? focus;
|
||||
final GlobalKey<TerminalViewState>? terminalKey;
|
||||
|
||||
const SSHPage({
|
||||
super.key,
|
||||
@@ -38,11 +38,11 @@ class SSHPage extends StatefulWidget {
|
||||
this.initCmd,
|
||||
this.notFromTab = true,
|
||||
this.onSessionEnd,
|
||||
this.focus,
|
||||
this.terminalKey,
|
||||
});
|
||||
|
||||
@override
|
||||
_SSHPageState createState() => _SSHPageState();
|
||||
State<SSHPage> createState() => _SSHPageState();
|
||||
}
|
||||
|
||||
const _horizonPadding = 7.0;
|
||||
@@ -52,7 +52,7 @@ class _SSHPageState extends State<SSHPage> with AutomaticKeepAliveClientMixin {
|
||||
late final _terminal = Terminal(inputHandler: _keyboard);
|
||||
final TerminalController _terminalController = TerminalController();
|
||||
final List<List<VirtKey>> _virtKeysList = [];
|
||||
late final _focus = widget.focus ?? FocusNode();
|
||||
late final _termKey = widget.terminalKey ?? GlobalKey<TerminalViewState>();
|
||||
|
||||
late MediaQueryData _media;
|
||||
late TerminalStyle _terminalStyle;
|
||||
@@ -144,8 +144,8 @@ class _SSHPageState extends State<SSHPage> with AutomaticKeepAliveClientMixin {
|
||||
),
|
||||
child: TerminalView(
|
||||
_terminal,
|
||||
key: _termKey,
|
||||
controller: _terminalController,
|
||||
focusNode: _focus,
|
||||
keyboardType: TextInputType.text,
|
||||
enableSuggestions: true,
|
||||
textStyle: _terminalStyle,
|
||||
@@ -282,11 +282,7 @@ class _SSHPageState extends State<SSHPage> with AutomaticKeepAliveClientMixin {
|
||||
Future<void> _doVirtualKeyFunc(VirtualKeyFunc type) async {
|
||||
switch (type) {
|
||||
case VirtualKeyFunc.toggleIME:
|
||||
if (!_focus.hasFocus) {
|
||||
_focus.requestFocus();
|
||||
} else {
|
||||
_focus.unfocus();
|
||||
}
|
||||
_termKey.currentState?.toggleFocus();
|
||||
break;
|
||||
case VirtualKeyFunc.backspace:
|
||||
_terminal.keyInput(TerminalKey.backspace);
|
||||
|
||||
@@ -17,8 +17,8 @@ class SSHTabPage extends StatefulWidget {
|
||||
|
||||
class _SSHTabPageState extends State<SSHTabPage>
|
||||
with TickerProviderStateMixin, AutomaticKeepAliveClientMixin {
|
||||
late final _tabMap = <String, ({Widget page, FocusNode? focus})>{
|
||||
l10n.add: (page: _buildAddPage(), focus: null),
|
||||
late final _tabMap = <String, ({Widget page})>{
|
||||
l10n.add: (page: _buildAddPage()),
|
||||
};
|
||||
late var _tabController = TabController(
|
||||
length: _tabMap.length,
|
||||
@@ -38,8 +38,7 @@ class _SSHTabPageState extends State<SSHTabPage>
|
||||
dividerColor: Colors.transparent,
|
||||
onTap: (value) {
|
||||
_fabRN.value = value;
|
||||
final mapKey = _tabMap.keys.elementAt(value);
|
||||
_tabMap[mapKey]?.focus?.requestFocus();
|
||||
FocusScope.of(context).unfocus();
|
||||
},
|
||||
),
|
||||
body: _buildBody(),
|
||||
@@ -70,20 +69,27 @@ class _SSHTabPageState extends State<SSHTabPage>
|
||||
IconBtn(
|
||||
icon: Icons.close,
|
||||
onTap: () async {
|
||||
final confirm = await context.showRoundDialog<bool>(
|
||||
title: l10n.attention,
|
||||
child: Text('${l10n.close} SSH ${l10n.conn}($e) ?'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => context.pop(true),
|
||||
child: Text(l10n.ok, style: UIs.textRed),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => context.pop(false),
|
||||
child: Text(l10n.cancel),
|
||||
),
|
||||
],
|
||||
final confirm = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return AlertDialog(
|
||||
title: Text(l10n.attention),
|
||||
content: Text('${l10n.close} SSH ${l10n.conn}($e) ?'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => context.pop(true),
|
||||
child: Text(l10n.ok, style: UIs.textRed),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => context.pop(false),
|
||||
child: Text(l10n.cancel),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
Future.delayed(const Duration(milliseconds: 50),
|
||||
FocusScope.of(context).unfocus);
|
||||
if (confirm != true) {
|
||||
return;
|
||||
}
|
||||
@@ -142,18 +148,15 @@ class _SSHTabPageState extends State<SSHTabPage>
|
||||
}
|
||||
return spi.name;
|
||||
}();
|
||||
final focus = FocusNode();
|
||||
_tabMap[name] = (
|
||||
page: SSHPage(
|
||||
spi: spi,
|
||||
focus: focus,
|
||||
notFromTab: false,
|
||||
onSessionEnd: () {
|
||||
_tabMap.remove(name);
|
||||
_refreshTabs();
|
||||
},
|
||||
),
|
||||
focus: focus,
|
||||
);
|
||||
_refreshTabs();
|
||||
final idx = _tabMap.length - 1;
|
||||
|
||||
Reference in New Issue
Block a user