Merge pull request #5260 from dignow/refact/separate_remote_window

Refact/separate remote window
This commit is contained in:
RustDesk 2023-08-06 11:00:49 +08:00 committed by GitHub
commit 755353dc0b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
41 changed files with 97 additions and 38 deletions

View File

@ -39,6 +39,7 @@ const String kWindowEventActiveSession = "active_session";
const String kWindowEventGetRemoteList = "get_remote_list";
const String kWindowEventGetSessionIdList = "get_session_id_list";
const String kWindowEventSplit = "split";
const String kWindowEventCloseForSeparateWindow = "close_for_separate_window";
const String kOptionSeparateRemoteWindow = "enable-separate-remote-window";

View File

@ -570,6 +570,17 @@ class _DesktopHomePageState extends State<DesktopHomePage>
forceRelay: call.arguments['forceRelay'],
forceSeparateWindow: call.arguments['forceSeparateWindow'],
);
} else if (call.method == kWindowEventSplit) {
final args = call.arguments.split(',');
int? windowId;
try {
windowId = int.parse(args[0]);
} catch (e) {
debugPrint("Failed to parse window id '${call.arguments}': $e");
}
if (windowId != null) {
await rustDeskWinManager.splitWindow(windowId, args[1], args[2]);
}
}
});
_uniLinksSubscription = listenUniLinks();

View File

@ -6,7 +6,6 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_hbb/common.dart';
import 'package:flutter_hbb/consts.dart';
import 'package:flutter_hbb/utils/multi_window_manager.dart';
import 'package:flutter_hbb/desktop/pages/desktop_home_page.dart';
import 'package:flutter_hbb/desktop/pages/desktop_tab_page.dart';
import 'package:flutter_hbb/models/platform_model.dart';
@ -323,13 +322,6 @@ class _GeneralState extends State<_General> {
'Separate remote window',
kOptionSeparateRemoteWindow,
isServer: false,
update: () {
final useSeparateWindow =
mainGetLocalBoolOptionSync(kOptionSeparateRemoteWindow);
if (useSeparateWindow) {
rustDeskWinManager.separateWindows();
}
},
),
];
// though this is related to GUI, but opengl problem affects all users, so put in config rather than local

View File

