Merge pull request #4878 from 21pages/fix_chat

Fix chat
This commit is contained in:
RustDesk 2023-07-05 22:26:48 +08:00 committed by GitHub
commit 3dfe8b27e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 76 additions and 42 deletions

View File

@ -545,16 +545,25 @@ closeConnection({String? id}) {
} }
} }
void window_on_top(int? id) { void window_on_top(int? id) async {
if (!isDesktop) { if (!isDesktop) {
return; return;
} }
if (id == null) { if (id == null) {
print("Bring window on top"); print("Bring window on top");
// main window // main window
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.restore();
windowManager.show(); windowManager.show();
windowManager.focus(); windowManager.focus();
}
rustDeskWinManager.registerActiveWindow(kWindowMainId); rustDeskWinManager.registerActiveWindow(kWindowMainId);
} else { } else {
WindowController.fromWindowId(id) WindowController.fromWindowId(id)
@ -2101,3 +2110,33 @@ Future<void> start_service(bool is_start) async {
bind.mainSetOption(key: "stop-service", value: is_start ? "" : "Y"); bind.mainSetOption(key: "stop-service", value: is_start ? "" : "Y");
} }
} }
typedef Future<bool> 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),
)),
]),
));
}

View File

@ -160,8 +160,22 @@ class ConnectionManagerState extends State<ConnectionManager> {
child: label), child: label),
Obx(() => Offstage( Obx(() => Offstage(
offstage: offstage:
!(client?.hasUnreadChatMessage.value ?? false), !((client?.unreadChatMessageCount.value ?? 0) > 0),
child: Icon(Icons.circle, color: Colors.red, size: 10))) 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)))
], ],
); );
}, },
@ -170,7 +184,9 @@ class ConnectionManagerState extends State<ConnectionManager> {
Consumer<ChatModel>( Consumer<ChatModel>(
builder: (_, model, child) => model.isShowCMChatPage builder: (_, model, child) => model.isShowCMChatPage
? Expanded( ? Expanded(
child: buildRemoteBlock(
child: ChatPage(), child: ChatPage(),
),
flex: (kConnectionManagerWindowSizeOpenChat.width - flex: (kConnectionManagerWindowSizeOpenChat.width -
kConnectionManagerWindowSizeClosedChat kConnectionManagerWindowSizeClosedChat
.width) .width)

View File

@ -295,38 +295,17 @@ class DesktopTab extends StatelessWidget {
if (tabType != DesktopTabType.main) { if (tabType != DesktopTabType.main) {
return child; return child;
} }
var block = false.obs; return buildRemoteBlock(
return Obx(() => MouseRegion( child: child,
onEnter: (_) async { use: () async {
var access_mode = await bind.mainGetOption(key: 'access-mode'); var access_mode = await bind.mainGetOption(key: 'access-mode');
var option = option2bool( var option = option2bool(
'allow-remote-config-modification', 'allow-remote-config-modification',
await bind.mainGetOption( await bind.mainGetOption(
key: 'allow-remote-config-modification')); key: 'allow-remote-config-modification'));
if (access_mode == 'view' || (access_mode.isEmpty && !option)) { return 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),
)),
],
),
));
}
List<Widget> _tabWidgets = []; List<Widget> _tabWidgets = [];
Widget _buildPageView() { Widget _buildPageView() {

View File

@ -318,7 +318,7 @@ class ChatModel with ChangeNotifier {
final currentSelectedTab = final currentSelectedTab =
session.serverModel.tabController.state.value.selectedTabInfo; session.serverModel.tabController.state.value.selectedTabInfo;
if (currentSelectedTab.key != id.toString() && inputNode.hasFocus) { if (currentSelectedTab.key != id.toString() && inputNode.hasFocus) {
client.hasUnreadChatMessage.value = true; client.unreadChatMessageCount.value += 1;
} else { } else {
parent.target?.serverModel.jumpTo(id); parent.target?.serverModel.jumpTo(id);
toId = id; toId = id;

View File

@ -463,8 +463,8 @@ class ServerModel with ChangeNotifier {
label: client.name, label: client.name,
closable: false, closable: false,
onTap: () { onTap: () {
if (client.hasUnreadChatMessage.value) { if (client.unreadChatMessageCount.value > 0) {
client.hasUnreadChatMessage.value = false; client.unreadChatMessageCount.value = 0;
final chatModel = parent.target!.chatModel; final chatModel = parent.target!.chatModel;
chatModel.showChatPage(client.id); chatModel.showChatPage(client.id);
} }
@ -643,7 +643,7 @@ class Client {
bool inVoiceCall = false; bool inVoiceCall = false;
bool incomingVoiceCall = false; bool incomingVoiceCall = false;
RxBool hasUnreadChatMessage = false.obs; RxInt unreadChatMessageCount = 0.obs;
Client(this.id, this.authorized, this.isFileTransfer, this.name, this.peerId, Client(this.id, this.authorized, this.isFileTransfer, this.name, this.peerId,
this.keyboard, this.clipboard, this.audio); this.keyboard, this.clipboard, this.audio);