Isolate SSHKeyPair process to avoid run stuck

This commit is contained in:
Junyuan Feng
2022-01-10 12:10:56 +08:00
parent 516cec5565
commit 692f3bcdbc
7 changed files with 39 additions and 31 deletions

6
.vscode/launch.json vendored
View File

@@ -13,7 +13,11 @@
"name": "toolbox (profile mode)", "name": "toolbox (profile mode)",
"request": "launch", "request": "launch",
"type": "dart", "type": "dart",
"flutterMode": "profile" "flutterMode": "profile",
"args": [
"--cache-sksl",
// "--purge-persistent-cache"
]
} }
] ]
} }

View File

@@ -354,7 +354,7 @@
buildSettings = { buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = 76; CURRENT_PROJECT_VERSION = 77;
DEVELOPMENT_TEAM = BA88US33G6; DEVELOPMENT_TEAM = BA88US33G6;
ENABLE_BITCODE = NO; ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist; INFOPLIST_FILE = Runner/Info.plist;
@@ -362,7 +362,7 @@
"$(inherited)", "$(inherited)",
"@executable_path/Frameworks", "@executable_path/Frameworks",
); );
MARKETING_VERSION = 1.0.76; MARKETING_VERSION = 1.0.77;
PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox; PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
@@ -484,7 +484,7 @@
buildSettings = { buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = 76; CURRENT_PROJECT_VERSION = 77;
DEVELOPMENT_TEAM = BA88US33G6; DEVELOPMENT_TEAM = BA88US33G6;
ENABLE_BITCODE = NO; ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist; INFOPLIST_FILE = Runner/Info.plist;
@@ -492,7 +492,7 @@
"$(inherited)", "$(inherited)",
"@executable_path/Frameworks", "@executable_path/Frameworks",
); );
MARKETING_VERSION = 1.0.76; MARKETING_VERSION = 1.0.77;
PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox; PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
@@ -508,7 +508,7 @@
buildSettings = { buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = 76; CURRENT_PROJECT_VERSION = 77;
DEVELOPMENT_TEAM = BA88US33G6; DEVELOPMENT_TEAM = BA88US33G6;
ENABLE_BITCODE = NO; ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist; INFOPLIST_FILE = Runner/Info.plist;
@@ -516,7 +516,7 @@
"$(inherited)", "$(inherited)",
"@executable_path/Frameworks", "@executable_path/Frameworks",
); );
MARKETING_VERSION = 1.0.76; MARKETING_VERSION = 1.0.77;
PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox; PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";

View File

