diff --git a/lib/data/model/server/server_private_info.dart b/lib/data/model/server/server_private_info.dart index 6761e987..ce8b94a1 100644 --- a/lib/data/model/server/server_private_info.dart +++ b/lib/data/model/server/server_private_info.dart @@ -86,10 +86,6 @@ class ServerPrivateInfo { throw SSHErr(type: SSHErrType.connect, message: 'alterUrl port error'); } return _IpPort(ip_, port_); - - // Do not update [id] - // Because [id] is the identity which is used to find the [SSHClient] - // id = '$user@$ip:$port'; } @override diff --git a/lib/view/page/private_key/list.dart b/lib/view/page/private_key/list.dart index d5d4ef99..a8850cbc 100644 --- a/lib/view/page/private_key/list.dart +++ b/lib/view/page/private_key/list.dart @@ -1,5 +1,6 @@ import 'dart:io'; import 'dart:async'; +import 'package:after_layout/after_layout.dart'; import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:provider/provider.dart'; @@ -23,30 +24,17 @@ class PrivateKeysListPage extends StatefulWidget { _PrivateKeyListState createState() => _PrivateKeyListState(); } -class _PrivateKeyListState extends State { +class _PrivateKeyListState extends State with AfterLayoutMixin { late S _s; - bool firstBuild = true; + @override void didChangeDependencies() { super.didChangeDependencies(); - this._s = S.of(context)!; - print(123); - } - - @override - void initState() { - super.initState(); - //autoAddSystemPriavteKey(); + _s = S.of(context)!; } @override Widget build(BuildContext context) { - if (this.firstBuild) { - Future.delayed(Duration.zero, () { - autoAddSystemPriavteKey(context); - }); - } - _s = S.of(context)!; return Scaffold( appBar: AppBar( title: Text(_s.privateKey, style: textSize18), @@ -92,7 +80,7 @@ class _PrivateKeyListState extends State { ); } - void autoAddSystemPriavteKey(BuildContext context) { + void autoAddSystemPriavteKey() { final store = locator(); // Only trigger on desktop platform and no private key saved if (isDesktop && store.box.keys.isEmpty) { @@ -127,4 +115,9 @@ class _PrivateKeyListState extends State { ); } } + + @override + FutureOr afterFirstLayout(BuildContext context) { + autoAddSystemPriavteKey(); + } } diff --git a/lib/view/page/server/tab.dart b/lib/view/page/server/tab.dart index 8daffc04..8ea01b11 100644 --- a/lib/view/page/server/tab.dart +++ b/lib/view/page/server/tab.dart @@ -491,7 +491,9 @@ class _ServerPageState extends State Future gotoSSH(ServerPrivateInfo spi) async { // as a `Mobile first` app -> handle mobile first - if (!isDesktop) { + // + // run built-in ssh on macOS due to incompatibility + if (!isDesktop || isMacOS) { AppRoute(SSHPage(spi: spi), 'ssh page').go(context); return; } @@ -523,17 +525,12 @@ class _ServerPageState extends State case "linux": await Process.start("x-terminal-emulator", ["-e"] + sshCommand); break; - case "macos": - await Process.start("osascript", [ - "-e", - 'tell application "Terminal" to do script "${sshCommand.join(" ")}"' - ]); - break; default: showSnackBar(context, Text('Mismatch system: $system')); } // For security reason, delete the private key file after use if (shouldGenKey) { + if (!await file.exists()) return; await Future.delayed(const Duration(seconds: 2), file.delete); } }