mirror of
https://github.com/rustdesk/rustdesk.git
synced 2025-12-12 19:17:58 +00:00
Merge pull request #1181 from Heap-Hop/flutter_desktop_merge_master_mobile
Flutter desktop merge master mobile
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:dash_chat/dash_chat.dart';
|
||||
import 'package:dash_chat_2/dash_chat_2.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../mobile/widgets/overlay.dart';
|
||||
@@ -11,8 +11,8 @@ class MessageBody {
|
||||
List<ChatMessage> chatMessages;
|
||||
MessageBody(this.chatUser, this.chatMessages);
|
||||
|
||||
void add(ChatMessage cm) {
|
||||
this.chatMessages.add(cm);
|
||||
void insert(ChatMessage cm) {
|
||||
this.chatMessages.insert(0, cm);
|
||||
}
|
||||
|
||||
void clear() {
|
||||
@@ -24,19 +24,15 @@ class ChatModel with ChangeNotifier {
|
||||
static final clientModeID = -1;
|
||||
|
||||
final ChatUser me = ChatUser(
|
||||
uid: "",
|
||||
name: "Me",
|
||||
id: "",
|
||||
firstName: "Me",
|
||||
);
|
||||
|
||||
late final Map<int, MessageBody> _messages = Map()
|
||||
..[clientModeID] = MessageBody(me, []);
|
||||
|
||||
final _scroller = ScrollController();
|
||||
|
||||
var _currentID = clientModeID;
|
||||
|
||||
ScrollController get scroller => _scroller;
|
||||
|
||||
Map<int, MessageBody> get messages => _messages;
|
||||
|
||||
int get currentID => _currentID;
|
||||
@@ -67,8 +63,8 @@ class ChatModel with ChangeNotifier {
|
||||
"Failed to changeCurrentID,remote user doesn't exist");
|
||||
}
|
||||
final chatUser = ChatUser(
|
||||
uid: client.peerId,
|
||||
name: client.name,
|
||||
id: client.peerId,
|
||||
firstName: client.name,
|
||||
);
|
||||
_messages[id] = MessageBody(chatUser, []);
|
||||
_currentID = id;
|
||||
@@ -85,48 +81,39 @@ class ChatModel with ChangeNotifier {
|
||||
late final chatUser;
|
||||
if (id == clientModeID) {
|
||||
chatUser = ChatUser(
|
||||
name: _ffi.target?.ffiModel.pi.username,
|
||||
uid: _ffi.target?.getId(),
|
||||
firstName: _ffi.target?.ffiModel.pi.username,
|
||||
id: _ffi.target?.getId() ?? "",
|
||||
);
|
||||
} else {
|
||||
final client = _ffi.target?.serverModel.clients[id];
|
||||
if (client == null) {
|
||||
return debugPrint("Failed to receive msg,user doesn't exist");
|
||||
}
|
||||
chatUser = ChatUser(uid: client.peerId, name: client.name);
|
||||
chatUser = ChatUser(id: client.peerId, firstName: client.name);
|
||||
}
|
||||
|
||||
if (!_messages.containsKey(id)) {
|
||||
_messages[id] = MessageBody(chatUser, []);
|
||||
}
|
||||
_messages[id]!.add(ChatMessage(text: text, user: chatUser));
|
||||
_messages[id]!.insert(
|
||||
ChatMessage(text: text, user: chatUser, createdAt: DateTime.now()));
|
||||
_currentID = id;
|
||||
notifyListeners();
|
||||
scrollToBottom();
|
||||
}
|
||||
|
||||
scrollToBottom() {
|
||||
Future.delayed(Duration(milliseconds: 500), () {
|
||||
_scroller.animateTo(_scroller.position.maxScrollExtent,
|
||||
duration: Duration(milliseconds: 200),
|
||||
curve: Curves.fastLinearToSlowEaseIn);
|
||||
});
|
||||
}
|
||||
|
||||
send(ChatMessage message) {
|
||||
if (message.text != null && message.text!.isNotEmpty) {
|
||||
_messages[_currentID]?.add(message);
|
||||
if (message.text.isNotEmpty) {
|
||||
_messages[_currentID]?.insert(message);
|
||||
if (_currentID == clientModeID) {
|
||||
_ffi.target?.setByName("chat_client_mode", message.text!);
|
||||
_ffi.target?.setByName("chat_client_mode", message.text);
|
||||
} else {
|
||||
final msg = Map()
|
||||
..["id"] = _currentID
|
||||
..["text"] = message.text!;
|
||||
..["text"] = message.text;
|
||||
_ffi.target?.setByName("chat_server_mode", jsonEncode(msg));
|
||||
}
|
||||
}
|
||||
notifyListeners();
|
||||
scrollToBottom();
|
||||
}
|
||||
|
||||
close() {
|
||||
|
||||
@@ -323,6 +323,7 @@ class FileModel extends ChangeNotifier {
|
||||
|
||||
onClose() {
|
||||
SmartDialog.dismiss();
|
||||
jobReset();
|
||||
|
||||
// save config
|
||||
Map<String, String> msgMap = Map();
|
||||
|
||||
@@ -73,7 +73,7 @@ class FfiModel with ChangeNotifier {
|
||||
|
||||
void updatePermission(Map<String, dynamic> evt) {
|
||||
evt.forEach((k, v) {
|
||||
if (k == 'name') return;
|
||||
if (k == 'name' || k.isEmpty) return;
|
||||
_permissions[k] = v == 'true';
|
||||
});
|
||||
print('$_permissions');
|
||||
@@ -224,6 +224,8 @@ class FfiModel with ChangeNotifier {
|
||||
parent.target?.serverModel.onClientAuthorized(evt);
|
||||
} else if (name == 'on_client_remove') {
|
||||
parent.target?.serverModel.onClientRemove(evt);
|
||||
} else if (name == 'update_quality_status') {
|
||||
parent.target?.qualityMonitorModel.updateQualityStatus(evt);
|
||||
}
|
||||
};
|
||||
platformFFI.setEventCallback(cb);
|
||||
@@ -256,6 +258,8 @@ class FfiModel with ChangeNotifier {
|
||||
wrongPasswordDialog(id);
|
||||
} else if (type == 'input-password') {
|
||||
enterPasswordDialog(id);
|
||||
} else if (type == 'restarting') {
|
||||
showMsgBox(id, type, title, text, false, hasCancel: false);
|
||||
} else {
|
||||
var hasRetry = evt['hasRetry'] == 'true';
|
||||
showMsgBox(id, type, title, text, hasRetry);
|
||||
@@ -264,8 +268,9 @@ class FfiModel with ChangeNotifier {
|
||||
|
||||
/// Show a message box with [type], [title] and [text].
|
||||
void showMsgBox(
|
||||
String id, String type, String title, String text, bool hasRetry) {
|
||||
msgBox(type, title, text);
|
||||
String id, String type, String title, String text, bool hasRetry,
|
||||
{bool? hasCancel}) {
|
||||
msgBox(type, title, text, hasCancel: hasCancel);
|
||||
_timer?.cancel();
|
||||
if (hasRetry) {
|
||||
_timer = Timer(Duration(seconds: _reconnects), () {
|
||||
@@ -784,6 +789,47 @@ class CursorModel with ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
class QualityMonitorData {
|
||||
String? speed;
|
||||
String? fps;
|
||||
String? delay;
|
||||
String? targetBitrate;
|
||||
String? codecFormat;
|
||||
}
|
||||
|
||||
class QualityMonitorModel with ChangeNotifier {
|
||||
WeakReference<FFI> parent;
|
||||
|
||||
QualityMonitorModel(this.parent);
|
||||
var _show = false;
|
||||
final _data = QualityMonitorData();
|
||||
|
||||
bool get show => _show;
|
||||
QualityMonitorData get data => _data;
|
||||
|
||||
checkShowQualityMonitor() {
|
||||
final show =
|
||||
gFFI.getByName('toggle_option', 'show-quality-monitor') == 'true';
|
||||
if (_show != show) {
|
||||
_show = show;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
updateQualityStatus(Map<String, dynamic> evt) {
|
||||
try {
|
||||
if ((evt["speed"] as String).isNotEmpty) _data.speed = evt["speed"];
|
||||
if ((evt["fps"] as String).isNotEmpty) _data.fps = evt["fps"];
|
||||
if ((evt["delay"] as String).isNotEmpty) _data.delay = evt["delay"];
|
||||
if ((evt["target_bitrate"] as String).isNotEmpty)
|
||||
_data.targetBitrate = evt["target_bitrate"];
|
||||
if ((evt["codec_format"] as String).isNotEmpty)
|
||||
_data.codecFormat = evt["codec_format"];
|
||||
notifyListeners();
|
||||
} catch (e) {}
|
||||
}
|
||||
}
|
||||
|
||||
/// Mouse button enum.
|
||||
enum MouseButtons { left, right, wheel }
|
||||
|
||||
@@ -817,6 +863,7 @@ class FFI {
|
||||
late final FileModel fileModel;
|
||||
late final AbModel abModel;
|
||||
late final UserModel userModel;
|
||||
late final QualityMonitorModel qualityMonitorModel;
|
||||
|
||||
FFI() {
|
||||
this.imageModel = ImageModel(WeakReference(this));
|
||||
@@ -828,6 +875,7 @@ class FFI {
|
||||
this.fileModel = FileModel(WeakReference(this));
|
||||
this.abModel = AbModel(WeakReference(this));
|
||||
this.userModel = UserModel(WeakReference(this));
|
||||
this.qualityMonitorModel = QualityMonitorModel(WeakReference(this));
|
||||
}
|
||||
|
||||
/// Get the remote id for current client.
|
||||
|
||||
Reference in New Issue
Block a user