@@ -2,6 +2,7 @@ import 'dart:async';
import 'dart:convert'; import 'dart:convert';
import 'package:dartssh2/dartssh2.dart'; import 'package:dartssh2/dartssh2.dart';
import 'package:flutter/foundation.dart';
import 'package:logging/logging.dart'; import 'package:logging/logging.dart';
import 'package:toolbox/core/extension/stringx.dart'; import 'package:toolbox/core/extension/stringx.dart';
import 'package:toolbox/core/provider_base.dart'; import 'package:toolbox/core/provider_base.dart';
@@ -20,6 +21,12 @@ import 'package:toolbox/data/store/server.dart';
import 'package:toolbox/data/store/setting.dart'; import 'package:toolbox/data/store/setting.dart';
import 'package:toolbox/locator.dart'; import 'package:toolbox/locator.dart';
/// Must put this func out of any Class
/// https://stackoverflow.com/questions/51998995/invalid-arguments-illegal-argument-in-isolate-message-object-is-a-closure
List<SSHKeyPair> loadIndentity(Map<String, dynamic> auth) {
return SSHKeyPair.fromPem(auth['privateKey'], auth['passphrase']);
}
class ServerProvider extends BusyProvider { class ServerProvider extends BusyProvider {
List<ServerInfo> _servers = []; List<ServerInfo> _servers = [];
List<ServerInfo> get servers => _servers; List<ServerInfo> get servers => _servers;
@@ -72,8 +79,7 @@ class ServerProvider extends BusyProvider {
} }
final auth = spi.authorization as Map<String, dynamic>; final auth = spi.authorization as Map<String, dynamic>;
return SSHClient(socket, return SSHClient(socket,
username: spi.user, username: spi.user, identities: await compute(loadIndentity, auth));
identities: SSHKeyPair.fromPem(auth['privateKey'], auth['passphrase']));
} }
Future<void> refreshData({int? idx}) async { Future<void> refreshData({int? idx}) async {
@@ -104,7 +110,6 @@ class ServerProvider extends BusyProvider {
locator<SettingStore>().serverStatusUpdateInterval.fetch()!; locator<SettingStore>().serverStatusUpdateInterval.fetch()!;
if (duration == 0) return; if (duration == 0) return;
stopAutoRefresh(); stopAutoRefresh();
Future.delayed(const Duration(milliseconds: 677), () => refreshData());
_timer = Timer.periodic(Duration(seconds: duration), (_) async { _timer = Timer.periodic(Duration(seconds: duration), (_) async {
await refreshData(); await refreshData();
}); });

View File

@@ -2,8 +2,9 @@
class BuildData { class BuildData {
static const String name = "ToolBox"; static const String name = "ToolBox";
static const int build = 79; static const int build = 77;
static const String engine = "Flutter 2.8.1 • channel stable • https://github.com/flutter/flutter.git\nFramework • revision 77d935af4d (3 weeks ago) • 2021-12-16 08:37:33 -0800\nEngine • revision 890a5fca2e\nTools • Dart 2.15.1\n"; static const String engine =
static const String buildAt = "2022-01-09 23:06:53.086748"; "Flutter 2.8.1 • channel stable • https://github.com/flutter/flutter.git\nFramework • revision 77d935af4d (3 weeks ago) • 2021-12-16 08:37:33 -0800\nEngine • revision 890a5fca2e\nTools • Dart 2.15.1\n";
static const int modifications = 0; static const String buildAt = "2022-01-10 10:55:03.676581";
static const int modifications = 7;
} }

View File

@@ -3,6 +3,7 @@ import 'dart:convert';
import 'package:clipboard/clipboard.dart'; import 'package:clipboard/clipboard.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_staggered_animations/flutter_staggered_animations.dart'; import 'package:flutter_staggered_animations/flutter_staggered_animations.dart';
import 'package:toolbox/core/utils.dart';
import 'package:toolbox/data/res/color.dart'; import 'package:toolbox/data/res/color.dart';
class ConvertPage extends StatefulWidget { class ConvertPage extends StatefulWidget {
@@ -70,7 +71,11 @@ class _ConvertPageState extends State<ConvertPage>
), ),
floatingActionButton: FloatingActionButton( floatingActionButton: FloatingActionButton(
onPressed: () { onPressed: () {
_textEditingControllerResult.text = doConvert(); try {
_textEditingControllerResult.text = doConvert();
} catch (e) {
showSnackBar(context, Text('Error: \n$e'));
}
}, },
tooltip: 'convert', tooltip: 'convert',
child: const Icon(Icons.send), child: const Icon(Icons.send),
@@ -79,7 +84,7 @@ class _ConvertPageState extends State<ConvertPage>
} }
String doConvert() { String doConvert() {
final text = _textEditingController.text; final text = _textEditingController.text.trim();
switch (_typeOptionIndex) { switch (_typeOptionIndex) {
case 0: case 0:
return utf8.decode(base64.decode(text)); return utf8.decode(base64.decode(text));

View File

@@ -35,8 +35,8 @@ class _ServerDetailPageState extends State<ServerDetailPage>
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Consumer<ServerProvider>(builder: (_, provider, __) { return Consumer<ServerProvider>(builder: (_, provider, __) {
return _buildMainPage( return _buildMainPage(provider.servers
provider.servers.firstWhere((e) => '${e.info.ip}:${e.info.port}' == widget.id)); .firstWhere((e) => '${e.info.ip}:${e.info.port}' == widget.id));
}); });
} }
@@ -44,16 +44,6 @@ class _ServerDetailPageState extends State<ServerDetailPage>
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
title: Text(si.info.name), title: Text(si.info.name),
actions: [
IconButton(
onPressed: () => AppRoute(
ServerEditPage(
spi: si.info,
),
'Edit server info page')
.go(context),
icon: const Icon(Icons.edit))
],
), ),
body: ListView( body: ListView(
padding: const EdgeInsets.all(17), padding: const EdgeInsets.all(17),

View File

@@ -115,8 +115,10 @@ class _ServerPageState extends State<ServerPage>
.go(context), .go(context),
child: Padding( child: Padding(
padding: const EdgeInsets.all(13), padding: const EdgeInsets.all(13),
child: child: SizedBox(
_buildRealServerCard(si.status, si.info.name, si.connectionState), height: _media.size.height * 0.147,
child: _buildRealServerCard(
si.status, si.info.name, si.connectionState)),
), ),
onTap: () => AppRoute(ServerDetailPage('${si.info.ip}:${si.info.port}'), onTap: () => AppRoute(ServerDetailPage('${si.info.ip}:${si.info.port}'),
'server detail page') 'server detail page')
@@ -239,7 +241,7 @@ class _ServerPageState extends State<ServerPage>
Widget _buildPercentCircle(double percent, String title) { Widget _buildPercentCircle(double percent, String title) {
if (percent <= 0) percent = 0.01; if (percent <= 0) percent = 0.01;
if (percent >= 100) percent = 99.9; if (percent >= 100) percent = 99.9;
var size = _media.size.height * 0.147; var size = _media.size.height * 0.15;
return SizedBox( return SizedBox(
width: _media.size.width * 0.2, width: _media.size.width * 0.2,
height: _media.size.height * 0.1, height: _media.size.height * 0.1,
@@ -285,6 +287,7 @@ class _ServerPageState extends State<ServerPage>
Future<void> afterFirstLayout(BuildContext context) async { Future<void> afterFirstLayout(BuildContext context) async {
await GetIt.I.allReady(); await GetIt.I.allReady();
await _serverProvider.loadLocalData(); await _serverProvider.loadLocalData();
_serverProvider.refreshData();
_serverProvider.startAutoRefresh(); _serverProvider.startAutoRefresh();
} }
} }