mirror of
https://github.com/weyne85/rustdesk.git
synced 2025-10-29 17:00:05 +00:00
Merge pull request #3196 from 21pages/relay_id
force relay when id is suffixed with "/r"
This commit is contained in:
@@ -1405,13 +1405,14 @@ bool callUniLinksUriHandler(Uri uri) {
|
||||
connectMainDesktop(String id,
|
||||
{required bool isFileTransfer,
|
||||
required bool isTcpTunneling,
|
||||
required bool isRDP}) async {
|
||||
required bool isRDP,
|
||||
bool? forceRelay}) async {
|
||||
if (isFileTransfer) {
|
||||
await rustDeskWinManager.newFileTransfer(id);
|
||||
await rustDeskWinManager.newFileTransfer(id, forceRelay: forceRelay);
|
||||
} else if (isTcpTunneling || isRDP) {
|
||||
await rustDeskWinManager.newPortForward(id, isRDP);
|
||||
await rustDeskWinManager.newPortForward(id, isRDP, forceRelay: forceRelay);
|
||||
} else {
|
||||
await rustDeskWinManager.newRemoteDesktop(id);
|
||||
await rustDeskWinManager.newRemoteDesktop(id, forceRelay: forceRelay);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1422,7 +1423,8 @@ connectMainDesktop(String id,
|
||||
connect(BuildContext context, String id,
|
||||
{bool isFileTransfer = false,
|
||||
bool isTcpTunneling = false,
|
||||
bool isRDP = false}) async {
|
||||
bool isRDP = false,
|
||||
bool forceRelay = false}) async {
|
||||
if (id == '') return;
|
||||
id = id.replaceAll(' ', '');
|
||||
assert(!(isFileTransfer && isTcpTunneling && isRDP),
|
||||
@@ -1430,18 +1432,18 @@ connect(BuildContext context, String id,
|
||||
|
||||
if (isDesktop) {
|
||||
if (desktopType == DesktopType.main) {
|
||||
await connectMainDesktop(
|
||||
id,
|
||||
isFileTransfer: isFileTransfer,
|
||||
isTcpTunneling: isTcpTunneling,
|
||||
isRDP: isRDP,
|
||||
);
|
||||
await connectMainDesktop(id,
|
||||
isFileTransfer: isFileTransfer,
|
||||
isTcpTunneling: isTcpTunneling,
|
||||
isRDP: isRDP,
|
||||
forceRelay: forceRelay);
|
||||
} else {
|
||||
await rustDeskWinManager.call(WindowType.Main, kWindowConnect, {
|
||||
'id': id,
|
||||
'isFileTransfer': isFileTransfer,
|
||||
'isTcpTunneling': isTcpTunneling,
|
||||
'isRDP': isRDP,
|
||||
"forceRelay": forceRelay,
|
||||
});
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -66,7 +66,8 @@ class _ConnectionPageState extends State<ConnectionPage>
|
||||
_idFocusNode.addListener(() {
|
||||
_idInputFocused.value = _idFocusNode.hasFocus;
|
||||
// select all to faciliate removing text, just following the behavior of address input of chrome
|
||||
_idController.selection = TextSelection(baseOffset: 0, extentOffset: _idController.value.text.length);
|
||||
_idController.selection = TextSelection(
|
||||
baseOffset: 0, extentOffset: _idController.value.text.length);
|
||||
});
|
||||
windowManager.addListener(this);
|
||||
}
|
||||
@@ -149,8 +150,11 @@ class _ConnectionPageState extends State<ConnectionPage>
|
||||
/// Callback for the connect button.
|
||||
/// Connects to the selected peer.
|
||||
void onConnect({bool isFileTransfer = false}) {
|
||||
final id = _idController.id;
|
||||
connect(context, id, isFileTransfer: isFileTransfer);
|
||||
var id = _idController.id;
|
||||
var forceRelay = id.endsWith(r'/r');
|
||||
if (forceRelay) id = id.substring(0, id.length - 2);
|
||||
connect(context, id,
|
||||
isFileTransfer: isFileTransfer, forceRelay: forceRelay);
|
||||
}
|
||||
|
||||
/// UI for the remote ID TextField.
|
||||
|
||||
@@ -557,6 +557,7 @@ class _DesktopHomePageState extends State<DesktopHomePage>
|
||||
isFileTransfer: call.arguments['isFileTransfer'],
|
||||
isTcpTunneling: call.arguments['isTcpTunneling'],
|
||||
isRDP: call.arguments['isRDP'],
|
||||
forceRelay: call.arguments['forceRelay'],
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -46,8 +46,10 @@ enum MouseFocusScope {
|
||||
}
|
||||
|
||||
class FileManagerPage extends StatefulWidget {
|
||||
const FileManagerPage({Key? key, required this.id}) : super(key: key);
|
||||
const FileManagerPage({Key? key, required this.id, this.forceRelay})
|
||||
: super(key: key);
|
||||
final String id;
|
||||
final bool? forceRelay;
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() => _FileManagerPageState();
|
||||
@@ -102,7 +104,7 @@ class _FileManagerPageState extends State<FileManagerPage>
|
||||
void initState() {
|
||||
super.initState();
|
||||
_ffi = FFI();
|
||||
_ffi.start(widget.id, isFileTransfer: true);
|
||||
_ffi.start(widget.id, isFileTransfer: true, forceRelay: widget.forceRelay);
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
_ffi.dialogManager
|
||||
.showLoading(translate('Connecting...'), onCancel: closeConnection);
|
||||
|
||||
@@ -41,7 +41,11 @@ class _FileManagerTabPageState extends State<FileManagerTabPage> {
|
||||
selectedIcon: selectedIcon,
|
||||
unselectedIcon: unselectedIcon,
|
||||
onTabCloseButton: () => () => tabController.closeBy(params['id']),
|
||||
page: FileManagerPage(key: ValueKey(params['id']), id: params['id'])));
|
||||
page: FileManagerPage(
|
||||
key: ValueKey(params['id']),
|
||||
id: params['id'],
|
||||
forceRelay: params['forceRelay'],
|
||||
)));
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -64,7 +68,11 @@ class _FileManagerTabPageState extends State<FileManagerTabPage> {
|
||||
selectedIcon: selectedIcon,
|
||||
unselectedIcon: unselectedIcon,
|
||||
onTabCloseButton: () => tabController.closeBy(id),
|
||||
page: FileManagerPage(key: ValueKey(id), id: id)));
|
||||
page: FileManagerPage(
|
||||
key: ValueKey(id),
|
||||
id: id,
|
||||
forceRelay: args['forceRelay'],
|
||||
)));
|
||||
} else if (call.method == "onDestroy") {
|
||||
tabController.clear();
|
||||
} else if (call.method == kWindowActionRebuild) {
|
||||
|
||||
@@ -26,10 +26,12 @@ class _PortForward {
|
||||
}
|
||||
|
||||
class PortForwardPage extends StatefulWidget {
|
||||
const PortForwardPage({Key? key, required this.id, required this.isRDP})
|
||||
const PortForwardPage(
|
||||
{Key? key, required this.id, required this.isRDP, this.forceRelay})
|
||||
: super(key: key);
|
||||
final String id;
|
||||
final bool isRDP;
|
||||
final bool? forceRelay;
|
||||
|
||||
@override
|
||||
State<PortForwardPage> createState() => _PortForwardPageState();
|
||||
@@ -47,7 +49,7 @@ class _PortForwardPageState extends State<PortForwardPage>
|
||||
void initState() {
|
||||
super.initState();
|
||||
_ffi = FFI();
|
||||
_ffi.start(widget.id, isPortForward: true);
|
||||
_ffi.start(widget.id, isPortForward: true, forceRelay: widget.forceRelay);
|
||||
Get.put(_ffi, tag: 'pf_${widget.id}');
|
||||
if (!Platform.isLinux) {
|
||||
Wakelock.enable();
|
||||
|
||||
@@ -44,6 +44,7 @@ class _PortForwardTabPageState extends State<PortForwardTabPage> {
|
||||
key: ValueKey(params['id']),
|
||||
id: params['id'],
|
||||
isRDP: isRDP,
|
||||
forceRelay: params['forceRelay'],
|
||||
)));
|
||||
}
|
||||
|
||||
@@ -72,7 +73,12 @@ class _PortForwardTabPageState extends State<PortForwardTabPage> {
|
||||
label: id,
|
||||
selectedIcon: selectedIcon,
|
||||
unselectedIcon: unselectedIcon,
|
||||
page: PortForwardPage(id: id, isRDP: isRDP)));
|
||||
page: PortForwardPage(
|
||||
key: ValueKey(args['id']),
|
||||
id: id,
|
||||
isRDP: isRDP,
|
||||
forceRelay: args['forceRelay'],
|
||||
)));
|
||||
} else if (call.method == "onDestroy") {
|
||||
tabController.clear();
|
||||
} else if (call.method == kWindowActionRebuild) {
|
||||
|
||||
@@ -34,11 +34,13 @@ class RemotePage extends StatefulWidget {
|
||||
required this.id,
|
||||
required this.menubarState,
|
||||
this.switchUuid,
|
||||
this.forceRelay,
|
||||
}) : super(key: key);
|
||||
|
||||
final String id;
|
||||
final MenubarState menubarState;
|
||||
final String? switchUuid;
|
||||
final bool? forceRelay;
|
||||
final SimpleWrapper<State<RemotePage>?> _lastState = SimpleWrapper(null);
|
||||
|
||||
FFI get ffi => (_lastState.value! as _RemotePageState)._ffi;
|
||||
@@ -107,6 +109,7 @@ class _RemotePageState extends State<RemotePage>
|
||||
_ffi.start(
|
||||
widget.id,
|
||||
switchUuid: widget.switchUuid,
|
||||
forceRelay: widget.forceRelay,
|
||||
);
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: []);
|
||||
|
||||
@@ -73,6 +73,7 @@ class _ConnectionTabPageState extends State<ConnectionTabPage> {
|
||||
id: peerId,
|
||||
menubarState: _menubarState,
|
||||
switchUuid: params['switch_uuid'],
|
||||
forceRelay: params['forceRelay'],
|
||||
),
|
||||
));
|
||||
_update_remote_count();
|
||||
@@ -107,6 +108,7 @@ class _ConnectionTabPageState extends State<ConnectionTabPage> {
|
||||
id: id,
|
||||
menubarState: _menubarState,
|
||||
switchUuid: switchUuid,
|
||||
forceRelay: args['forceRelay'],
|
||||
),
|
||||
));
|
||||
} else if (call.method == "onDestroy") {
|
||||
|
||||
@@ -298,6 +298,8 @@ class FfiModel with ChangeNotifier {
|
||||
showWaitUacDialog(id, dialogManager, type);
|
||||
} else if (type == 'elevation-error') {
|
||||
showElevationError(id, type, title, text, dialogManager);
|
||||
} else if (type == "relay-hint") {
|
||||
showRelayHintDialog(id, type, title, text, dialogManager);
|
||||
} else {
|
||||
var hasRetry = evt['hasRetry'] == 'true';
|
||||
showMsgBox(id, type, title, text, link, hasRetry, dialogManager);
|
||||
@@ -312,7 +314,7 @@ class FfiModel with ChangeNotifier {
|
||||
_timer?.cancel();
|
||||
if (hasRetry) {
|
||||
_timer = Timer(Duration(seconds: _reconnects), () {
|
||||
bind.sessionReconnect(id: id);
|
||||
bind.sessionReconnect(id: id, forceRelay: false);
|
||||
clearPermissions();
|
||||
dialogManager.showLoading(translate('Connecting...'),
|
||||
onCancel: closeConnection);
|
||||
@@ -323,6 +325,44 @@ class FfiModel with ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
void showRelayHintDialog(String id, String type, String title, String text,
|
||||
OverlayDialogManager dialogManager) {
|
||||
dialogManager.show(tag: '$id-$type', (setState, close) {
|
||||
onClose() {
|
||||
closeConnection();
|
||||
close();
|
||||
}
|
||||
|
||||
reconnect(bool forceRelay) {
|
||||
bind.sessionReconnect(id: id, forceRelay: forceRelay);
|
||||
clearPermissions();
|
||||
dialogManager.showLoading(translate('Connecting...'),
|
||||
onCancel: closeConnection);
|
||||
}
|
||||
|
||||
final style =
|
||||
ElevatedButton.styleFrom(backgroundColor: Colors.green[700]);
|
||||
return CustomAlertDialog(
|
||||
title: null,
|
||||
content: msgboxContent(type, title,
|
||||
"${translate(text)}\n\n${translate('relay_hint_tip')}"),
|
||||
actions: [
|
||||
dialogButton('Close', onPressed: onClose, isOutline: true),
|
||||
dialogButton('Retry', onPressed: () => reconnect(false)),
|
||||
dialogButton('Connect via relay',
|
||||
onPressed: () => reconnect(true), buttonStyle: style),
|
||||
dialogButton('Always connect via relay', onPressed: () {
|
||||
const option = 'force-always-relay';
|
||||
bind.sessionPeerOption(
|
||||
id: id, name: option, value: bool2option(option, true));
|
||||
reconnect(true);
|
||||
}, buttonStyle: style),
|
||||
],
|
||||
onCancel: onClose,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
/// Handle the peer info event based on [evt].
|
||||
handlePeerInfo(Map<String, dynamic> evt, String peerId) async {
|
||||
// recent peer updated by handle_peer_info(ui_session_interface.rs) --> handle_peer_info(client.rs) --> save_config(client.rs)
|
||||
@@ -1341,7 +1381,8 @@ class FFI {
|
||||
void start(String id,
|
||||
{bool isFileTransfer = false,
|
||||
bool isPortForward = false,
|
||||
String? switchUuid}) {
|
||||
String? switchUuid,
|
||||
bool? forceRelay}) {
|
||||
assert(!(isFileTransfer && isPortForward), 'more than one connect type');
|
||||
if (isFileTransfer) {
|
||||
connType = ConnType.fileTransfer;
|
||||
@@ -1357,11 +1398,11 @@ class FFI {
|
||||
}
|
||||
// ignore: unused_local_variable
|
||||
final addRes = bind.sessionAddSync(
|
||||
id: id,
|
||||
isFileTransfer: isFileTransfer,
|
||||
isPortForward: isPortForward,
|
||||
switchUuid: switchUuid ?? "",
|
||||
);
|
||||
id: id,
|
||||
isFileTransfer: isFileTransfer,
|
||||
isPortForward: isPortForward,
|
||||
switchUuid: switchUuid ?? "",
|
||||
forceRelay: forceRelay ?? false);
|
||||
final stream = bind.sessionStart(id: id);
|
||||
final cb = ffiModel.startEventListener(id);
|
||||
() async {
|
||||
|
||||
@@ -41,11 +41,15 @@ class RustDeskMultiWindowManager {
|
||||
int? _fileTransferWindowId;
|
||||
int? _portForwardWindowId;
|
||||
|
||||
Future<dynamic> newRemoteDesktop(String remoteId,
|
||||
{String? switch_uuid}) async {
|
||||
Future<dynamic> newRemoteDesktop(
|
||||
String remoteId, {
|
||||
String? switch_uuid,
|
||||
bool? forceRelay,
|
||||
}) async {
|
||||
var params = {
|
||||
"type": WindowType.RemoteDesktop.index,
|
||||
"id": remoteId,
|
||||
"forceRelay": forceRelay
|
||||
};
|
||||
if (switch_uuid != null) {
|
||||
params['switch_uuid'] = switch_uuid;
|
||||
@@ -78,9 +82,12 @@ class RustDeskMultiWindowManager {
|
||||
}
|
||||
}
|
||||
|
||||
Future<dynamic> newFileTransfer(String remoteId) async {
|
||||
final msg =
|
||||
jsonEncode({"type": WindowType.FileTransfer.index, "id": remoteId});
|
||||
Future<dynamic> newFileTransfer(String remoteId, {bool? forceRelay}) async {
|
||||
var msg = jsonEncode({
|
||||
"type": WindowType.FileTransfer.index,
|
||||
"id": remoteId,
|
||||
"forceRelay": forceRelay,
|
||||
});
|
||||
|
||||
try {
|
||||
final ids = await DesktopMultiWindow.getAllSubWindowIds();
|
||||
@@ -107,9 +114,14 @@ class RustDeskMultiWindowManager {
|
||||
}
|
||||
}
|
||||
|
||||
Future<dynamic> newPortForward(String remoteId, bool isRDP) async {
|
||||
final msg = jsonEncode(
|
||||
{"type": WindowType.PortForward.index, "id": remoteId, "isRDP": isRDP});
|
||||
Future<dynamic> newPortForward(String remoteId, bool isRDP,
|
||||
{bool? forceRelay}) async {
|
||||
final msg = jsonEncode({
|
||||
"type": WindowType.PortForward.index,
|
||||
"id": remoteId,
|
||||
"isRDP": isRDP,
|
||||
"forceRelay": forceRelay,
|
||||
});
|
||||
|
||||
try {
|
||||
final ids = await DesktopMultiWindow.getAllSubWindowIds();
|
||||
|
||||
Reference in New Issue
Block a user