fix: uni links failed to be invoked with --cm running on macOS

This commit is contained in:
Kingtous 2023-02-07 01:31:11 +08:00
parent b2afde4b27
commit 1426771ec9
3 changed files with 21 additions and 5 deletions

View File

@ -1292,14 +1292,24 @@ Future<bool> initUniLinks() async {
}
}
StreamSubscription? listenUniLinks() {
if (!(Platform.isWindows || Platform.isMacOS)) {
/// Listen for uni links.
///
/// * handleByFlutter: Should uni links being handled by Flutter.
///
/// Returns a [StreamSubscription] which can listen the uni links.
StreamSubscription? listenUniLinks({handleByFlutter = true}) {
if (Platform.isLinux) {
return null;
}
final sub = uriLinkStream.listen((Uri? uri) {
debugPrint("A uri was received: $uri.");
if (uri != null) {
callUniLinksUriHandler(uri);
if (handleByFlutter) {
callUniLinksUriHandler(uri);
} else {
bind.sendUrlScheme(url: uri.toString());
}
} else {
print("uni listen error: uri is empty.");
}

View File

@ -1,3 +1,4 @@
import 'dart:async';
import 'dart:convert';
import 'dart:io';
@ -31,6 +32,9 @@ int? kWindowId;
WindowType? kWindowType;
late List<String> kBootArgs;
/// Uni links.
StreamSubscription? _uniLinkSubscription;
Future<void> main(List<String> args) async {
WidgetsFlutterBinding.ensureInitialized();
debugPrint("launch args: $args");
@ -203,7 +207,7 @@ void runMultiWindow(
await restoreWindowPosition(WindowType.PortForward, windowId: kWindowId!);
break;
default:
// no such appType
// no such appType
exit(0);
}
// show window from hidden status
@ -222,6 +226,8 @@ void runConnectionManagerScreen(bool hide) async {
} else {
showCmWindow();
}
// Start the uni links handler and redirect links to Native, not for Flutter.
_uniLinkSubscription = listenUniLinks(handleByFlutter: false);
}
void showCmWindow() {

View File

@ -117,7 +117,7 @@ class PlatformFFI {
if (Platform.isLinux) {
// Start a dbus service, no need to await
_ffiBind.mainStartDbusServer();
} else if (Platform.isMacOS) {
} else if (Platform.isMacOS && isMain) {
// Start an ipc server for handling url schemes.
_ffiBind.mainStartIpcUrlServer();
}