web uni link (#9697)

Signed-off-by: 21pages <sunboeasy@gmail.com>
This commit is contained in:
21pages 2024-10-19 15:32:17 +08:00 committed by GitHub
parent 8c8a643cce
commit 1212d9fa2d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 70 additions and 3 deletions

View File

@ -2038,6 +2038,8 @@ Future<bool> restoreWindowPosition(WindowType type,
return false; return false;
} }
var webInitialLink = "";
/// Initialize uni links for macos/windows /// Initialize uni links for macos/windows
/// ///
/// [Availability] /// [Availability]
@ -2054,7 +2056,12 @@ Future<bool> initUniLinks() async {
if (initialLink == null || initialLink.isEmpty) { if (initialLink == null || initialLink.isEmpty) {
return false; return false;
} }
return handleUriLink(uriString: initialLink); if (isWeb) {
webInitialLink = initialLink;
return false;
} else {
return handleUriLink(uriString: initialLink);
}
} catch (err) { } catch (err) {
debugPrintStack(label: "$err"); debugPrintStack(label: "$err");
return false; return false;
@ -2067,7 +2074,7 @@ Future<bool> initUniLinks() async {
/// ///
/// Returns a [StreamSubscription] which can listen the uni links. /// Returns a [StreamSubscription] which can listen the uni links.
StreamSubscription? listenUniLinks({handleByFlutter = true}) { StreamSubscription? listenUniLinks({handleByFlutter = true}) {
if (isLinux) { if (isLinux || isWeb) {
return null; return null;
} }

View File

@ -162,7 +162,7 @@ void runMobileApp() async {
await Future.wait([gFFI.abModel.loadCache(), gFFI.groupModel.loadCache()]); await Future.wait([gFFI.abModel.loadCache(), gFFI.groupModel.loadCache()]);
gFFI.userModel.refreshCurrentUser(); gFFI.userModel.refreshCurrentUser();
runApp(App()); runApp(App());
if (!isWeb) await initUniLinks(); await initUniLinks();
} }
void runMultiWindow( void runMultiWindow(

View File

@ -161,6 +161,7 @@ class WebHomePage extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
stateGlobal.isInMainPage = true; stateGlobal.isInMainPage = true;
handleUnilink(context);
return Scaffold( return Scaffold(
// backgroundColor: MyTheme.grayBg, // backgroundColor: MyTheme.grayBg,
appBar: AppBar( appBar: AppBar(
@ -171,4 +172,63 @@ class WebHomePage extends StatelessWidget {
body: connectionPage, 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);
}
}
} }