From 1212d9fa2df6b0f5d2e1970e1a0e4743dc95b4a7 Mon Sep 17 00:00:00 2001 From: 21pages Date: Sat, 19 Oct 2024 15:32:17 +0800 Subject: [PATCH] web uni link (#9697) Signed-off-by: 21pages --- flutter/lib/common.dart | 11 ++++- flutter/lib/main.dart | 2 +- flutter/lib/mobile/pages/home_page.dart | 60 +++++++++++++++++++++++++ 3 files changed, 70 insertions(+), 3 deletions(-) diff --git a/flutter/lib/common.dart b/flutter/lib/common.dart index 8bf8cb056..1d59d0202 100644 --- a/flutter/lib/common.dart +++ b/flutter/lib/common.dart @@ -2038,6 +2038,8 @@ Future restoreWindowPosition(WindowType type, return false; } +var webInitialLink = ""; + /// Initialize uni links for macos/windows /// /// [Availability] @@ -2054,7 +2056,12 @@ Future initUniLinks() async { if (initialLink == null || initialLink.isEmpty) { return false; } - return handleUriLink(uriString: initialLink); + if (isWeb) { + webInitialLink = initialLink; + return false; + } else { + return handleUriLink(uriString: initialLink); + } } catch (err) { debugPrintStack(label: "$err"); return false; @@ -2067,7 +2074,7 @@ Future initUniLinks() async { /// /// Returns a [StreamSubscription] which can listen the uni links. StreamSubscription? listenUniLinks({handleByFlutter = true}) { - if (isLinux) { + if (isLinux || isWeb) { return null; } diff --git a/flutter/lib/main.dart b/flutter/lib/main.dart index 16324c0e5..00afbb001 100644 --- a/flutter/lib/main.dart +++ b/flutter/lib/main.dart @@ -162,7 +162,7 @@ void runMobileApp() async { await Future.wait([gFFI.abModel.loadCache(), gFFI.groupModel.loadCache()]); gFFI.userModel.refreshCurrentUser(); runApp(App()); - if (!isWeb) await initUniLinks(); + await initUniLinks(); } void runMultiWindow( diff --git a/flutter/lib/mobile/pages/home_page.dart b/flutter/lib/mobile/pages/home_page.dart index bad569afe..efccc5de6 100644 --- a/flutter/lib/mobile/pages/home_page.dart +++ b/flutter/lib/mobile/pages/home_page.dart @@ -161,6 +161,7 @@ class WebHomePage extends StatelessWidget { @override Widget build(BuildContext context) { stateGlobal.isInMainPage = true; + handleUnilink(context); return Scaffold( // backgroundColor: MyTheme.grayBg, appBar: AppBar( @@ -171,4 +172,63 @@ class WebHomePage extends StatelessWidget { body: connectionPage, ); } + + handleUnilink(BuildContext context) { + if (webInitialLink.isEmpty) { + return; + } + final link = webInitialLink; + webInitialLink = ''; + final splitter = ["/#/", "/#", "#/", "#"]; + var fakelink = ''; + for (var s in splitter) { + if (link.contains(s)) { + var list = link.split(s); + if (list.length < 2 || list[1].isEmpty) { + return; + } + list.removeAt(0); + fakelink = "rustdesk://${list.join(s)}"; + break; + } + } + if (fakelink.isEmpty) { + return; + } + final uri = Uri.tryParse(fakelink); + if (uri == null) { + return; + } + final args = urlLinkToCmdArgs(uri); + if (args == null || args.isEmpty) { + return; + } + bool isFileTransfer = false; + String? id; + String? password; + for (int i = 0; i < args.length; i++) { + switch (args[i]) { + case '--connect': + case '--play': + isFileTransfer = false; + id = args[i + 1]; + i++; + break; + case '--file-transfer': + isFileTransfer = true; + id = args[i + 1]; + i++; + break; + case '--password': + password = args[i + 1]; + i++; + break; + default: + break; + } + } + if (id != null) { + connect(context, id, isFileTransfer: isFileTransfer, password: password); + } + } }