Skip to content

An open-source remote desktop application designed for self-hosting, as an alternative to TeamViewer.

sync ab alias

21pages57b8ec178ccb
diff --git a/flutter/lib/common/widgets/peer_card.dart b/flutter/lib/common/widgets/peer_card.dart
index 5ace63fb8..88d44cc7e 100644
--- a/flutter/lib/common/widgets/peer_card.dart
+++ b/flutter/lib/common/widgets/peer_card.dart
@@ -159,7 +159,6 @@ class _PeerCardState extends State<_PeerCard>
final greyStyle = TextStyle(
fontSize: 11,
color: Theme.of(context).textTheme.titleLarge?.color?.withOpacity(0.6));
- final alias = bind.mainGetPeerOptionSync(id: peer.id, key: 'alias');
final child = Obx(
() => Container(
foregroundDecoration: deco.value,
@@ -196,7 +195,9 @@ class _PeerCardState extends State<_PeerCard>
getOnline(8, peer.online),
Expanded(
child: Text(
- alias.isEmpty ? formatID(peer.id) : alias,
+ peer.alias.isEmpty
+ ? formatID(peer.id)
+ : peer.alias,
overflow: TextOverflow.ellipsis,
style: Theme.of(context).textTheme.titleSmall,
)),
@@ -651,8 +652,13 @@ abstract class BasePeerCard extends StatelessWidget {
oldName: oldName,
onSubmit: (String newName) async {
if (newName != oldName) {
- await bind.mainSetPeerAlias(id: id, alias: newName);
- _update();
+ if (tab == PeerTabIndex.ab) {
+ gFFI.abModel.changeAlias(id: id, alias: newName);
+ gFFI.abModel.pushAb();
+ } else {
+ await bind.mainSetPeerAlias(id: id, alias: newName);
+ _update();
+ }
}
});
},
@@ -1050,6 +1056,11 @@ class AddressBookPeerCard extends BasePeerCard {
dismissOnClicked: true,
);
}
+
+ @protected
+ @override
+ Future<String> _getAlias(String id) async =>
+ gFFI.abModel.find(id)?.alias ?? '';
}
class MyGroupPeerCard extends BasePeerCard {
diff --git a/flutter/lib/models/ab_model.dart b/flutter/lib/models/ab_model.dart
index f1722efe9..7fdf940d3 100644
--- a/flutter/lib/models/ab_model.dart
+++ b/flutter/lib/models/ab_model.dart
@@ -197,6 +197,14 @@ class AbModel {
}).toList();
}
+ void changeAlias({required String id, required String alias}) {
+ final it = peers.where((element) => element.id == id);
+ if (it.isEmpty) {
+ return;
+ }
+ it.first.alias = alias;
+ }
+
Future<void> pushAb({bool toast = true}) async {
debugPrint("pushAb");
pushError.value = '';
@@ -332,7 +340,7 @@ class AbModel {
username: r.username.isEmpty ? p.username : r.username,
hostname: r.hostname.isEmpty ? p.hostname : r.hostname,
platform: r.platform.isEmpty ? p.platform : r.platform,
- alias: r.alias,
+ alias: p.alias.isEmpty ? r.alias : p.alias,
tags: p.tags,
forceAlwaysRelay: r.forceAlwaysRelay,
rdpPort: r.rdpPort,
@@ -352,7 +360,8 @@ class AbModel {
return a.hash != b.hash ||
a.username != b.username ||
a.platform != b.platform ||
- a.hostname != b.hostname;
+ a.hostname != b.hostname ||
+ a.alias != b.alias;
}
Future<List<Peer>> getRecentPeers() async {
diff --git a/flutter/lib/models/peer_model.dart b/flutter/lib/models/peer_model.dart
index 7a61c3dcf..98810b09e 100644
--- a/flutter/lib/models/peer_model.dart
+++ b/flutter/lib/models/peer_model.dart
@@ -56,6 +56,7 @@ class Peer {
"username": username,
"hostname": hostname,
"platform": platform,
+ "alias": alias,
"tags": tags,
};
}
diff --git a/libs/hbb_common/src/config.rs b/libs/hbb_common/src/config.rs
index 16c02d758..b0ec5602f 100644
--- a/libs/hbb_common/src/config.rs
+++ b/libs/hbb_common/src/config.rs
@@ -1499,6 +1499,12 @@ pub struct AbPeer {
skip_serializing_if = "String::is_empty"
)]
pub platform: String,
+ #[serde(
+ default,
+ deserialize_with = "deserialize_string",
+ skip_serializing_if = "String::is_empty"
+ )]
+ pub alias: String,
#[serde(default, deserialize_with = "deserialize_vec_string")]
pub tags: Vec<String>,
}