mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 15:24:35 +01:00
Isolate SSHKeyPair process to avoid run stuck
This commit is contained in:
@@ -2,6 +2,7 @@ import 'dart:async';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:dartssh2/dartssh2.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:toolbox/core/extension/stringx.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/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 {
|
||||
List<ServerInfo> _servers = [];
|
||||
List<ServerInfo> get servers => _servers;
|
||||
@@ -72,8 +79,7 @@ class ServerProvider extends BusyProvider {
|
||||
}
|
||||
final auth = spi.authorization as Map<String, dynamic>;
|
||||
return SSHClient(socket,
|
||||
username: spi.user,
|
||||
identities: SSHKeyPair.fromPem(auth['privateKey'], auth['passphrase']));
|
||||
username: spi.user, identities: await compute(loadIndentity, auth));
|
||||
}
|
||||
|
||||
Future<void> refreshData({int? idx}) async {
|
||||
@@ -104,7 +110,6 @@ class ServerProvider extends BusyProvider {
|
||||
locator<SettingStore>().serverStatusUpdateInterval.fetch()!;
|
||||
if (duration == 0) return;
|
||||
stopAutoRefresh();
|
||||
Future.delayed(const Duration(milliseconds: 677), () => refreshData());
|
||||
_timer = Timer.periodic(Duration(seconds: duration), (_) async {
|
||||
await refreshData();
|
||||
});
|
||||
|
||||
@@ -2,8 +2,9 @@
|
||||
|
||||
class BuildData {
|
||||
static const String name = "ToolBox";
|
||||
static const int build = 79;
|
||||
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 buildAt = "2022-01-09 23:06:53.086748";
|
||||
static const int modifications = 0;
|
||||
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 buildAt = "2022-01-10 10:55:03.676581";
|
||||
static const int modifications = 7;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user