Skip to content

Commit

Permalink
fix: web chat (rustdesk#9588)
Browse files Browse the repository at this point in the history
* fix: web chat

Signed-off-by: fufesou <[email protected]>

* add missing svg

Signed-off-by: fufesou <[email protected]>

---------

Signed-off-by: fufesou <[email protected]>
  • Loading branch information
fufesou authored Oct 8, 2024
1 parent 9bcd0d1 commit 2591d4f
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 27 deletions.
1 change: 1 addition & 0 deletions flutter/assets/message_24dp_5F6368.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
59 changes: 37 additions & 22 deletions flutter/lib/desktop/widgets/remote_toolbar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -479,8 +479,8 @@ class _RemoteToolbarState extends State<RemoteToolbar> {
setFullscreen: _setFullscreen,
));
toolbarItems.add(_KeyboardMenu(id: widget.id, ffi: widget.ffi));
toolbarItems.add(_ChatMenu(id: widget.id, ffi: widget.ffi));
if (!isWeb) {
toolbarItems.add(_ChatMenu(id: widget.id, ffi: widget.ffi));
toolbarItems.add(_VoiceCallMenu(id: widget.id, ffi: widget.ffi));
}
if (!isWeb) toolbarItems.add(_RecordMenu());
Expand Down Expand Up @@ -1781,34 +1781,49 @@ class _ChatMenuState extends State<_ChatMenu> {

@override
Widget build(BuildContext context) {
return _IconSubmenuButton(
tooltip: 'Chat',
key: chatButtonKey,
svg: 'assets/chat.svg',
ffi: widget.ffi,
color: _ToolbarTheme.blueColor,
hoverColor: _ToolbarTheme.hoverBlueColor,
menuChildrenGetter: () => [textChat(), voiceCall()]);
if (isWeb) {
return buildTextChatButton();
} else {
return _IconSubmenuButton(
tooltip: 'Chat',
key: chatButtonKey,
svg: 'assets/chat.svg',
ffi: widget.ffi,
color: _ToolbarTheme.blueColor,
hoverColor: _ToolbarTheme.hoverBlueColor,
menuChildrenGetter: () => [textChat(), voiceCall()]);
}
}

buildTextChatButton() {
return _IconMenuButton(
assetName: 'assets/message_24dp_5F6368.svg',
tooltip: 'Text chat',
key: chatButtonKey,
onPressed: _textChatOnPressed,
color: _ToolbarTheme.blueColor,
hoverColor: _ToolbarTheme.hoverBlueColor,
);
}

textChat() {
return MenuButton(
child: Text(translate('Text chat')),
ffi: widget.ffi,
onPressed: () {
RenderBox? renderBox =
chatButtonKey.currentContext?.findRenderObject() as RenderBox?;

Offset? initPos;
if (renderBox != null) {
final pos = renderBox.localToGlobal(Offset.zero);
initPos = Offset(pos.dx, pos.dy + _ToolbarTheme.dividerHeight);
}
onPressed: _textChatOnPressed);
}

widget.ffi.chatModel.changeCurrentKey(
MessageKey(widget.ffi.id, ChatModel.clientModeID));
widget.ffi.chatModel.toggleChatOverlay(chatInitPos: initPos);
});
_textChatOnPressed() {
RenderBox? renderBox =
chatButtonKey.currentContext?.findRenderObject() as RenderBox?;
Offset? initPos;
if (renderBox != null) {
final pos = renderBox.localToGlobal(Offset.zero);
initPos = Offset(pos.dx, pos.dy + _ToolbarTheme.dividerHeight);
}
widget.ffi.chatModel
.changeCurrentKey(MessageKey(widget.ffi.id, ChatModel.clientModeID));
widget.ffi.chatModel.toggleChatOverlay(chatInitPos: initPos);
}

voiceCall() {
Expand Down
7 changes: 4 additions & 3 deletions flutter/lib/models/chat_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -235,13 +235,14 @@ class ChatModel with ChangeNotifier {
}
}

_isChatOverlayHide() => ((!isDesktop && chatIconOverlayEntry == null) ||
chatWindowOverlayEntry == null);
_isChatOverlayHide() =>
((!(isDesktop || isWebDesktop) && chatIconOverlayEntry == null) ||
chatWindowOverlayEntry == null);

toggleChatOverlay({Offset? chatInitPos}) {
if (_isChatOverlayHide()) {
gFFI.invokeMethod("enable_soft_keyboard", true);
if (!isDesktop) {
if (!(isDesktop || isWebDesktop)) {
showChatIconOverlay();
}
showChatWindowOverlay(chatInitPos: chatInitPos);
Expand Down
6 changes: 4 additions & 2 deletions flutter/lib/web/bridge.dart
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,8 @@ class RustdeskImpl {

Future<void> sessionSendChat(
{required UuidValue sessionId, required String text, dynamic hint}) {
throw UnimplementedError();
return Future(
() => js.context.callMethod('setByName', ['send_chat', text]));
}

Future<void> sessionPeerOption(
Expand Down Expand Up @@ -1188,7 +1189,8 @@ class RustdeskImpl {

Future<void> sessionSendNote(
{required UuidValue sessionId, required String note, dynamic hint}) {
return Future(() => js.context.callMethod('setByName', ['send_note', note]));
return Future(
() => js.context.callMethod('setByName', ['send_note', note]));
}

Future<String> sessionAlternativeCodecs(
Expand Down

0 comments on commit 2591d4f

Please sign in to comment.