Merge pull request #1969 from fufesou/fix_cm

Fix cm
This commit is contained in:
RustDesk 2022-11-05 11:00:08 +08:00 committed by GitHub
commit 96f2e61ca4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 35 additions and 30 deletions

View File

@ -54,6 +54,7 @@ class ChatPage extends StatelessWidget implements PageShape {
return DashChat( return DashChat(
onSend: (chatMsg) { onSend: (chatMsg) {
chatModel.send(chatMsg); chatModel.send(chatMsg);
chatModel.inputNode.requestFocus();
}, },
currentUser: chatModel.me, currentUser: chatModel.me,
messages: chatModel messages: chatModel

View File

@ -101,6 +101,7 @@ class ConnectionManagerState extends State<ConnectionManager> {
gFFI.serverModel.updateClientState(); gFFI.serverModel.updateClientState();
gFFI.serverModel.tabController.onSelected = (index, _) => gFFI.serverModel.tabController.onSelected = (index, _) =>
gFFI.chatModel.changeCurrentID(gFFI.serverModel.clients[index].id); gFFI.chatModel.changeCurrentID(gFFI.serverModel.clients[index].id);
gFFI.chatModel.isConnManager = true;
super.initState(); super.initState();
} }
@ -159,7 +160,7 @@ class ConnectionManagerState extends State<ConnectionManager> {
pageViewBuilder: (pageView) => Row(children: [ pageViewBuilder: (pageView) => Row(children: [
Expanded(child: pageView), Expanded(child: pageView),
Consumer<ChatModel>( Consumer<ChatModel>(
builder: (_, model, child) => model.isShowChatPage builder: (_, model, child) => model.isShowCMChatPage
? Expanded(child: Scaffold(body: ChatPage())) ? Expanded(child: Scaffold(body: ChatPage()))
: Offstage()) : Offstage())
]))); ])));

View File

@ -160,15 +160,10 @@ void runConnectionManagerScreen() async {
); );
windowManager.waitUntilReadyToShow(windowOptions, () async { windowManager.waitUntilReadyToShow(windowOptions, () async {
await windowManager.show(); await windowManager.show();
await Future.wait([windowManager.focus(), windowManager.setOpacity(1)]);
// ensure initial window size to be changed // ensure initial window size to be changed
await windowManager.setSize(kConnectionManagerWindowSize); await windowManager.setSizeAlignment(
await Future.wait([ kConnectionManagerWindowSize, Alignment.topRight);
windowManager.setAlignment(Alignment.topRight),
windowManager.focus(),
windowManager.setOpacity(1)
]);
// ensure
windowManager.setAlignment(Alignment.topRight);
}); });
} }

View File

@ -32,6 +32,7 @@ class ChatModel with ChangeNotifier {
OverlayState? _overlayState; OverlayState? _overlayState;
OverlayEntry? chatIconOverlayEntry; OverlayEntry? chatIconOverlayEntry;
OverlayEntry? chatWindowOverlayEntry; OverlayEntry? chatWindowOverlayEntry;
bool isConnManager = false;
final ChatUser me = ChatUser( final ChatUser me = ChatUser(
id: "", id: "",
@ -42,13 +43,13 @@ class ChatModel with ChangeNotifier {
MessageBody(me, []); MessageBody(me, []);
var _currentID = clientModeID; var _currentID = clientModeID;
late bool _isShowChatPage = false; late bool _isShowCMChatPage = false;
Map<int, MessageBody> get messages => _messages; Map<int, MessageBody> get messages => _messages;
int get currentID => _currentID; int get currentID => _currentID;
bool get isShowChatPage => _isShowChatPage; bool get isShowCMChatPage => _isShowCMChatPage;
final WeakReference<FFI> parent; final WeakReference<FFI> parent;
@ -147,9 +148,11 @@ class ChatModel with ChangeNotifier {
} }
} }
_isChatOverlayHide() => ((!isDesktop && chatIconOverlayEntry == null) ||
chatWindowOverlayEntry == null);
toggleChatOverlay() { toggleChatOverlay() {
if ((!isDesktop && chatIconOverlayEntry == null) || if (_isChatOverlayHide()) {
chatWindowOverlayEntry == null) {
gFFI.invokeMethod("enable_soft_keyboard", true); gFFI.invokeMethod("enable_soft_keyboard", true);
if (!isDesktop) { if (!isDesktop) {
showChatIconOverlay(); showChatIconOverlay();
@ -161,20 +164,29 @@ class ChatModel with ChangeNotifier {
} }
} }
showChatPage(int id) async {
if (isConnManager) {
if (!_isShowCMChatPage) {
await toggleCMChatPage(id);
}
} else {
if (_isChatOverlayHide()) {
await toggleChatOverlay();
}
}
}
toggleCMChatPage(int id) async { toggleCMChatPage(int id) async {
if (gFFI.chatModel.currentID != id) { if (gFFI.chatModel.currentID != id) {
gFFI.chatModel.changeCurrentID(id); gFFI.chatModel.changeCurrentID(id);
} }
if (_isShowChatPage) { if (_isShowCMChatPage) {
_isShowChatPage = !_isShowChatPage; _isShowCMChatPage = !_isShowCMChatPage;
notifyListeners(); notifyListeners();
await windowManager.setSize(Size(300, 400)); await windowManager.setSizeAlignment(Size(300, 400), Alignment.topRight);
await windowManager.setAlignment(Alignment.topRight);
} else { } else {
await windowManager.setSize(Size(600, 400)); await windowManager.setSizeAlignment(Size(600, 400), Alignment.topRight);
await Future.delayed(Duration(milliseconds: 100)); _isShowCMChatPage = !_isShowCMChatPage;
await windowManager.setAlignment(Alignment.topRight);
_isShowChatPage = !_isShowChatPage;
notifyListeners(); notifyListeners();
} }
} }
@ -208,13 +220,11 @@ class ChatModel with ChangeNotifier {
} }
if (text.isEmpty) return; if (text.isEmpty) return;
// mobile: first message show overlay icon // mobile: first message show overlay icon
if (chatIconOverlayEntry == null) { if (!isDesktop && chatIconOverlayEntry == null) {
showChatIconOverlay(); showChatIconOverlay();
} }
// desktop: show chat page // show chat page
if (!_isShowChatPage) { await showChatPage(id);
toggleCMChatPage(id);
}
int toId = currentID; int toId = currentID;

View File

@ -407,9 +407,7 @@ class ServerModel with ChangeNotifier {
if (client.hasUnreadChatMessage.value) { if (client.hasUnreadChatMessage.value) {
client.hasUnreadChatMessage.value = false; client.hasUnreadChatMessage.value = false;
final chatModel = parent.target!.chatModel; final chatModel = parent.target!.chatModel;
if (!chatModel.isShowChatPage) { chatModel.showChatPage(client.id);
chatModel.toggleCMChatPage(client.id);
}
} }
}, },
page: desktop.buildConnectionCard(client))); page: desktop.buildConnectionCard(client)));

View File

@ -60,7 +60,7 @@ dependencies:
window_manager: window_manager:
git: git:
url: https://github.com/Kingtous/rustdesk_window_manager url: https://github.com/Kingtous/rustdesk_window_manager
ref: 88487257cbafc501599ab4f82ec343b46acec020 ref: d1e4b40f4a1ffeb8630696be6883dd31bf307998
desktop_multi_window: desktop_multi_window:
git: git:
url: https://github.com/Kingtous/rustdesk_desktop_multi_window url: https://github.com/Kingtous/rustdesk_desktop_multi_window