diff --git a/lib/view/common/sharing_intent_listener.dart b/lib/view/common/sharing_intent_listener.dart index d892614e9..9bb74e2f9 100644 --- a/lib/view/common/sharing_intent_listener.dart +++ b/lib/view/common/sharing_intent_listener.dart @@ -26,7 +26,6 @@ class SharingIntentListener extends ConsumerStatefulWidget { class SharingIntentListenerState extends ConsumerState { late final StreamSubscription> intentDataStreamSubscription; - late final StreamSubscription intentDataTextStreamSubscription; late Iterable account = []; @override @@ -35,36 +34,43 @@ class SharingIntentListenerState extends ConsumerState { if (defaultTargetPlatform == TargetPlatform.android || defaultTargetPlatform == TargetPlatform.iOS) { intentDataStreamSubscription = - ReceiveSharingIntent.getMediaStream().listen((event) { - final items = event.map((e) => e.path).toList(); - if (account.length == 1) { - widget.router.push( - NoteCreateRoute( - initialMediaFiles: items, - initialAccount: account.first, - ), - ); - } else { - widget.router.push( - SharingAccountSelectRoute( - filePath: items, - ), - ); - } - }); - intentDataTextStreamSubscription = - ReceiveSharingIntent.getTextStream().listen((event) { + ReceiveSharingIntent.instance.getMediaStream().listen((event) { + final items = event + .where( + (e) => + e.type == SharedMediaType.image || + e.type == SharedMediaType.video || + e.type == SharedMediaType.file, + ) + .map((e) => e.path) + .toList(); + + final text = event + .where( + (e) => + e.type == SharedMediaType.text || + e.type == SharedMediaType.url, + ) + .map((e) => e.path) + .join("\n"); + if (account.length == 1) { - widget.router.push( - NoteCreateRoute( - initialText: event, - initialAccount: account.first, + unawaited( + widget.router.push( + NoteCreateRoute( + initialMediaFiles: items, + initialAccount: account.first, + initialText: text, + ), ), ); } else { - widget.router.push( - SharingAccountSelectRoute( - sharingText: event, + unawaited( + widget.router.push( + SharingAccountSelectRoute( + filePath: items, + sharingText: text, + ), ), ); } @@ -75,7 +81,6 @@ class SharingIntentListenerState extends ConsumerState { @override void dispose() { intentDataStreamSubscription.cancel(); - intentDataTextStreamSubscription.cancel(); super.dispose(); } diff --git a/lib/view/splash_page/splash_page.dart b/lib/view/splash_page/splash_page.dart index 9d5bc215a..62794e495 100644 --- a/lib/view/splash_page/splash_page.dart +++ b/lib/view/splash_page/splash_page.dart @@ -36,10 +36,25 @@ class SplashPageState extends ConsumerState { if (_isFirst) { if (Platform.isAndroid || Platform.isIOS) { - initialSharingMedias = (await ReceiveSharingIntent.getInitialMedia()) - .map((e) => e.path) - .toList(); - initialSharingText = await ReceiveSharingIntent.getInitialText() ?? ""; + initialSharingMedias = + (await ReceiveSharingIntent.instance.getInitialMedia()) + .where( + (e) => + e.type == SharedMediaType.image || + e.type == SharedMediaType.video || + e.type == SharedMediaType.file, + ) + .map((e) => e.path) + .toList(); + initialSharingText = + (await ReceiveSharingIntent.instance.getInitialMedia()) + .where( + (e) => + e.type == SharedMediaType.text || + e.type == SharedMediaType.url, + ) + .map((e) => e.path) + .join("\n"); } LicenseRegistry.addLicense( diff --git a/pubspec.yaml b/pubspec.yaml index e12e2e756..9cf72a310 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -44,7 +44,7 @@ dependencies: visibility_detector: ^0.4.0+2 percent_indicator: ^4.2.3 fl_chart: ^0.68.0 - receive_sharing_intent: 1.5.4 + receive_sharing_intent: ^1.8.1 share_plus: ^9.0.0 mfm_parser: ^1.0.3 flutter_svg: ^2.0.6