@ -329,6 +329,22 @@ class _ConnectionTabPageState extends State<ConnectionTabPage> {
));
}
if (tabController.state.value.tabs.length > 1) {
final splitAction = MenuEntryButton<String>(
childBuilder: (TextStyle? style) => Text(
translate('Split'),
style: style,
),
proc: () async {
await DesktopMultiWindow.invokeMethod(
kMainWindowId, kWindowEventSplit, '${windowId()},$key,$sessionId');
cancelFunc();
},
padding: padding,
);
menu.insert(1, splitAction);
}
if (perms['keyboard'] != false && !ffi.ffiModel.viewOnly) {
if (perms['clipboard'] != false) {
menu.add(RemoteMenuEntry.disableClipboard(sessionId, padding,

View File

@ -43,33 +43,22 @@ class RustDeskMultiWindowManager {
final List<int> _fileTransferWindows = List.empty(growable: true);
final List<int> _portForwardWindows = List.empty(growable: true);
separateWindows() async {
for (final windowId in _remoteDesktopWindows.toList()) {
final String sessionIdList = await DesktopMultiWindow.invokeMethod(
windowId, kWindowEventGetSessionIdList, null);
final idList = sessionIdList.split(';');
if (idList.length <= 1) {
continue;
}
for (final idPair in idList.sublist(1)) {
final peerSession = idPair.split(',');
var params = {
'type': WindowType.RemoteDesktop.index,
'id': peerSession[0],
'session_id': peerSession[1],
};
await _newSession(
true,
WindowType.RemoteDesktop,
kWindowEventNewRemoteDesktop,
peerSession[0],
_remoteDesktopWindows,
jsonEncode(params),
);
await DesktopMultiWindow.invokeMethod(
windowId, kWindowEventCloseForSeparateWindow, peerSession[0]);
}
}
splitWindow(int windowId, String peerId, String sessionId) async {
var params = {
'type': WindowType.RemoteDesktop.index,
'id': peerId,
'session_id': sessionId,
};
await _newSession(
true,
WindowType.RemoteDesktop,
kWindowEventNewRemoteDesktop,
peerId,
_remoteDesktopWindows,
jsonEncode(params),
);
await DesktopMultiWindow.invokeMethod(
windowId, kWindowEventCloseForSeparateWindow, peerId);
}
newSessionWindow(
@ -214,7 +203,8 @@ class RustDeskMultiWindowManager {
}
for (final windowId in wnds) {
if (_activeWindows.contains(windowId)) {
return await DesktopMultiWindow.invokeMethod(windowId, methodName, args);
return await DesktopMultiWindow.invokeMethod(
windowId, methodName, args);
}
}
return await DesktopMultiWindow.invokeMethod(wnds[0], methodName, args);
@ -223,7 +213,7 @@ class RustDeskMultiWindowManager {
List<int> _findWindowsByType(WindowType type) {
switch (type) {
case WindowType.Main:
return [0];
return [kMainWindowId];
case WindowType.RemoteDesktop:
return _remoteDesktopWindows;
case WindowType.FileTransfer:

View File

@ -125,7 +125,18 @@ impl<T: InvokeUiSession> Remote<T> {
.await
{
Ok((mut peer, direct, pk)) => {
self.handler.set_connection_type(peer.is_secured(), direct); // flutter -> connection_ready
let is_secured = peer.is_secured();
#[cfg(feature = "flutter")]
#[cfg(not(any(target_os = "android", target_os = "ios")))]
{
self.handler
.cache_flutter
.write()
.unwrap()
.is_secured_direct
.replace((is_secured, direct));
}
self.handler.set_connection_type(is_secured, direct); // flutter -> connection_ready
self.handler.update_direct(Some(direct));
if conn_type == ConnType::DEFAULT_CONN {
self.handler

View File

@ -526,5 +526,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Sort tags", ""),
("Separate remote window", ""),
("separate window", ""),
("Split", ""),
].iter().cloned().collect();
}

View File

@ -526,5 +526,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Sort tags", "对标签进行排序"),
("Separate remote window", "使用独立远程窗口"),
("separate window", "独立窗口"),
("Split", "拆分"),
].iter().cloned().collect();
}

View File

@ -526,5 +526,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Sort tags", ""),
("Separate remote window", ""),
("separate window", ""),
("Split", ""),
].iter().cloned().collect();
}

View File

@ -526,5 +526,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Sort tags", ""),
("Separate remote window", ""),
("separate window", ""),
("Split", ""),
].iter().cloned().collect();
}

View File

@ -526,5 +526,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Sort tags", "Tags sortieren"),
("Separate remote window", ""),
("separate window", ""),
("Split", ""),
].iter().cloned().collect();
}

View File

@ -526,5 +526,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Sort tags", ""),
("Separate remote window", ""),
("separate window", ""),
("Split", ""),
].iter().cloned().collect();
}

View File

@ -526,5 +526,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Sort tags", ""),
("Separate remote window", ""),
("separate window", ""),
("Split", ""),
].iter().cloned().collect();
}

View File

@ -526,5 +526,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Sort tags", "Ordenar etiquetas"),
("Separate remote window", ""),
("separate window", ""),
("Split", ""),
].iter().cloned().collect();
}

View File

@ -526,5 +526,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Sort tags", ""),
("Separate remote window", ""),
("separate window", ""),
("Split", ""),
].iter().cloned().collect();
}

View File

@ -526,5 +526,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Sort tags", ""),
("Separate remote window", ""),
("separate window", ""),
("Split", ""),
].iter().cloned().collect();
}

View File

@ -526,5 +526,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Sort tags", ""),
("Separate remote window", ""),
("separate window", ""),
("Split", ""),
].iter().cloned().collect();
}

View File

@ -526,5 +526,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Sort tags", ""),
("Separate remote window", ""),
("separate window", ""),
("Split", ""),
].iter().cloned().collect();
}

View File

@ -526,5 +526,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Sort tags", "Ordina etichette"),
("Separate remote window", ""),
("separate window", ""),
("Split", ""),
].iter().cloned().collect();
}

View File

@ -526,5 +526,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Sort tags", ""),
("Separate remote window", ""),
("separate window", ""),
("Split", ""),
].iter().cloned().collect();
}

View File

