mirror of
https://github.com/rustdesk/rustdesk.git
synced 2025-12-12 02:57:22 +00:00
Merge pull request #5386 from dignow/refact/tab_2_window_flutter_data
Refact/tab 2 window flutter data
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:texture_rgba_renderer/texture_rgba_renderer.dart';
|
||||
|
||||
@@ -21,7 +20,6 @@ class RenderTexture {
|
||||
_sessionId = sessionId;
|
||||
|
||||
textureRenderer.createTexture(_textureKey).then((id) async {
|
||||
debugPrint("id: $id, texture_key: $_textureKey");
|
||||
if (id != -1) {
|
||||
final ptr = await textureRenderer.getTexturePtr(_textureKey);
|
||||
platformFFI.registerTexture(sessionId, ptr);
|
||||
|
||||
@@ -4,6 +4,7 @@ import 'dart:io';
|
||||
import 'dart:math';
|
||||
import 'dart:ui' as ui;
|
||||
|
||||
import 'package:desktop_multi_window/desktop_multi_window.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_hbb/consts.dart';
|
||||
@@ -41,7 +42,50 @@ final _waitForImageDialogShow = <UuidValue, bool>{};
|
||||
final _waitForFirstImage = <UuidValue, bool>{};
|
||||
final _constSessionId = Uuid().v4obj();
|
||||
|
||||
class CachedPeerData {
|
||||
Map<String, dynamic> updatePrivacyMode = {};
|
||||
Map<String, dynamic> peerInfo = {};
|
||||
List<Map<String, dynamic>> cursorDataList = [];
|
||||
Map<String, dynamic> lastCursorId = {};
|
||||
bool secure = false;
|
||||
bool direct = false;
|
||||
|
||||
CachedPeerData();
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return jsonEncode({
|
||||
'updatePrivacyMode': updatePrivacyMode,
|
||||
'peerInfo': peerInfo,
|
||||
'cursorDataList': cursorDataList,
|
||||
'lastCursorId': lastCursorId,
|
||||
'secure': secure,
|
||||
'direct': direct,
|
||||
});
|
||||
}
|
||||
|
||||
static CachedPeerData? fromString(String s) {
|
||||
try {
|
||||
final map = jsonDecode(s);
|
||||
final data = CachedPeerData();
|
||||
data.updatePrivacyMode = map['updatePrivacyMode'];
|
||||
data.peerInfo = map['peerInfo'];
|
||||
for (final cursorData in map['cursorDataList']) {
|
||||
data.cursorDataList.add(cursorData);
|
||||
}
|
||||
data.lastCursorId = map['lastCursorId'];
|
||||
data.secure = map['secure'];
|
||||
data.direct = map['direct'];
|
||||
return data;
|
||||
} catch (e) {
|
||||
debugPrint('Failed to parse CachedPeerData: $e');
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class FfiModel with ChangeNotifier {
|
||||
CachedPeerData cachedPeerData = CachedPeerData();
|
||||
PeerInfo _pi = PeerInfo();
|
||||
Display _display = Display();
|
||||
|
||||
@@ -117,6 +161,8 @@ class FfiModel with ChangeNotifier {
|
||||
}
|
||||
|
||||
setConnectionType(String peerId, bool secure, bool direct) {
|
||||
cachedPeerData.secure = secure;
|
||||
cachedPeerData.direct = direct;
|
||||
_secure = secure;
|
||||
_direct = direct;
|
||||
try {
|
||||
@@ -143,6 +189,22 @@ class FfiModel with ChangeNotifier {
|
||||
_permissions.clear();
|
||||
}
|
||||
|
||||
handleCachedPeerData(CachedPeerData data, String peerId) async {
|
||||
handleMsgBox({
|
||||
'type': 'success',
|
||||
'title': 'Successful',
|
||||
'text': 'Connected, waiting for image...',
|
||||
'link': '',
|
||||
}, sessionId, peerId);
|
||||
updatePrivacyMode(data.updatePrivacyMode, sessionId, peerId);
|
||||
setConnectionType(peerId, data.secure, data.direct);
|
||||
handlePeerInfo(data.peerInfo, peerId);
|
||||
for (var element in data.cursorDataList) {
|
||||
handleCursorData(element);
|
||||
}
|
||||
handleCursorId(data.lastCursorId);
|
||||
}
|
||||
|
||||
// todo: why called by two position
|
||||
StreamEventHandler startEventListener(SessionID sessionId, String peerId) {
|
||||
return (evt) async {
|
||||
@@ -159,9 +221,9 @@ class FfiModel with ChangeNotifier {
|
||||
} else if (name == 'switch_display') {
|
||||
handleSwitchDisplay(evt, sessionId, peerId);
|
||||
} else if (name == 'cursor_data') {
|
||||
await parent.target?.cursorModel.updateCursorData(evt);
|
||||
await handleCursorData(evt);
|
||||
} else if (name == 'cursor_id') {
|
||||
await parent.target?.cursorModel.updateCursorId(evt);
|
||||
await handleCursorId(evt);
|
||||
} else if (name == 'cursor_position') {
|
||||
await parent.target?.cursorModel.updateCursorPosition(evt, peerId);
|
||||
} else if (name == 'clipboard') {
|
||||
@@ -464,6 +526,8 @@ class FfiModel with ChangeNotifier {
|
||||
|
||||
/// Handle the peer info event based on [evt].
|
||||
handlePeerInfo(Map<String, dynamic> evt, String peerId) async {
|
||||
cachedPeerData.peerInfo = evt;
|
||||
|
||||
// recent peer updated by handle_peer_info(ui_session_interface.rs) --> handle_peer_info(client.rs) --> save_config(client.rs)
|
||||
bind.mainLoadRecentPeers();
|
||||
|
||||
@@ -579,9 +643,20 @@ class FfiModel with ChangeNotifier {
|
||||
return d;
|
||||
}
|
||||
|
||||
handleCursorId(Map<String, dynamic> evt) async {
|
||||
cachedPeerData.lastCursorId = evt;
|
||||
await parent.target?.cursorModel.updateCursorId(evt);
|
||||
}
|
||||
|
||||
handleCursorData(Map<String, dynamic> evt) async {
|
||||
cachedPeerData.cursorDataList.add(evt);
|
||||
await parent.target?.cursorModel.updateCursorData(evt);
|
||||
}
|
||||
|
||||
/// Handle the peer info synchronization event based on [evt].
|
||||
handleSyncPeerInfo(Map<String, dynamic> evt, SessionID sessionId) async {
|
||||
if (evt['displays'] != null) {
|
||||
cachedPeerData.peerInfo['displays'] = evt['displays'];
|
||||
List<dynamic> displays = json.decode(evt['displays']);
|
||||
List<Display> newDisplays = [];
|
||||
for (int i = 0; i < displays.length; ++i) {
|
||||
@@ -1596,7 +1671,6 @@ class FFI {
|
||||
/// dialogManager use late to ensure init after main page binding [globalKey]
|
||||
late final dialogManager = OverlayDialogManager();
|
||||
|
||||
late final bool isSessionAdded;
|
||||
late final SessionID sessionId;
|
||||
late final ImageModel imageModel; // session
|
||||
late final FfiModel ffiModel; // session
|
||||
@@ -1615,7 +1689,6 @@ class FFI {
|
||||
late final ElevationModel elevationModel; // session
|
||||
|
||||
FFI(SessionID? sId) {
|
||||
isSessionAdded = sId != null;
|
||||
sessionId = sId ?? (isDesktop ? Uuid().v4obj() : _constSessionId);
|
||||
imageModel = ImageModel(WeakReference(this));
|
||||
ffiModel = FfiModel(WeakReference(this));
|
||||
@@ -1641,7 +1714,8 @@ class FFI {
|
||||
bool isRdp = false,
|
||||
String? switchUuid,
|
||||
String? password,
|
||||
bool? forceRelay}) {
|
||||
bool? forceRelay,
|
||||
int? tabWindowId}) {
|
||||
closed = false;
|
||||
auditNote = '';
|
||||
assert(!(isFileTransfer && isPortForward), 'more than one connect type');
|
||||
@@ -1656,7 +1730,9 @@ class FFI {
|
||||
imageModel.id = id;
|
||||
cursorModel.id = id;
|
||||
}
|
||||
if (!isSessionAdded) {
|
||||
// If tabWindowId != null, this session is a "tab -> window" one.
|
||||
// Else this session is a new one.
|
||||
if (tabWindowId == null) {
|
||||
// ignore: unused_local_variable
|
||||
final addRes = bind.sessionAddSync(
|
||||
sessionId: sessionId,
|
||||
@@ -1677,8 +1753,25 @@ class FFI {
|
||||
// Preserved for the rgba data.
|
||||
stream.listen((message) {
|
||||
if (closed) return;
|
||||
if (isSessionAdded && !isToNewWindowNotified.value) {
|
||||
bind.sessionReadyToNewWindow(sessionId: sessionId);
|
||||
if (tabWindowId != null && !isToNewWindowNotified.value) {
|
||||
// Session is read to be moved to a new window.
|
||||
// Get the cached data and handle the cached data.
|
||||
Future.delayed(Duration.zero, () async {
|
||||
final cachedData = await DesktopMultiWindow.invokeMethod(
|
||||
tabWindowId, kWindowEventGetCachedSessionData, id);
|
||||
if (cachedData == null) {
|
||||
// unreachable
|
||||
debugPrint('Unreachable, the cached data is empty.');
|
||||
return;
|
||||
}
|
||||
final data = CachedPeerData.fromString(cachedData);
|
||||
if (data == null) {
|
||||
debugPrint('Unreachable, the cached data cannot be decoded.');
|
||||
return;
|
||||
}
|
||||
ffiModel.handleCachedPeerData(data, id);
|
||||
await bind.sessionRefresh(sessionId: sessionId);
|
||||
});
|
||||
isToNewWindowNotified.value = true;
|
||||
}
|
||||
() async {
|
||||
|
||||
Reference in New Issue
Block a user