diff --git a/flutter/lib/common/widgets/chat_page.dart b/flutter/lib/common/widgets/chat_page.dart index 3b4e06a6f..510ce1f73 100644 --- a/flutter/lib/common/widgets/chat_page.dart +++ b/flutter/lib/common/widgets/chat_page.dart @@ -54,6 +54,7 @@ class ChatPage extends StatelessWidget implements PageShape { return DashChat( onSend: (chatMsg) { chatModel.send(chatMsg); + chatModel.inputNode.requestFocus(); }, currentUser: chatModel.me, messages: chatModel diff --git a/flutter/lib/desktop/pages/server_page.dart b/flutter/lib/desktop/pages/server_page.dart index d04f7871f..884ac6441 100644 --- a/flutter/lib/desktop/pages/server_page.dart +++ b/flutter/lib/desktop/pages/server_page.dart @@ -101,6 +101,7 @@ class ConnectionManagerState extends State { gFFI.serverModel.updateClientState(); gFFI.serverModel.tabController.onSelected = (index, _) => gFFI.chatModel.changeCurrentID(gFFI.serverModel.clients[index].id); + gFFI.chatModel.isConnManager = true; super.initState(); } @@ -159,7 +160,7 @@ class ConnectionManagerState extends State { pageViewBuilder: (pageView) => Row(children: [ Expanded(child: pageView), Consumer( - builder: (_, model, child) => model.isShowChatPage + builder: (_, model, child) => model.isShowCMChatPage ? Expanded(child: Scaffold(body: ChatPage())) : Offstage()) ]))); diff --git a/flutter/lib/main.dart b/flutter/lib/main.dart index 3621a3bf8..afc98a1e1 100644 --- a/flutter/lib/main.dart +++ b/flutter/lib/main.dart @@ -160,15 +160,10 @@ void runConnectionManagerScreen() async { ); windowManager.waitUntilReadyToShow(windowOptions, () async { await windowManager.show(); + await Future.wait([windowManager.focus(), windowManager.setOpacity(1)]); // ensure initial window size to be changed - await windowManager.setSize(kConnectionManagerWindowSize); - await Future.wait([ - windowManager.setAlignment(Alignment.topRight), - windowManager.focus(), - windowManager.setOpacity(1) - ]); - // ensure - windowManager.setAlignment(Alignment.topRight); + await windowManager.setSizeAlignment( + kConnectionManagerWindowSize, Alignment.topRight); }); } diff --git a/flutter/lib/models/chat_model.dart b/flutter/lib/models/chat_model.dart index 9aa1a23ce..bc6582617 100644 --- a/flutter/lib/models/chat_model.dart +++ b/flutter/lib/models/chat_model.dart @@ -32,6 +32,7 @@ class ChatModel with ChangeNotifier { OverlayState? _overlayState; OverlayEntry? chatIconOverlayEntry; OverlayEntry? chatWindowOverlayEntry; + bool isConnManager = false; final ChatUser me = ChatUser( id: "", @@ -42,13 +43,13 @@ class ChatModel with ChangeNotifier { MessageBody(me, []); var _currentID = clientModeID; - late bool _isShowChatPage = false; + late bool _isShowCMChatPage = false; Map get messages => _messages; int get currentID => _currentID; - bool get isShowChatPage => _isShowChatPage; + bool get isShowCMChatPage => _isShowCMChatPage; final WeakReference parent; @@ -147,9 +148,11 @@ class ChatModel with ChangeNotifier { } } + _isChatOverlayHide() => ((!isDesktop && chatIconOverlayEntry == null) || + chatWindowOverlayEntry == null); + toggleChatOverlay() { - if ((!isDesktop && chatIconOverlayEntry == null) || - chatWindowOverlayEntry == null) { + if (_isChatOverlayHide()) { gFFI.invokeMethod("enable_soft_keyboard", true); if (!isDesktop) { 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 { if (gFFI.chatModel.currentID != id) { gFFI.chatModel.changeCurrentID(id); } - if (_isShowChatPage) { - _isShowChatPage = !_isShowChatPage; + if (_isShowCMChatPage) { + _isShowCMChatPage = !_isShowCMChatPage; notifyListeners(); - await windowManager.setSize(Size(300, 400)); - await windowManager.setAlignment(Alignment.topRight); + await windowManager.setSizeAlignment(Size(300, 400), Alignment.topRight); } else { - await windowManager.setSize(Size(600, 400)); - await Future.delayed(Duration(milliseconds: 100)); - await windowManager.setAlignment(Alignment.topRight); - _isShowChatPage = !_isShowChatPage; + await windowManager.setSizeAlignment(Size(600, 400), Alignment.topRight); + _isShowCMChatPage = !_isShowCMChatPage; notifyListeners(); } } @@ -208,13 +220,11 @@ class ChatModel with ChangeNotifier { } if (text.isEmpty) return; // mobile: first message show overlay icon - if (chatIconOverlayEntry == null) { + if (!isDesktop && chatIconOverlayEntry == null) { showChatIconOverlay(); } - // desktop: show chat page - if (!_isShowChatPage) { - toggleCMChatPage(id); - } + // show chat page + await showChatPage(id); int toId = currentID; diff --git a/flutter/lib/models/server_model.dart b/flutter/lib/models/server_model.dart index 6671ec669..d407ca51b 100644 --- a/flutter/lib/models/server_model.dart +++ b/flutter/lib/models/server_model.dart @@ -407,9 +407,7 @@ class ServerModel with ChangeNotifier { if (client.hasUnreadChatMessage.value) { client.hasUnreadChatMessage.value = false; final chatModel = parent.target!.chatModel; - if (!chatModel.isShowChatPage) { - chatModel.toggleCMChatPage(client.id); - } + chatModel.showChatPage(client.id); } }, page: desktop.buildConnectionCard(client))); diff --git a/flutter/pubspec.yaml b/flutter/pubspec.yaml index 7dfb53538..3cbb1fc21 100644 --- a/flutter/pubspec.yaml +++ b/flutter/pubspec.yaml @@ -60,7 +60,7 @@ dependencies: window_manager: git: url: https://github.com/Kingtous/rustdesk_window_manager - ref: 88487257cbafc501599ab4f82ec343b46acec020 + ref: d1e4b40f4a1ffeb8630696be6883dd31bf307998 desktop_multi_window: git: url: https://github.com/Kingtous/rustdesk_desktop_multi_window