56 lines
1.5 KiB
Dart
56 lines
1.5 KiB
Dart
final class RemoteConnection {
|
|
const RemoteConnection({
|
|
required this.id,
|
|
required this.name,
|
|
required this.host,
|
|
required this.port,
|
|
required this.status,
|
|
required this.config,
|
|
});
|
|
|
|
factory RemoteConnection.fromJson(Map<String, dynamic> json) {
|
|
final String id = (json['id'] ?? json['uuid'] ?? '').toString();
|
|
final String name = (json['name'] ?? json['remark'] ?? json['title'] ?? '')
|
|
.toString();
|
|
final String host =
|
|
(json['host'] ?? json['server'] ?? json['address'] ?? '').toString();
|
|
final int port = int.tryParse((json['port'] ?? '').toString()) ?? 0;
|
|
final String status = (json['status'] ?? json['state'] ?? 'unknown')
|
|
.toString();
|
|
final String config = (json['config'] ?? json['link'] ?? json['url'] ?? '')
|
|
.toString();
|
|
|
|
return RemoteConnection(
|
|
id: id,
|
|
name: name.isEmpty ? 'Unnamed connection' : name,
|
|
host: host,
|
|
port: port,
|
|
status: status,
|
|
config: config,
|
|
);
|
|
}
|
|
|
|
final String id;
|
|
final String name;
|
|
final String host;
|
|
final int port;
|
|
final String status;
|
|
final String config;
|
|
|
|
String get subtitle {
|
|
if (host.isEmpty || port <= 0) {
|
|
return status;
|
|
}
|
|
|
|
return '$host:$port • $status';
|
|
}
|
|
|
|
String get safeName {
|
|
final int separatorIndex = name.indexOf('-');
|
|
final String value =
|
|
separatorIndex >= 0 ? name.substring(0, separatorIndex) : name;
|
|
final String trimmed = value.trim();
|
|
return trimmed.isEmpty ? 'Connection' : trimmed;
|
|
}
|
|
}
|