From 769e46d3e6fa978d061405de29d73612f27fc177 Mon Sep 17 00:00:00 2001 From: 21pages Date: Wed, 5 Jul 2023 15:51:33 +0800 Subject: [PATCH 1/3] fix cm window_on_top when behind other window Signed-off-by: 21pages --- flutter/lib/common.dart | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/flutter/lib/common.dart b/flutter/lib/common.dart index 41fa826b8..d40a4e899 100644 --- a/flutter/lib/common.dart +++ b/flutter/lib/common.dart @@ -545,16 +545,25 @@ closeConnection({String? id}) { } } -void window_on_top(int? id) { +void window_on_top(int? id) async { if (!isDesktop) { return; } if (id == null) { print("Bring window on top"); // main window - windowManager.restore(); - windowManager.show(); - windowManager.focus(); + if (desktopType == DesktopType.cm && + !(await windowManager.isMinimized() || + !await windowManager.isVisible())) { + await windowManager.setAlwaysOnTop(true); + Future.delayed(Duration(microseconds: 500), () async { + windowManager.setAlwaysOnTop(false); + }); + } else { + windowManager.restore(); + windowManager.show(); + windowManager.focus(); + } rustDeskWinManager.registerActiveWindow(kWindowMainId); } else { WindowController.fromWindowId(id) From 7c4c69aa75fd63a3fb176dc808bc0ae04396cc9f Mon Sep 17 00:00:00 2001 From: 21pages Date: Wed, 5 Jul 2023 17:01:33 +0800 Subject: [PATCH 2/3] cm unread message count Signed-off-by: 21pages --- flutter/lib/desktop/pages/server_page.dart | 18 ++++++++++++++++-- flutter/lib/models/chat_model.dart | 2 +- flutter/lib/models/server_model.dart | 6 +++--- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/flutter/lib/desktop/pages/server_page.dart b/flutter/lib/desktop/pages/server_page.dart index 3ea735d25..62333456e 100644 --- a/flutter/lib/desktop/pages/server_page.dart +++ b/flutter/lib/desktop/pages/server_page.dart @@ -160,8 +160,22 @@ class ConnectionManagerState extends State { child: label), Obx(() => Offstage( offstage: - !(client?.hasUnreadChatMessage.value ?? false), - child: Icon(Icons.circle, color: Colors.red, size: 10))) + !((client?.unreadChatMessageCount.value ?? 0) > 0), + child: Container( + width: 16, + height: 16, + decoration: BoxDecoration( + color: Colors.red, + shape: BoxShape.circle, + ), + child: Center( + child: Text( + "${client?.unreadChatMessageCount.value ?? 0}", + maxLines: 1, + style: TextStyle( + color: Colors.white, fontSize: 10)), + ), + ).marginOnly(left: 4))) ], ); }, diff --git a/flutter/lib/models/chat_model.dart b/flutter/lib/models/chat_model.dart index 8c1e0a9a4..81a240cba 100644 --- a/flutter/lib/models/chat_model.dart +++ b/flutter/lib/models/chat_model.dart @@ -318,7 +318,7 @@ class ChatModel with ChangeNotifier { final currentSelectedTab = session.serverModel.tabController.state.value.selectedTabInfo; if (currentSelectedTab.key != id.toString() && inputNode.hasFocus) { - client.hasUnreadChatMessage.value = true; + client.unreadChatMessageCount.value += 1; } else { parent.target?.serverModel.jumpTo(id); toId = id; diff --git a/flutter/lib/models/server_model.dart b/flutter/lib/models/server_model.dart index 9a6b52e7e..cd0f52f39 100644 --- a/flutter/lib/models/server_model.dart +++ b/flutter/lib/models/server_model.dart @@ -463,8 +463,8 @@ class ServerModel with ChangeNotifier { label: client.name, closable: false, onTap: () { - if (client.hasUnreadChatMessage.value) { - client.hasUnreadChatMessage.value = false; + if (client.unreadChatMessageCount.value > 0) { + client.unreadChatMessageCount.value = 0; final chatModel = parent.target!.chatModel; chatModel.showChatPage(client.id); } @@ -643,7 +643,7 @@ class Client { bool inVoiceCall = false; bool incomingVoiceCall = false; - RxBool hasUnreadChatMessage = false.obs; + RxInt unreadChatMessageCount = 0.obs; Client(this.id, this.authorized, this.isFileTransfer, this.name, this.peerId, this.keyboard, this.clipboard, this.audio); From 87e06e974e1df1517f5066558026aaea804a1e1f Mon Sep 17 00:00:00 2001 From: 21pages Date: Wed, 5 Jul 2023 17:35:37 +0800 Subject: [PATCH 3/3] desktop block remote click chat page Signed-off-by: 21pages --- flutter/lib/common.dart | 30 ++++++++++++++ flutter/lib/desktop/pages/server_page.dart | 4 +- .../lib/desktop/widgets/tabbar_widget.dart | 41 +++++-------------- 3 files changed, 43 insertions(+), 32 deletions(-) diff --git a/flutter/lib/common.dart b/flutter/lib/common.dart index d40a4e899..38085ae8c 100644 --- a/flutter/lib/common.dart +++ b/flutter/lib/common.dart @@ -2110,3 +2110,33 @@ Future start_service(bool is_start) async { bind.mainSetOption(key: "stop-service", value: is_start ? "" : "Y"); } } + +typedef Future WhetherUseRemoteBlock(); +Widget buildRemoteBlock({required Widget child, WhetherUseRemoteBlock? use}) { + var block = false.obs; + return Obx(() => MouseRegion( + onEnter: (_) async { + if (use != null && !await use()) { + block.value = false; + return; + } + var time0 = DateTime.now().millisecondsSinceEpoch; + await bind.mainCheckMouseTime(); + Timer(const Duration(milliseconds: 120), () async { + var d = time0 - await bind.mainGetMouseTime(); + if (d < 120) { + block.value = true; + } + }); + }, + onExit: (event) => block.value = false, + child: Stack(children: [ + child, + Offstage( + offstage: !block.value, + child: Container( + color: Colors.black.withOpacity(0.5), + )), + ]), + )); +} diff --git a/flutter/lib/desktop/pages/server_page.dart b/flutter/lib/desktop/pages/server_page.dart index 62333456e..e996de2db 100644 --- a/flutter/lib/desktop/pages/server_page.dart +++ b/flutter/lib/desktop/pages/server_page.dart @@ -184,7 +184,9 @@ class ConnectionManagerState extends State { Consumer( builder: (_, model, child) => model.isShowCMChatPage ? Expanded( - child: ChatPage(), + child: buildRemoteBlock( + child: ChatPage(), + ), flex: (kConnectionManagerWindowSizeOpenChat.width - kConnectionManagerWindowSizeClosedChat .width) diff --git a/flutter/lib/desktop/widgets/tabbar_widget.dart b/flutter/lib/desktop/widgets/tabbar_widget.dart index ab36728cd..975398c94 100644 --- a/flutter/lib/desktop/widgets/tabbar_widget.dart +++ b/flutter/lib/desktop/widgets/tabbar_widget.dart @@ -295,37 +295,16 @@ class DesktopTab extends StatelessWidget { if (tabType != DesktopTabType.main) { return child; } - var block = false.obs; - return Obx(() => MouseRegion( - onEnter: (_) async { - var access_mode = await bind.mainGetOption(key: 'access-mode'); - var option = option2bool( - 'allow-remote-config-modification', - await bind.mainGetOption( - key: 'allow-remote-config-modification')); - if (access_mode == 'view' || (access_mode.isEmpty && !option)) { - var time0 = DateTime.now().millisecondsSinceEpoch; - await bind.mainCheckMouseTime(); - Timer(const Duration(milliseconds: 120), () async { - var d = time0 - await bind.mainGetMouseTime(); - if (d < 120) { - block.value = true; - } - }); - } - }, - onExit: (_) => block.value = false, - child: Stack( - children: [ - child, - Offstage( - offstage: !block.value, - child: Container( - color: Colors.black.withOpacity(0.5), - )), - ], - ), - )); + return buildRemoteBlock( + child: child, + use: () async { + var access_mode = await bind.mainGetOption(key: 'access-mode'); + var option = option2bool( + 'allow-remote-config-modification', + await bind.mainGetOption( + key: 'allow-remote-config-modification')); + return access_mode == 'view' || (access_mode.isEmpty && !option); + }); } List _tabWidgets = [];