@ -526,5 +526,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Sort tags", ""),
("Separate remote window", ""),
("separate window", ""),
("Split", ""),
].iter().cloned().collect();
}

View File

@ -526,5 +526,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Sort tags", ""),
("Separate remote window", ""),
("separate window", ""),
("Split", ""),
].iter().cloned().collect();
}

View File

@ -526,5 +526,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Sort tags", ""),
("Separate remote window", ""),
("separate window", ""),
("Split", ""),
].iter().cloned().collect();
}

View File

@ -526,5 +526,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Sort tags", "Labels sorteren"),
("Separate remote window", ""),
("separate window", ""),
("Split", ""),
].iter().cloned().collect();
}

View File

@ -526,5 +526,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Sort tags", ""),
("Separate remote window", ""),
("separate window", ""),
("Split", ""),
].iter().cloned().collect();
}

View File

@ -526,5 +526,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Sort tags", ""),
("Separate remote window", ""),
("separate window", ""),
("Split", ""),
].iter().cloned().collect();
}

View File

@ -526,5 +526,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Sort tags", ""),
("Separate remote window", ""),
("separate window", ""),
("Split", ""),
].iter().cloned().collect();
}

View File

@ -526,5 +526,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Sort tags", ""),
("Separate remote window", ""),
("separate window", ""),
("Split", ""),
].iter().cloned().collect();
}

View File

@ -526,5 +526,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Sort tags", "Сортировка меток"),
("Separate remote window", ""),
("separate window", ""),
("Split", ""),
].iter().cloned().collect();
}

View File

@ -526,5 +526,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Sort tags", ""),
("Separate remote window", ""),
("separate window", ""),
("Split", ""),
].iter().cloned().collect();
}

View File

@ -526,5 +526,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Sort tags", ""),
("Separate remote window", ""),
("separate window", ""),
("Split", ""),
].iter().cloned().collect();
}

View File

@ -526,5 +526,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Sort tags", ""),
("Separate remote window", ""),
("separate window", ""),
("Split", ""),
].iter().cloned().collect();
}

View File

@ -526,5 +526,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Sort tags", ""),
("Separate remote window", ""),
("separate window", ""),
("Split", ""),
].iter().cloned().collect();
}

View File

@ -526,5 +526,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Sort tags", ""),
("Separate remote window", ""),
("separate window", ""),
("Split", ""),
].iter().cloned().collect();
}

View File

@ -526,5 +526,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Sort tags", ""),
("Separate remote window", ""),
("separate window", ""),
("Split", ""),
].iter().cloned().collect();
}

View File

@ -526,5 +526,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Sort tags", ""),
("Separate remote window", ""),
("separate window", ""),
("Split", ""),
].iter().cloned().collect();
}

View File

@ -526,5 +526,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Sort tags", ""),
("Separate remote window", ""),
("separate window", ""),
("Split", ""),
].iter().cloned().collect();
}

View File

@ -526,5 +526,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Sort tags", ""),
("Separate remote window", ""),
("separate window", ""),
("Split", ""),
].iter().cloned().collect();
}

View File

@ -526,5 +526,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Sort tags", ""),
("Separate remote window", ""),
("separate window", ""),
("Split", ""),
].iter().cloned().collect();
}

View File

@ -526,5 +526,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Sort tags", ""),
("Separate remote window", ""),
("separate window", ""),
("Split", ""),
].iter().cloned().collect();
}

View File

@ -56,6 +56,7 @@ pub struct CacheFlutter {
pub sp: Option<SwitchDisplay>,
pub cursor_data: HashMap<u64, CursorData>,
pub cursor_id: u64,
pub is_secured_direct: Option<(bool, bool)>,
}
#[derive(Clone, Default)]
@ -1198,6 +1199,9 @@ impl<T: InvokeUiSession> Session<T> {
#[cfg(feature = "flutter")]
#[cfg(not(any(target_os = "android", target_os = "ios")))]
pub fn restore_flutter_cache(&mut self) {
if let Some((is_secured, direct)) = self.cache_flutter.read().unwrap().is_secured_direct {
self.set_connection_type(is_secured, direct);
}
let pi = self.cache_flutter.read().unwrap().pi.clone();
self.handle_peer_info(pi);
if let Some(sp) = self.cache_flutter.read().unwrap().sp.as_ref() {