From 1a3cb09ca2ecd92e45610e995cc86892bbcec894 Mon Sep 17 00:00:00 2001 From: lollipopkit Date: Mon, 27 May 2024 11:32:52 +0800 Subject: [PATCH] fix: ssh term (#365) --- lib/app.dart | 2 +- lib/l10n/app_de.arb | 1 + lib/l10n/app_en.arb | 1 + lib/l10n/app_es.arb | 1 + lib/l10n/app_fr.arb | 1 + lib/l10n/app_id.arb | 1 + lib/l10n/app_ja.arb | 1 + lib/l10n/app_nl.arb | 1 + lib/l10n/app_pt.arb | 1 + lib/l10n/app_ru.arb | 1 + lib/l10n/app_zh.arb | 1 + lib/l10n/app_zh_tw.arb | 1 + lib/view/page/editor.dart | 2 +- lib/view/page/ping.dart | 2 +- lib/view/page/private_key/edit.dart | 2 +- lib/view/page/private_key/list.dart | 2 +- lib/view/page/process.dart | 2 +- lib/view/page/pve.dart | 2 +- lib/view/page/server/detail/view.dart | 2 +- lib/view/page/server/edit.dart | 2 +- lib/view/page/server/tab.dart | 2 +- lib/view/page/setting/entry.dart | 2 +- lib/view/page/setting/platform/ios.dart | 5 +-- lib/view/page/setting/seq/srv_seq.dart | 2 +- lib/view/page/setting/seq/virt_key.dart | 2 +- lib/view/page/snippet/edit.dart | 2 +- lib/view/page/snippet/list.dart | 2 +- lib/view/page/ssh/page.dart | 16 ++++----- lib/view/page/ssh/tab.dart | 43 +++++++++++++------------ lib/view/page/storage/sftp.dart | 2 +- lib/view/page/storage/sftp_mission.dart | 2 +- pubspec.lock | 19 ++++++----- pubspec.yaml | 11 +++---- 33 files changed, 73 insertions(+), 66 deletions(-) diff --git a/lib/app.dart b/lib/app.dart index 2659b342..195ae307 100644 --- a/lib/app.dart +++ b/lib/app.dart @@ -16,7 +16,7 @@ class MyApp extends StatelessWidget { _setup(context); return ListenableBuilder( listenable: RebuildNodes.app, - builder: (_, __) { + builder: (context, _) { if (!Stores.setting.useSystemPrimaryColor.fetch()) { UIs.colorSeed = Color(Stores.setting.primaryColor.fetch()); return _buildApp(context); diff --git a/lib/l10n/app_de.arb b/lib/l10n/app_de.arb index 61b47d97..cd1a0175 100644 --- a/lib/l10n/app_de.arb +++ b/lib/l10n/app_de.arb @@ -280,6 +280,7 @@ "suspend": "Suspend", "suspendTip": "Die Suspend-Funktion erfordert Root-Rechte und systemd-Unterstützung.", "switchTo": "Wechseln zu {val}", + "sync": "Sync", "syncTip": "Damit einige Änderungen wirksam werden, kann ein Neustart erforderlich sein.", "system": "Systeme", "tag": "Tags", diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index 106fde16..86f52dfd 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -280,6 +280,7 @@ "suspend": "Suspend", "suspendTip": "The suspend function requires root privileges and systemd support.", "switchTo": "Switch to {val}", + "sync": "Sync", "syncTip": "A restart may be required for some changes to take effect.", "system": "System", "tag": "Tags", diff --git a/lib/l10n/app_es.arb b/lib/l10n/app_es.arb index 46e4ded9..762a1982 100644 --- a/lib/l10n/app_es.arb +++ b/lib/l10n/app_es.arb @@ -280,6 +280,7 @@ "suspend": "Suspender", "suspendTip": "La función de suspender necesita permisos de root y soporte de systemd.", "switchTo": "Cambiar a {val}", + "sync": "Sincronizar", "syncTip": "Puede que necesites reiniciar para que algunos cambios tengan efecto.", "system": "Sistema", "tag": "Etiqueta", diff --git a/lib/l10n/app_fr.arb b/lib/l10n/app_fr.arb index 2809093a..c291010f 100644 --- a/lib/l10n/app_fr.arb +++ b/lib/l10n/app_fr.arb @@ -280,6 +280,7 @@ "suspend": "Suspendre", "suspendTip": "La fonction de suspension nécessite des privilèges root et le support de systemd.", "switchTo": "Passer à {val}", + "sync": "Sync", "syncTip": "Un redémarrage peut être nécessaire pour que certains changements prennent effet.", "system": "Système", "tag": "Étiquettes", diff --git a/lib/l10n/app_id.arb b/lib/l10n/app_id.arb index b54304f4..e6e18431 100644 --- a/lib/l10n/app_id.arb +++ b/lib/l10n/app_id.arb @@ -280,6 +280,7 @@ "suspend": "Suspend", "suspendTip": "Fungsi penangguhan memerlukan hak akses root dan dukungan systemd.", "switchTo": "Beralih ke {val}", + "sync": "Sinkronisasi", "syncTip": "Pengaktifan ulang mungkin diperlukan agar beberapa perubahan dapat diterapkan.", "system": "Sistem", "tag": "Tag", diff --git a/lib/l10n/app_ja.arb b/lib/l10n/app_ja.arb index bc348a83..95768a67 100644 --- a/lib/l10n/app_ja.arb +++ b/lib/l10n/app_ja.arb @@ -280,6 +280,7 @@ "suspend": "中断", "suspendTip": "suspend機能はroot権限とsystemdのサポートが必要です。", "switchTo": "{val}に切り替える", + "sync": "同期する", "syncTip": "再起動が必要な場合があります。一部の変更はその後に有効になります。", "system": "システム", "tag": "タグ", diff --git a/lib/l10n/app_nl.arb b/lib/l10n/app_nl.arb index 3a05cd58..aa225aa2 100644 --- a/lib/l10n/app_nl.arb +++ b/lib/l10n/app_nl.arb @@ -279,6 +279,7 @@ "suspend": "Ophangen", "suspendTip": "De opschortfunctie vereist rootrechten en systemd-ondersteuning.", "switchTo": "Overschakelen naar {val}", + "sync": "Sync", "syncTip": "Een herstart kan nodig zijn voor sommige wijzigingen om van kracht te worden.", "system": "Systeem", "tag": "Labels", diff --git a/lib/l10n/app_pt.arb b/lib/l10n/app_pt.arb index 5975d3b1..24d1ed37 100644 --- a/lib/l10n/app_pt.arb +++ b/lib/l10n/app_pt.arb @@ -280,6 +280,7 @@ "suspend": "Suspender", "suspendTip": "A função de suspensão requer permissões de root e suporte do systemd.", "switchTo": "Mudar para {val}", + "sync": "Sincronizar", "syncTip": "Pode ser necessário reiniciar para algumas mudanças surtirem efeito.", "system": "Sistema", "tag": "Tag", diff --git a/lib/l10n/app_ru.arb b/lib/l10n/app_ru.arb index a822817d..cd4eab81 100644 --- a/lib/l10n/app_ru.arb +++ b/lib/l10n/app_ru.arb @@ -280,6 +280,7 @@ "suspend": "приостановить", "suspendTip": "Функция приостановки требует прав root и поддержки systemd.", "switchTo": "переключиться на {val}", + "sync": "Синхронизировать", "syncTip": "Возможно, потребуется перезагрузка, чтобы некоторые изменения вступили в силу.", "system": "система", "tag": "тег", diff --git a/lib/l10n/app_zh.arb b/lib/l10n/app_zh.arb index 5561b0e5..3573ce83 100644 --- a/lib/l10n/app_zh.arb +++ b/lib/l10n/app_zh.arb @@ -280,6 +280,7 @@ "suspend": "挂起", "suspendTip": "suspend 功能需要 root 权限及 systemd 支持。", "switchTo": "切换到 {val}", + "sync": "同步", "syncTip": "可能需要重新启动,某些更改才能生效。", "system": "系统", "tag": "标签", diff --git a/lib/l10n/app_zh_tw.arb b/lib/l10n/app_zh_tw.arb index d25d94dc..fdc2e75a 100644 --- a/lib/l10n/app_zh_tw.arb +++ b/lib/l10n/app_zh_tw.arb @@ -280,6 +280,7 @@ "suspend": "挂起", "suspendTip": "suspend 功能需要 root 權限及 systemd 支持。", "switchTo": "切換到 {val}", + "sync": "同步", "syncTip": "可能需要重新啟動,某些更改才能生效。", "system": "系統", "tag": "标签", diff --git a/lib/view/page/editor.dart b/lib/view/page/editor.dart index 5226006e..2895ba34 100644 --- a/lib/view/page/editor.dart +++ b/lib/view/page/editor.dart @@ -37,7 +37,7 @@ class EditorPage extends StatefulWidget { }); @override - _EditorPageState createState() => _EditorPageState(); + State createState() => _EditorPageState(); } class _EditorPageState extends State { diff --git a/lib/view/page/ping.dart b/lib/view/page/ping.dart index bac91e32..1baafbf9 100644 --- a/lib/view/page/ping.dart +++ b/lib/view/page/ping.dart @@ -14,7 +14,7 @@ class PingPage extends StatefulWidget { const PingPage({super.key}); @override - _PingPageState createState() => _PingPageState(); + State createState() => _PingPageState(); } class _PingPageState extends State diff --git a/lib/view/page/private_key/edit.dart b/lib/view/page/private_key/edit.dart index f3b63050..ec43fdd9 100644 --- a/lib/view/page/private_key/edit.dart +++ b/lib/view/page/private_key/edit.dart @@ -19,7 +19,7 @@ class PrivateKeyEditPage extends StatefulWidget { final PrivateKeyInfo? pki; @override - _PrivateKeyEditPageState createState() => _PrivateKeyEditPageState(); + State createState() => _PrivateKeyEditPageState(); } class _PrivateKeyEditPageState extends State { diff --git a/lib/view/page/private_key/list.dart b/lib/view/page/private_key/list.dart index 0e448e50..ddde2191 100644 --- a/lib/view/page/private_key/list.dart +++ b/lib/view/page/private_key/list.dart @@ -15,7 +15,7 @@ class PrivateKeysListPage extends StatefulWidget { const PrivateKeysListPage({super.key}); @override - _PrivateKeyListState createState() => _PrivateKeyListState(); + State createState() => _PrivateKeyListState(); } class _PrivateKeyListState extends State diff --git a/lib/view/page/process.dart b/lib/view/page/process.dart index 4ac8de14..29f66f1b 100644 --- a/lib/view/page/process.dart +++ b/lib/view/page/process.dart @@ -16,7 +16,7 @@ class ProcessPage extends StatefulWidget { const ProcessPage({super.key, required this.spi}); @override - _ProcessPageState createState() => _ProcessPageState(); + State createState() => _ProcessPageState(); } class _ProcessPageState extends State { diff --git a/lib/view/page/pve.dart b/lib/view/page/pve.dart index 80d4238a..5821f784 100644 --- a/lib/view/page/pve.dart +++ b/lib/view/page/pve.dart @@ -19,7 +19,7 @@ final class PvePage extends StatefulWidget { }); @override - _PvePageState createState() => _PvePageState(); + State createState() => _PvePageState(); } const _kHorziPadding = 11.0; diff --git a/lib/view/page/server/detail/view.dart b/lib/view/page/server/detail/view.dart index 914dfe37..841a094f 100644 --- a/lib/view/page/server/detail/view.dart +++ b/lib/view/page/server/detail/view.dart @@ -32,7 +32,7 @@ class ServerDetailPage extends StatefulWidget { final ServerPrivateInfo spi; @override - _ServerDetailPageState createState() => _ServerDetailPageState(); + State createState() => _ServerDetailPageState(); } class _ServerDetailPageState extends State diff --git a/lib/view/page/server/edit.dart b/lib/view/page/server/edit.dart index ee9d6826..6d7e8f93 100644 --- a/lib/view/page/server/edit.dart +++ b/lib/view/page/server/edit.dart @@ -20,7 +20,7 @@ class ServerEditPage extends StatefulWidget { final ServerPrivateInfo? spi; @override - _ServerEditPageState createState() => _ServerEditPageState(); + State createState() => _ServerEditPageState(); } class _ServerEditPageState extends State { diff --git a/lib/view/page/server/tab.dart b/lib/view/page/server/tab.dart index e883728b..12f21e9f 100644 --- a/lib/view/page/server/tab.dart +++ b/lib/view/page/server/tab.dart @@ -25,7 +25,7 @@ class ServerPage extends StatefulWidget { const ServerPage({super.key}); @override - _ServerPageState createState() => _ServerPageState(); + State createState() => _ServerPageState(); } class _ServerPageState extends State diff --git a/lib/view/page/setting/entry.dart b/lib/view/page/setting/entry.dart index afd6dbf9..e8e70e6e 100644 --- a/lib/view/page/setting/entry.dart +++ b/lib/view/page/setting/entry.dart @@ -23,7 +23,7 @@ class SettingPage extends StatefulWidget { const SettingPage({super.key}); @override - _SettingPageState createState() => _SettingPageState(); + State createState() => _SettingPageState(); } class _SettingPageState extends State { diff --git a/lib/view/page/setting/platform/ios.dart b/lib/view/page/setting/platform/ios.dart index 9d6dd628..af861cc2 100644 --- a/lib/view/page/setting/platform/ios.dart +++ b/lib/view/page/setting/platform/ios.dart @@ -14,7 +14,7 @@ class IOSSettingsPage extends StatefulWidget { const IOSSettingsPage({super.key}); @override - _IOSSettingsPageState createState() => _IOSSettingsPageState(); + State createState() => _IOSSettingsPageState(); } class _IOSSettingsPageState extends State { @@ -83,7 +83,7 @@ class _IOSSettingsPageState extends State { } Widget _buildWatchApp() { - return FutureWidget?>( + return FutureWidget( future: () async { if (!await wc.isPaired) { return null; @@ -107,6 +107,7 @@ class _IOSSettingsPageState extends State { } return ListTile( title: const Text('Watch app'), + subtitle: Text(l10n.edit, style: UIs.textGrey), trailing: const Icon(Icons.keyboard_arrow_right), onTap: () async => _onTapWatchApp(ctx), ); diff --git a/lib/view/page/setting/seq/srv_seq.dart b/lib/view/page/setting/seq/srv_seq.dart index 970a4815..8eb212b9 100644 --- a/lib/view/page/setting/seq/srv_seq.dart +++ b/lib/view/page/setting/seq/srv_seq.dart @@ -8,7 +8,7 @@ class ServerOrderPage extends StatefulWidget { const ServerOrderPage({super.key}); @override - _ServerOrderPageState createState() => _ServerOrderPageState(); + State createState() => _ServerOrderPageState(); } class _ServerOrderPageState extends State { diff --git a/lib/view/page/setting/seq/virt_key.dart b/lib/view/page/setting/seq/virt_key.dart index 352c9752..b9fdb9c9 100644 --- a/lib/view/page/setting/seq/virt_key.dart +++ b/lib/view/page/setting/seq/virt_key.dart @@ -8,7 +8,7 @@ class SSHVirtKeySettingPage extends StatefulWidget { const SSHVirtKeySettingPage({super.key}); @override - _SSHVirtKeySettingPageState createState() => _SSHVirtKeySettingPageState(); + State createState() => _SSHVirtKeySettingPageState(); } class _SSHVirtKeySettingPageState extends State { diff --git a/lib/view/page/snippet/edit.dart b/lib/view/page/snippet/edit.dart index c6406a05..170f4146 100644 --- a/lib/view/page/snippet/edit.dart +++ b/lib/view/page/snippet/edit.dart @@ -13,7 +13,7 @@ class SnippetEditPage extends StatefulWidget { final Snippet? snippet; @override - _SnippetEditPageState createState() => _SnippetEditPageState(); + State createState() => _SnippetEditPageState(); } class _SnippetEditPageState extends State diff --git a/lib/view/page/snippet/list.dart b/lib/view/page/snippet/list.dart index 1b5ea358..2da88103 100644 --- a/lib/view/page/snippet/list.dart +++ b/lib/view/page/snippet/list.dart @@ -12,7 +12,7 @@ class SnippetListPage extends StatefulWidget { const SnippetListPage({super.key}); @override - _SnippetListPageState createState() => _SnippetListPageState(); + State createState() => _SnippetListPageState(); } class _SnippetListPageState extends State { diff --git a/lib/view/page/ssh/page.dart b/lib/view/page/ssh/page.dart index 8a4d196a..c598654f 100644 --- a/lib/view/page/ssh/page.dart +++ b/lib/view/page/ssh/page.dart @@ -30,7 +30,7 @@ class SSHPage extends StatefulWidget { final String? initCmd; final bool notFromTab; final Function()? onSessionEnd; - final FocusNode? focus; + final GlobalKey? 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 createState() => _SSHPageState(); } const _horizonPadding = 7.0; @@ -52,7 +52,7 @@ class _SSHPageState extends State with AutomaticKeepAliveClientMixin { late final _terminal = Terminal(inputHandler: _keyboard); final TerminalController _terminalController = TerminalController(); final List> _virtKeysList = []; - late final _focus = widget.focus ?? FocusNode(); + late final _termKey = widget.terminalKey ?? GlobalKey(); late MediaQueryData _media; late TerminalStyle _terminalStyle; @@ -144,8 +144,8 @@ class _SSHPageState extends State 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 with AutomaticKeepAliveClientMixin { Future _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); diff --git a/lib/view/page/ssh/tab.dart b/lib/view/page/ssh/tab.dart index fdf5b504..290e1996 100644 --- a/lib/view/page/ssh/tab.dart +++ b/lib/view/page/ssh/tab.dart @@ -17,8 +17,8 @@ class SSHTabPage extends StatefulWidget { class _SSHTabPageState extends State with TickerProviderStateMixin, AutomaticKeepAliveClientMixin { - late final _tabMap = { - l10n.add: (page: _buildAddPage(), focus: null), + late final _tabMap = { + l10n.add: (page: _buildAddPage()), }; late var _tabController = TabController( length: _tabMap.length, @@ -38,8 +38,7 @@ class _SSHTabPageState extends State 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 IconBtn( icon: Icons.close, onTap: () async { - final confirm = await context.showRoundDialog( - 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( + 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 } 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; diff --git a/lib/view/page/storage/sftp.dart b/lib/view/page/storage/sftp.dart index f11fe659..0465859a 100644 --- a/lib/view/page/storage/sftp.dart +++ b/lib/view/page/storage/sftp.dart @@ -32,7 +32,7 @@ class SftpPage extends StatefulWidget { }); @override - _SftpPageState createState() => _SftpPageState(); + State createState() => _SftpPageState(); } class _SftpPageState extends State with AfterLayoutMixin { diff --git a/lib/view/page/storage/sftp_mission.dart b/lib/view/page/storage/sftp_mission.dart index 78a0ef23..9f6f88cb 100644 --- a/lib/view/page/storage/sftp_mission.dart +++ b/lib/view/page/storage/sftp_mission.dart @@ -12,7 +12,7 @@ class SftpMissionPage extends StatefulWidget { const SftpMissionPage({super.key}); @override - _SftpMissionPageState createState() => _SftpMissionPageState(); + State createState() => _SftpMissionPageState(); } class _SftpMissionPageState extends State { diff --git a/pubspec.lock b/pubspec.lock index 0276a31a..a1d88759 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1434,20 +1434,19 @@ packages: watch_connectivity: dependency: "direct main" description: - path: "." - ref: master - resolved-ref: ad5f151a5591b64d384ef22b7855b7a2a53ad3d3 - url: "https://github.com/lollipopkit/watch_connectivity" - source: git - version: "0.1.5" + name: watch_connectivity + sha256: a4257a314601c8448662d1a91421321a2e8a3207937fec4792116f1270ea8766 + url: "https://pub.dev" + source: hosted + version: "0.2.0" watch_connectivity_platform_interface: dependency: transitive description: name: watch_connectivity_platform_interface - sha256: "9074115391bd764c08a17346fcbc4d5c0b555672defbe6928ac648503b54aa9c" + sha256: "82e8f165eac779d71bff7f6269a8be530798311cf7f3c33f1594d93468747d11" url: "https://pub.dev" source: hosted - version: "0.1.2" + version: "0.2.0" watcher: dependency: transitive description: @@ -1525,8 +1524,8 @@ packages: dependency: "direct main" description: path: "." - ref: a343bc2fdc11fbc7dbfc1f170692426a6fe01cb9 - resolved-ref: a343bc2fdc11fbc7dbfc1f170692426a6fe01cb9 + ref: master + resolved-ref: "13a280e77dd077b439af24ad3d054d318ae5df4a" url: "https://github.com/lollipopkit/xterm.dart" source: git version: "4.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index a6dca24d..a090ff15 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -27,7 +27,7 @@ dependencies: intl: ^0.19.0 xterm: git: - ref: a343bc2fdc11fbc7dbfc1f170692426a6fe01cb9 + ref: master url: https://github.com/lollipopkit/xterm.dart plain_notification_token: ^0.0.4 highlight: ^0.7.0 @@ -35,10 +35,7 @@ dependencies: code_text_field: ^1.1.0 shared_preferences: ^2.1.1 dynamic_color: ^1.6.6 - watch_connectivity: - git: - ref: master - url: https://github.com/lollipopkit/watch_connectivity + watch_connectivity: ^0.2.0 #flutter_secure_storage: ^9.0.0 xml: ^6.4.2 # for parsing nvidia-smi flutter_displaymode: ^0.6.0 @@ -63,8 +60,8 @@ dependency_overrides: # path: ../dartssh2 # fl_lib: # path: ../fl_lib -# xterm: -# path: ../xterm.dart + # xterm: + # path: ../xterm.dart dev_dependencies: flutter_native_splash: ^2.1.6