refact, separate remote window, connect(separate window)

Signed-off-by: dignow <linlong1265@gmail.com>
This commit is contained in:
dignow 2023-08-02 23:10:31 +08:00
parent 688ecef4cc
commit 1a8463015f
39 changed files with 146 additions and 42 deletions

View File

@ -1515,7 +1515,8 @@ Future<Offset?> _adjustRestoreMainWindowOffset(
/// Restore window position and size on start
/// Note that windowId must be provided if it's subwindow
Future<bool> restoreWindowPosition(WindowType type, {int? windowId, String? peerId}) async {
Future<bool> restoreWindowPosition(WindowType type,
{int? windowId, String? peerId}) async {
if (bind
.mainGetEnv(key: "DISABLE_RUSTDESK_RESTORE_WINDOW_POSITION")
.isNotEmpty) {
@ -1529,11 +1530,11 @@ Future<bool> restoreWindowPosition(WindowType type, {int? windowId, String? peer
String? pos;
if (type == WindowType.RemoteDesktop && windowId != null && peerId != null) {
pos = await bind.sessionGetFlutterConfigByPeerId(id: peerId, k: kWindowPrefix);
pos = await bind.sessionGetFlutterConfigByPeerId(
id: peerId, k: kWindowPrefix);
}
pos ??= bind.getLocalFlutterConfig(k: kWindowPrefix + type.name);
var lpos = LastWindowPosition.loadFromString(pos);
if (lpos == null) {
debugPrint("no window position saved, ignoring position restoration");
@ -1781,17 +1782,20 @@ List<String>? urlLinkToCmdArgs(Uri uri) {
return null;
}
connectMainDesktop(String id,
{required bool isFileTransfer,
required bool isTcpTunneling,
required bool isRDP,
bool? forceRelay}) async {
connectMainDesktop(
String id, {
required bool isFileTransfer,
required bool isTcpTunneling,
required bool isRDP,
bool? forceRelay,
bool forceSeparateWindow = false,
}) async {
if (isFileTransfer) {
await rustDeskWinManager.newFileTransfer(id, forceRelay: forceRelay);
} else if (isTcpTunneling || isRDP) {
await rustDeskWinManager.newPortForward(id, isRDP, forceRelay: forceRelay);
} else {
await rustDeskWinManager.newRemoteDesktop(id, forceRelay: forceRelay);
await rustDeskWinManager.newRemoteDesktop(id, forceRelay: forceRelay, forceSeparateWindow: forceSeparateWindow);
}
}
@ -1799,10 +1803,14 @@ connectMainDesktop(String id,
/// If [isFileTransfer], starts a session only for file transfer.
/// If [isTcpTunneling], starts a session only for tcp tunneling.
/// If [isRDP], starts a session only for rdp.
connect(BuildContext context, String id,
{bool isFileTransfer = false,
bool isTcpTunneling = false,
bool isRDP = false}) async {
connect(
BuildContext context,
String id, {
bool isFileTransfer = false,
bool isTcpTunneling = false,
bool isRDP = false,
bool forceSeparateWindow = false,
}) async {
if (id == '') return;
id = id.replaceAll(' ', '');
final oldId = id;
@ -1813,18 +1821,22 @@ connect(BuildContext context, String id,
if (isDesktop) {
if (desktopType == DesktopType.main) {
await connectMainDesktop(id,
isFileTransfer: isFileTransfer,
isTcpTunneling: isTcpTunneling,
isRDP: isRDP,
forceRelay: forceRelay);
await connectMainDesktop(
id,
isFileTransfer: isFileTransfer,
isTcpTunneling: isTcpTunneling,
isRDP: isRDP,
forceRelay: forceRelay,
forceSeparateWindow: forceSeparateWindow,
);
} else {
await rustDeskWinManager.call(WindowType.Main, kWindowConnect, {
'id': id,
'isFileTransfer': isFileTransfer,
'isTcpTunneling': isTcpTunneling,
'isRDP': isRDP,
"forceRelay": forceRelay,
'forceRelay': forceRelay,
'forceSeparateWindow': forceSeparateWindow,
});
}
} else {

View File

@ -399,10 +399,14 @@ abstract class BasePeerCard extends StatelessWidget {
Future<List<MenuEntryBase<String>>> _buildMenuItems(BuildContext context);
MenuEntryBase<String> _connectCommonAction(
BuildContext context, String id, String title,
{bool isFileTransfer = false,
bool isTcpTunneling = false,
bool isRDP = false}) {
BuildContext context,
String id,
String title, {
bool isFileTransfer = false,
bool isTcpTunneling = false,
bool isRDP = false,
bool forceSeparateWindow = false,
}) {
return MenuEntryButton<String>(
childBuilder: (TextStyle? style) => Text(
title,
@ -415,6 +419,7 @@ abstract class BasePeerCard extends StatelessWidget {
isFileTransfer: isFileTransfer,
isTcpTunneling: isTcpTunneling,
isRDP: isRDP,
forceSeparateWindow: forceSeparateWindow,
);
},
padding: menuPadding,
@ -423,13 +428,26 @@ abstract class BasePeerCard extends StatelessWidget {
}
@protected
MenuEntryBase<String> _connectAction(BuildContext context, Peer peer) {
List<MenuEntryBase<String>> _connectActions(BuildContext context, Peer peer) {
final actions = [_connectAction(context, peer, false)];
if (!mainGetLocalBoolOptionSync(kOptionSeparateRemoteWindow)) {
actions.add(_connectAction(context, peer, true));
}
return actions;
}
@protected
MenuEntryBase<String> _connectAction(
BuildContext context, Peer peer, bool forceSeparateWindow) {
return _connectCommonAction(
context,
peer.id,
peer.alias.isEmpty
? translate('Connect')
: "${translate('Connect')} ${peer.id}");
context,
peer.id,
(peer.alias.isEmpty
? translate('Connect')
: '${translate('Connect')} ${peer.id}') +
(forceSeparateWindow ? ' (${translate('separate window')})' : ''),
forceSeparateWindow: forceSeparateWindow,
);
}
@protected
@ -796,7 +814,7 @@ class RecentPeerCard extends BasePeerCard {
Future<List<MenuEntryBase<String>>> _buildMenuItems(
BuildContext context) async {
final List<MenuEntryBase<String>> menuItems = [
_connectAction(context, peer),
..._connectActions(context, peer),
_transferFileAction(context, peer.id),
];
@ -852,7 +870,7 @@ class FavoritePeerCard extends BasePeerCard {
Future<List<MenuEntryBase<String>>> _buildMenuItems(
BuildContext context) async {
final List<MenuEntryBase<String>> menuItems = [
_connectAction(context, peer),
..._connectActions(context, peer),
_transferFileAction(context, peer.id),
];
if (isDesktop && peer.platform != 'Android') {
@ -902,7 +920,7 @@ class DiscoveredPeerCard extends BasePeerCard {
Future<List<MenuEntryBase<String>>> _buildMenuItems(
BuildContext context) async {
final List<MenuEntryBase<String>> menuItems = [
_connectAction(context, peer),
..._connectActions(context, peer),
_transferFileAction(context, peer.id),
];
@ -954,7 +972,7 @@ class AddressBookPeerCard extends BasePeerCard {
Future<List<MenuEntryBase<String>>> _buildMenuItems(
BuildContext context) async {
final List<MenuEntryBase<String>> menuItems = [
_connectAction(context, peer),
..._connectActions(context, peer),
_transferFileAction(context, peer.id),
];
if (isDesktop && peer.platform != 'Android') {
@ -1016,7 +1034,7 @@ class MyGroupPeerCard extends BasePeerCard {
Future<List<MenuEntryBase<String>>> _buildMenuItems(
BuildContext context) async {
final List<MenuEntryBase<String>> menuItems = [
_connectAction(context, peer),
..._connectActions(context, peer),
_transferFileAction(context, peer.id),
];
if (isDesktop && peer.platform != 'Android') {

View File

@ -556,7 +556,7 @@ class _DesktopHomePageState extends State<DesktopHomePage>
} else if (call.method == kWindowEventHide) {
final wId = call.arguments['id'];
final isSeparateWindowEnabled =
mainGetBoolOptionSync(kOptionSeparateRemoteWindow);
mainGetLocalBoolOptionSync(kOptionSeparateRemoteWindow);
if (isSeparateWindowEnabled && !kCloseMultiWindowByHide) {
await rustDeskWinManager.destroyWindow(wId);
}
@ -568,6 +568,7 @@ class _DesktopHomePageState extends State<DesktopHomePage>
isTcpTunneling: call.arguments['isTcpTunneling'],
isRDP: call.arguments['isRDP'],
forceRelay: call.arguments['forceRelay'],
forceSeparateWindow: call.arguments['forceSeparateWindow'],
);
}
});

View File

@ -112,7 +112,7 @@ class _RemotePageState extends State<RemotePage>
Wakelock.enable();
}
// Register texture.
if (mainGetBoolOptionSync(kOptionSeparateRemoteWindow)) {
if (mainGetLocalBoolOptionSync(kOptionSeparateRemoteWindow)) {
_renderTexture = renderTexture;
} else {
_renderTexture = RenderTexture();

View File

@ -52,6 +52,7 @@ class RustDeskMultiWindowManager {
bool? forceRelay,
String? switchUuid,
bool? isRDP,
bool forceSeparateWindow = false,
}) async {
var params = {
"type": type.index,
@ -70,7 +71,9 @@ class RustDeskMultiWindowManager {
newSessionWindow() async {
final windowController = await DesktopMultiWindow.createWindow(msg);
windowController
..setFrame(const Offset(0, 0) & Size(1280 + windowController.windowId * 20, 720 + windowController.windowId * 20))
..setFrame(const Offset(0, 0) &
Size(1280 + windowController.windowId * 20,
720 + windowController.windowId * 20))
..center()
..setTitle(getWindowNameWithId(
remoteId,
@ -84,8 +87,9 @@ class RustDeskMultiWindowManager {
}
// separate window for file transfer is not supported
bool separateWindow = type != WindowType.FileTransfer &&
mainGetBoolOptionSync(kOptionSeparateRemoteWindow);
bool separateWindow = forceSeparateWindow ||
(type != WindowType.FileTransfer &&
mainGetLocalBoolOptionSync(kOptionSeparateRemoteWindow));
if (windows.length > 1 || separateWindow) {
for (final windowId in windows) {
@ -123,6 +127,7 @@ class RustDeskMultiWindowManager {
String? password,
String? switchUuid,
bool? forceRelay,
bool forceSeparateWindow = false,
}) async {
return await newSession(
WindowType.RemoteDesktop,
@ -132,6 +137,7 @@ class RustDeskMultiWindowManager {
password: password,
forceRelay: forceRelay,
switchUuid: switchUuid,
forceSeparateWindow: forceSeparateWindow,
);
}
@ -165,8 +171,7 @@ class RustDeskMultiWindowManager {
if (wnds.isEmpty) {
return;
}
return await DesktopMultiWindow.invokeMethod(
wnds[0], methodName, args);
return await DesktopMultiWindow.invokeMethod(wnds[0], methodName, args);
}
List<int> _findWindowsByType(WindowType type) {

View File

@ -524,5 +524,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("exceed_max_devices", ""),
("Sync with recent sessions", ""),
("Sort tags", ""),
("Separate remote window", ""),
("separate window", ""),
].iter().cloned().collect();
}

View File

@ -524,5 +524,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("exceed_max_devices", "管理的设备数已达到最大值"),
("Sync with recent sessions", "同步最近会话"),
("Sort tags", "对标签进行排序"),
("Separate remote window", "使用独立远程窗口"),
("separate window", "独立窗口"),
].iter().cloned().collect();
}

View File

@ -524,5 +524,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("exceed_max_devices", ""),
("Sync with recent sessions", ""),
("Sort tags", ""),
("Separate remote window", ""),
("separate window", ""),
].iter().cloned().collect();
}

View File

@ -524,5 +524,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("exceed_max_devices", ""),
("Sync with recent sessions", ""),
("Sort tags", ""),
("Separate remote window", ""),
("separate window", ""),
].iter().cloned().collect();
}

View File

@ -524,5 +524,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("exceed_max_devices", "Sie haben die maximale Anzahl der verwalteten Geräte erreicht."),
("Sync with recent sessions", "Synchronisierung mit den letzten Sitzungen"),
("Sort tags", "Tags sortieren"),
("Separate remote window", ""),
("separate window", ""),
].iter().cloned().collect();
}

View File

@ -524,5 +524,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("exceed_max_devices", ""),
("Sync with recent sessions", ""),
("Sort tags", ""),
("Separate remote window", ""),
("separate window", ""),
].iter().cloned().collect();
}

View File

@ -524,5 +524,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("exceed_max_devices", ""),
("Sync with recent sessions", ""),
("Sort tags", ""),
("Separate remote window", ""),
("separate window", ""),
].iter().cloned().collect();
}

View File

@ -524,5 +524,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("exceed_max_devices", "Has alcanzado el máximo número de dispositivos administrados."),
("Sync with recent sessions", "Sincronizar con sesiones recientes"),
("Sort tags", "Ordenar etiquetas"),
("Separate remote window", ""),
("separate window", ""),
].iter().cloned().collect();
}

View File

@ -524,5 +524,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("exceed_max_devices", ""),
("Sync with recent sessions", ""),
("Sort tags", ""),
("Separate remote window", ""),
("separate window", ""),
].iter().cloned().collect();
}

View File

@ -524,5 +524,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("exceed_max_devices", ""),
("Sync with recent sessions", ""),
("Sort tags", ""),
("Separate remote window", ""),
("separate window", ""),
].iter().cloned().collect();
}

View File

@ -524,5 +524,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("exceed_max_devices", ""),
("Sync with recent sessions", ""),
("Sort tags", ""),
("Separate remote window", ""),
("separate window", ""),
].iter().cloned().collect();
}

View File

@ -524,5 +524,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("exceed_max_devices", ""),
("Sync with recent sessions", ""),
("Sort tags", ""),
("Separate remote window", ""),
("separate window", ""),
].iter().cloned().collect();
}

View File

@ -524,5 +524,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("exceed_max_devices", "Hai raggiunto il numero massimo di dispositivi gestibili."),
("Sync with recent sessions", "Sincronizza con le sessioni recenti"),
("Sort tags", "Ordina etichette"),
("Separate remote window", ""),
("separate window", ""),
].iter().cloned().collect();
}

View File

@ -524,5 +524,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("exceed_max_devices", ""),
("Sync with recent sessions", ""),
("Sort tags", ""),
("Separate remote window", ""),
("separate window", ""),
].iter().cloned().collect();
}

View File

@ -524,5 +524,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("exceed_max_devices", ""),
("Sync with recent sessions", ""),
("Sort tags", ""),
("Separate remote window", ""),
("separate window", ""),
].iter().cloned().collect();
}

View File

@ -524,5 +524,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("exceed_max_devices", ""),
("Sync with recent sessions", ""),
("Sort tags", ""),
("Separate remote window", ""),
("separate window", ""),
].iter().cloned().collect();
}

View File

@ -524,5 +524,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("exceed_max_devices", ""),
("Sync with recent sessions", ""),
("Sort tags", ""),
("Separate remote window", ""),
("separate window", ""),
].iter().cloned().collect();
}

