diff --git a/flutter/lib/common.dart b/flutter/lib/common.dart index 6f41aa27a..890feac6b 100644 --- a/flutter/lib/common.dart +++ b/flutter/lib/common.dart @@ -1135,10 +1135,36 @@ void checkArguments() { if (connectIndex == -1) { return; } - String? peerId = bootArgs.length < connectIndex + 1 ? null: bootArgs[connectIndex + 1]; - if (peerId != null) { - rustDeskWinManager.newRemoteDesktop(peerId); - bootArgs.removeAt(connectIndex); bootArgs.removeAt(connectIndex); + String? arg = + bootArgs.length < connectIndex + 1 ? null : bootArgs[connectIndex + 1]; + if (arg != null) { + if (arg.startsWith(kUniLinksPrefix)) { + parseRustdeskUri(arg); + } else { + // fallback to peer id + rustDeskWinManager.newRemoteDesktop(arg); + bootArgs.removeAt(connectIndex); + bootArgs.removeAt(connectIndex); + } + } +} + +/// Parse `rustdesk://` unilinks +/// +/// [Functions] +/// 1. New Connection: rustdesk://connection/new/your_peer_id +void parseRustdeskUri(String uriPath) { + final uri = Uri.tryParse(uriPath); + if (uri == null) { + print("uri is not valid: $uriPath"); + return; + } + // new connection + if (uri.authority == "connection" && uri.path.startsWith("/new/")) { + final peerId = uri.path.substring("/new/".length); + Future.delayed(Duration.zero, () { + rustDeskWinManager.newRemoteDesktop(peerId); + }); } } diff --git a/flutter/lib/consts.dart b/flutter/lib/consts.dart index ce6c93c00..056cc000c 100644 --- a/flutter/lib/consts.dart +++ b/flutter/lib/consts.dart @@ -9,6 +9,9 @@ const String kAppTypeDesktopRemote = "remote"; const String kAppTypeDesktopFileTransfer = "file transfer"; const String kAppTypeDesktopPortForward = "port forward"; +const String kUniLinksPrefix = "rustdesk://"; +const String kActionNewConnection = "connection/new/"; + const String kTabLabelHomePage = "Home"; const String kTabLabelSettingPage = "Settings"; diff --git a/flutter/lib/main.dart b/flutter/lib/main.dart index 549a07517..43f4b9c24 100644 --- a/flutter/lib/main.dart +++ b/flutter/lib/main.dart @@ -29,7 +29,7 @@ late List bootArgs; Future main(List args) async { WidgetsFlutterBinding.ensureInitialized(); debugPrint("launch args: $args"); - bootArgs = args; + bootArgs = List.from(args); if (!isDesktop) { runMobileApp(); diff --git a/flutter/lib/models/model.dart b/flutter/lib/models/model.dart index b57d1fbc1..8b4d89461 100644 --- a/flutter/lib/models/model.dart +++ b/flutter/lib/models/model.dart @@ -178,8 +178,14 @@ class FfiModel with ChangeNotifier { } else if (name == 'update_privacy_mode') { updatePrivacyMode(evt, peerId); } else if (name == 'new_connection') { - final remoteId = evt['peer_id']; - rustDeskWinManager.newRemoteDesktop(remoteId); + var arg = evt['peer_id'].toString(); + if (arg.startsWith(kUniLinksPrefix)) { + parseRustdeskUri(arg); + } else { + Future.delayed(Duration.zero, () { + rustDeskWinManager.newRemoteDesktop(arg); + }); + } } }; }