adjust cm display behavior

Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
21pages
2022-09-01 21:18:53 +08:00
parent 39a1545e94
commit f6bc448cec
10 changed files with 83 additions and 40 deletions

View File

@@ -209,10 +209,19 @@ class ChatModel with ChangeNotifier {
id: await bind.mainGetLastRemoteId(),
);
} else {
final client = _ffi.target?.serverModel.clients[id];
final client = _ffi.target?.serverModel.clients
.firstWhere((client) => client.id == id);
if (client == null) {
return debugPrint("Failed to receive msg,user doesn't exist");
}
if (isDesktop) {
window_on_top(null);
var index = _ffi.target?.serverModel.clients
.indexWhere((client) => client.id == id);
if (index != null && index >= 0) {
gFFI.serverModel.tabController.jumpTo(index);
}
}
chatUser = ChatUser(id: client.peerId, firstName: client.name);
}

View File

@@ -32,7 +32,7 @@ class ServerModel with ChangeNotifier {
late final TextEditingController _serverId;
final _serverPasswd = TextEditingController(text: "");
final tabController = DesktopTabController();
final tabController = DesktopTabController(tabType: DesktopTabType.cm);
List<Client> _clients = [];
@@ -347,20 +347,18 @@ class ServerModel with ChangeNotifier {
var res = await bind.mainGetClientsState();
try {
final List clientsJson = jsonDecode(res);
if (isDesktop && clientsJson.isEmpty && _clients.isNotEmpty) {
// exit cm when >1 peers to no peers
exit(0);
}
_clients.clear();
tabController.state.value.tabs.clear();
for (var clientJson in clientsJson) {
final client = Client.fromJson(clientJson);
_clients.add(client);
tabController.add(TabInfo(
key: client.id.toString(),
label: client.name,
closable: false,
page: Desktop.buildConnectionCard(client)));
tabController.add(
TabInfo(
key: client.id.toString(),
label: client.name,
closable: false,
page: Desktop.buildConnectionCard(client)),
authorized: client.authorized);
}
notifyListeners();
} catch (e) {
@@ -471,14 +469,18 @@ class ServerModel with ChangeNotifier {
} else {
_clients[index].authorized = true;
}
tabController.add(TabInfo(
key: client.id.toString(),
label: client.name,
closable: false,
page: Desktop.buildConnectionCard(client)));
tabController.add(
TabInfo(
key: client.id.toString(),
label: client.name,
closable: false,
page: Desktop.buildConnectionCard(client)),
authorized: true);
scrollToBottom();
notifyListeners();
} catch (e) {}
} catch (e) {
debugPrint("onClientAuthorized:$e");
}
}
void onClientRemove(Map<String, dynamic> evt) {
@@ -486,8 +488,10 @@ class ServerModel with ChangeNotifier {
final id = int.parse(evt['id'] as String);
if (_clients.any((c) => c.id == id)) {
final index = _clients.indexWhere((client) => client.id == id);
_clients.removeAt(index);
tabController.remove(index);
if (index >= 0) {
_clients.removeAt(index);
tabController.remove(index);
}
parent.target?.dialogManager.dismissByTag(getLoginDialogTag(id));
parent.target?.invokeMethod("cancel_notification", id);
}