View File

@ -524,5 +524,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("exceed_max_devices", "Het maximum aantal gecontroleerde apparaten is bereikt."),
("Sync with recent sessions", "Recente sessies synchroniseren"),
("Sort tags", "Labels sorteren"),
("Separate remote window", ""),
("separate window", ""),
].iter().cloned().collect();
}

View File

@ -524,5 +524,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("exceed_max_devices", ""),
("Sync with recent sessions", ""),
("Sort tags", ""),
("Separate remote window", ""),
("separate window", ""),
].iter().cloned().collect();
}

View File

@ -524,5 +524,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("exceed_max_devices", ""),
("Sync with recent sessions", ""),
("Sort tags", ""),
("Separate remote window", ""),
("separate window", ""),
].iter().cloned().collect();
}

View File

@ -524,5 +524,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("exceed_max_devices", ""),
("Sync with recent sessions", ""),
("Sort tags", ""),
("Separate remote window", ""),
("separate window", ""),
].iter().cloned().collect();
}

View File

@ -524,5 +524,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("exceed_max_devices", ""),
("Sync with recent sessions", ""),
("Sort tags", ""),
("Separate remote window", ""),
("separate window", ""),
].iter().cloned().collect();
}

View File

@ -524,5 +524,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("exceed_max_devices", "Достигнуто максимальне количество управляемых устройств."),
("Sync with recent sessions", "Синхронизация последних сессий"),
("Sort tags", "Сортировка меток"),
("Separate remote window", ""),
("separate window", ""),
].iter().cloned().collect();
}

