This commit is contained in:
lollipopkit
2023-08-13 22:19:08 +08:00
parent 1af7271a06
commit 8057c24947
3 changed files with 14 additions and 28 deletions

View File

@@ -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

View File

@@ -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<PrivateKeysListPage> {
class _PrivateKeyListState extends State<PrivateKeysListPage> 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<PrivateKeysListPage> {
);
}
void autoAddSystemPriavteKey(BuildContext context) {
void autoAddSystemPriavteKey() {
final store = locator<PrivateKeyStore>();
// Only trigger on desktop platform and no private key saved
if (isDesktop && store.box.keys.isEmpty) {
@@ -127,4 +115,9 @@ class _PrivateKeyListState extends State<PrivateKeysListPage> {
);
}
}
@override
FutureOr<void> afterFirstLayout(BuildContext context) {
autoAddSystemPriavteKey();
}
}

View File

@@ -491,7 +491,9 @@ class _ServerPageState extends State<ServerPage>
Future<void> 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<ServerPage>
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);
}
}