mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 07:14:28 +01:00
#155 new: option autoConnect
This commit is contained in:
@@ -7,23 +7,25 @@ part 'server_private_info.g.dart';
|
||||
@HiveType(typeId: 3)
|
||||
class ServerPrivateInfo {
|
||||
@HiveField(0)
|
||||
late String name;
|
||||
final String name;
|
||||
@HiveField(1)
|
||||
late String ip;
|
||||
final String ip;
|
||||
@HiveField(2)
|
||||
late int port;
|
||||
final int port;
|
||||
@HiveField(3)
|
||||
late String user;
|
||||
final String user;
|
||||
@HiveField(4)
|
||||
late String pwd;
|
||||
final String? pwd;
|
||||
@HiveField(5)
|
||||
String? pubKeyId;
|
||||
final String? pubKeyId;
|
||||
@HiveField(6)
|
||||
List<String>? tags;
|
||||
final List<String>? tags;
|
||||
@HiveField(7)
|
||||
String? alterUrl;
|
||||
final String? alterUrl;
|
||||
@HiveField(8)
|
||||
final bool? autoConnect;
|
||||
|
||||
late String id;
|
||||
final String id;
|
||||
|
||||
ServerPrivateInfo({
|
||||
required this.name,
|
||||
@@ -34,19 +36,23 @@ class ServerPrivateInfo {
|
||||
this.pubKeyId,
|
||||
this.tags,
|
||||
this.alterUrl,
|
||||
this.autoConnect,
|
||||
}) : id = '$user@$ip:$port';
|
||||
|
||||
ServerPrivateInfo.fromJson(Map<String, dynamic> json) {
|
||||
name = json["name"].toString();
|
||||
ip = json["ip"].toString();
|
||||
port = json["port"] ?? 22;
|
||||
user = json["user"].toString();
|
||||
pwd = json["authorization"].toString();
|
||||
pubKeyId = json["pubKeyId"]?.toString();
|
||||
id = '$user@$ip:$port';
|
||||
tags = json["tags"]?.cast<String>();
|
||||
alterUrl = json["alterUrl"]?.toString();
|
||||
}
|
||||
/// TODO: if any field is changed, remember to update [id] [name]
|
||||
ServerPrivateInfo.fromJson(Map<String, dynamic> json)
|
||||
: ip = json["ip"].toString(),
|
||||
port = json["port"] ?? 22,
|
||||
user = json["user"]?.toString() ?? 'root',
|
||||
id =
|
||||
'${json["user"]?.toString() ?? "root"}@${json["ip"].toString()}:${json["port"] ?? 22}',
|
||||
name = json["name"]?.toString() ??
|
||||
'${json["user"]?.toString() ?? 'root'}@${json["ip"].toString()}:${json["port"] ?? 22}',
|
||||
pwd = json["authorization"]?.toString(),
|
||||
pubKeyId = json["pubKeyId"]?.toString(),
|
||||
tags = json["tags"]?.cast<String>(),
|
||||
alterUrl = json["alterUrl"]?.toString(),
|
||||
autoConnect = json["autoConnect"];
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final Map<String, dynamic> data = <String, dynamic>{};
|
||||
@@ -58,6 +64,7 @@ class ServerPrivateInfo {
|
||||
data["pubKeyId"] = pubKeyId;
|
||||
data["tags"] = tags;
|
||||
data["alterUrl"] = alterUrl;
|
||||
data["autoConnect"] = autoConnect;
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,17 +21,18 @@ class ServerPrivateInfoAdapter extends TypeAdapter<ServerPrivateInfo> {
|
||||
ip: fields[1] as String,
|
||||
port: fields[2] as int,
|
||||
user: fields[3] as String,
|
||||
pwd: fields[4] as String,
|
||||
pwd: fields[4] as String?,
|
||||
pubKeyId: fields[5] as String?,
|
||||
tags: (fields[6] as List?)?.cast<String>(),
|
||||
alterUrl: fields[7] as String?,
|
||||
autoConnect: fields[8] as bool?,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void write(BinaryWriter writer, ServerPrivateInfo obj) {
|
||||
writer
|
||||
..writeByte(8)
|
||||
..writeByte(9)
|
||||
..writeByte(0)
|
||||
..write(obj.name)
|
||||
..writeByte(1)
|
||||
@@ -47,7 +48,9 @@ class ServerPrivateInfoAdapter extends TypeAdapter<ServerPrivateInfo> {
|
||||
..writeByte(6)
|
||||
..write(obj.tags)
|
||||
..writeByte(7)
|
||||
..write(obj.alterUrl);
|
||||
..write(obj.alterUrl)
|
||||
..writeByte(8)
|
||||
..write(obj.autoConnect);
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -94,6 +94,8 @@ class ServerProvider extends ChangeNotifier {
|
||||
return Server(spi, initStatus, null, ServerState.disconnected);
|
||||
}
|
||||
|
||||
/// if [spi] is specificed then only refresh this server
|
||||
/// [onlyFailed] only refresh failed servers
|
||||
Future<void> refreshData({
|
||||
ServerPrivateInfo? spi,
|
||||
bool onlyFailed = false,
|
||||
@@ -107,6 +109,7 @@ class ServerProvider extends ChangeNotifier {
|
||||
if (s.state != ServerState.failed) return;
|
||||
_limiter.reset(s.spi.id);
|
||||
}
|
||||
if (!(s.spi.autoConnect ?? true)) return;
|
||||
return await _getData(s.spi);
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
class BuildData {
|
||||
static const String name = "ServerBox";
|
||||
static const int build = 522;
|
||||
static const int build = 525;
|
||||
static const String engine = "3.13.1";
|
||||
static const String buildAt = "2023-09-01 12:58:00.909396";
|
||||
static const int modifications = 2;
|
||||
static const String buildAt = "2023-09-03 17:54:05.367410";
|
||||
static const int modifications = 4;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user