View File

@ -524,5 +524,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("exceed_max_devices", ""),
("Sync with recent sessions", ""),
("Sort tags", ""),
("Separate remote window", ""),
("separate window", ""),
].iter().cloned().collect();
}

View File

@ -524,5 +524,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("exceed_max_devices", ""),
("Sync with recent sessions", ""),
("Sort tags", ""),
("Separate remote window", ""),
("separate window", ""),
].iter().cloned().collect();
}

View File

@ -524,5 +524,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("exceed_max_devices", ""),
("Sync with recent sessions", ""),
("Sort tags", ""),
("Separate remote window", ""),
("separate window", ""),
].iter().cloned().collect();
}

View File

@ -524,5 +524,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("exceed_max_devices", ""),
("Sync with recent sessions", ""),
("Sort tags", ""),
("Separate remote window", ""),
("separate window", ""),
].iter().cloned().collect();
}

View File

@ -524,5 +524,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("exceed_max_devices", ""),
("Sync with recent sessions", ""),
("Sort tags", ""),
("Separate remote window", ""),
("separate window", ""),
].iter().cloned().collect();
}

View File

@ -524,5 +524,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("exceed_max_devices", ""),
("Sync with recent sessions", ""),
("Sort tags", ""),
("Separate remote window", ""),
("separate window", ""),
].iter().cloned().collect();
}

View File

@ -524,5 +524,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("exceed_max_devices", ""),
("Sync with recent sessions", ""),
("Sort tags", ""),
("Separate remote window", ""),
("separate window", ""),
].iter().cloned().collect();
}

View File

@ -524,5 +524,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("exceed_max_devices", ""),
("Sync with recent sessions", ""),
("Sort tags", ""),
("Separate remote window", ""),
("separate window", ""),
].iter().cloned().collect();
}

View File

@ -524,5 +524,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("exceed_max_devices", ""),
("Sync with recent sessions", ""),
("Sort tags", ""),
("Separate remote window", ""),
("separate window", ""),
].iter().cloned().collect();
}

View File

@ -524,5 +524,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("exceed_max_devices", ""),
("Sync with recent sessions", ""),
("Sort tags", ""),
("Separate remote window", ""),
("separate window", ""),
].iter().cloned().collect();
}

View File

@ -524,5 +524,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("exceed_max_devices", ""),
("Sync with recent sessions", ""),
("Sort tags", ""),
("Separate remote window", ""),
("separate window", ""),
].iter().cloned().collect();
}