Show alias if set, on remote tab
Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
parent
082839ea91
commit
730cd4ab10
@ -201,3 +201,25 @@ class RemoteCountState {
|
||||
|
||||
static RxInt find() => Get.find<RxInt>(tag: tag());
|
||||
}
|
||||
|
||||
class PeerStringOption {
|
||||
static String tag(String id, String opt) => 'peer_{$opt}_$id';
|
||||
|
||||
static void init(String id, String opt, String Function() init_getter) {
|
||||
final key = tag(id, opt);
|
||||
if (!Get.isRegistered(tag: key)) {
|
||||
final RxString value = RxString(init_getter());
|
||||
Get.put(value, tag: key);
|
||||
}
|
||||
}
|
||||
|
||||
static void delete(String id, String opt) {
|
||||
final key = tag(id, opt);
|
||||
if (Get.isRegistered(tag: key)) {
|
||||
Get.delete(tag: key);
|
||||
}
|
||||
}
|
||||
|
||||
static RxString find(String id, String opt) =>
|
||||
Get.find<RxString>(tag: tag(id, opt));
|
||||
}
|
||||
|
@ -584,7 +584,7 @@ abstract class BasePeerCard extends StatelessWidget {
|
||||
submit() async {
|
||||
isInProgress.value = true;
|
||||
name = controller.text;
|
||||
await bind.mainSetPeerOption(id: id, key: 'alias', value: name);
|
||||
await bind.mainSetPeerAlias(id: id, alias: name);
|
||||
if (isAddressBook) {
|
||||
gFFI.abModel.setPeerAlias(id, name);
|
||||
await gFFI.abModel.pushAb();
|
||||
|
@ -83,6 +83,7 @@ class _FileManagerTabPageState extends State<FileManagerTabPage> {
|
||||
controller: tabController,
|
||||
onWindowCloseButton: handleWindowCloseButton,
|
||||
tail: const AddButton().paddingOnly(left: 10),
|
||||
labelGetter: DesktopTab.labelGetterAlias,
|
||||
)),
|
||||
);
|
||||
return Platform.isMacOS
|
||||
|
@ -94,6 +94,7 @@ class _PortForwardTabPageState extends State<PortForwardTabPage> {
|
||||
return true;
|
||||
},
|
||||
tail: AddButton().paddingOnly(left: 10),
|
||||
labelGetter: DesktopTab.labelGetterAlias,
|
||||
)),
|
||||
);
|
||||
return Platform.isMacOS
|
||||
|
@ -128,6 +128,7 @@ class _ConnectionTabPageState extends State<ConnectionTabPage> {
|
||||
onWindowCloseButton: handleWindowCloseButton,
|
||||
tail: const AddButton().paddingOnly(left: 10),
|
||||
pageViewBuilder: (pageView) => pageView,
|
||||
labelGetter: DesktopTab.labelGetterAlias,
|
||||
tabBuilder: (key, icon, label, themeConf) => Obx(() {
|
||||
final connectionType = ConnectionTypeState.find(key);
|
||||
if (!connectionType.isValid()) {
|
||||
|
@ -9,6 +9,7 @@ import 'package:flutter/material.dart' hide TabBarTheme;
|
||||
import 'package:flutter_hbb/common.dart';
|
||||
import 'package:flutter_hbb/consts.dart';
|
||||
import 'package:flutter_hbb/main.dart';
|
||||
import 'package:flutter_hbb/common/shared_state.dart';
|
||||
import 'package:flutter_hbb/models/platform_model.dart';
|
||||
import 'package:flutter_hbb/models/state_model.dart';
|
||||
import 'package:get/get.dart';
|
||||
@ -252,6 +253,15 @@ class DesktopTab extends StatelessWidget {
|
||||
tabType == DesktopTabType.main || tabType == DesktopTabType.cm;
|
||||
}
|
||||
|
||||
static RxString labelGetterAlias(String peerId) {
|
||||
final opt = 'alias';
|
||||
PeerStringOption.init(peerId, opt, () {
|
||||
final alias = bind.mainGetPeerOptionSync(id: peerId, key: opt);
|
||||
return alias.isEmpty ? peerId : alias;
|
||||
});
|
||||
return PeerStringOption.find(peerId, opt);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(children: [
|
||||
|
@ -15,6 +15,7 @@ import 'package:flutter_hbb/models/file_model.dart';
|
||||
import 'package:flutter_hbb/models/server_model.dart';
|
||||
import 'package:flutter_hbb/models/user_model.dart';
|
||||
import 'package:flutter_hbb/models/state_model.dart';
|
||||
import 'package:flutter_hbb/common/shared_state.dart';
|
||||
import 'package:flutter_hbb/utils/multi_window_manager.dart';
|
||||
import 'package:tuple/tuple.dart';
|
||||
import 'package:image/image.dart' as img2;
|
||||
@ -189,6 +190,8 @@ class FfiModel with ChangeNotifier {
|
||||
rustDeskWinManager.newRemoteDesktop(arg);
|
||||
});
|
||||
}
|
||||
} else if (name == 'alias') {
|
||||
handleAliasChanged(evt);
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -198,6 +201,13 @@ class FfiModel with ChangeNotifier {
|
||||
platformFFI.setEventCallback(startEventListener(peerId));
|
||||
}
|
||||
|
||||
handleAliasChanged(Map<String, dynamic> evt) {
|
||||
final rxAlias = PeerStringOption.find(evt['id'], 'alias');
|
||||
if (rxAlias.value != evt['alias']) {
|
||||
rxAlias.value = evt['alias'];
|
||||
}
|
||||
}
|
||||
|
||||
handleSwitchDisplay(Map<String, dynamic> evt) {
|
||||
final oldOrientation = _display.width > _display.height;
|
||||
var old = _pi.currentDisplay;
|
||||
@ -927,7 +937,7 @@ class CursorModel with ChangeNotifier {
|
||||
// my throw exception, because the listener maybe already dispose
|
||||
notifyListeners();
|
||||
} catch (e) {
|
||||
debugPrint('notify cursor: $e');
|
||||
debugPrint('WARNING: updateCursorId $id, without notifyListeners(). $e');
|
||||
}
|
||||
}
|
||||
|
||||
@ -980,6 +990,9 @@ class CursorModel with ChangeNotifier {
|
||||
_hotx = tmp.item2;
|
||||
_hoty = tmp.item3;
|
||||
notifyListeners();
|
||||
} else {
|
||||
debugPrint(
|
||||
'WARNING: updateCursorId $id, cache is ${_cache == null ? "null" : "not null"}. without notifyListeners()');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -592,6 +592,11 @@ pub fn main_set_peer_option_sync(id: String, key: String, value: String) -> Sync
|
||||
SyncReturn(true)
|
||||
}
|
||||
|
||||
pub fn main_set_peer_alias(id: String, alias: String) {
|
||||
main_broadcast_message(&HashMap::from([("name", "alias"), ("id", &id), ("alias", &alias)]));
|
||||
set_peer_option(id, "alias".to_owned(), alias)
|
||||
}
|
||||
|
||||
pub fn main_forget_password(id: String) {
|
||||
forget_password(id)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user