Skip to content

Commit

Permalink
chore: receive_sharing_intentをv1.8.1に更新
Browse files Browse the repository at this point in the history
  • Loading branch information
4ster1sk authored and Npepperlinux committed Dec 15, 2024
1 parent b0dd5bf commit fe4e615
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 33 deletions.
61 changes: 33 additions & 28 deletions lib/view/common/sharing_intent_listener.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class SharingIntentListener extends ConsumerStatefulWidget {
class SharingIntentListenerState extends ConsumerState<SharingIntentListener> {
late final StreamSubscription<List<SharedMediaFile>>
intentDataStreamSubscription;
late final StreamSubscription<String> intentDataTextStreamSubscription;
late Iterable<Account> account = [];

@override
Expand All @@ -35,36 +34,43 @@ class SharingIntentListenerState extends ConsumerState<SharingIntentListener> {
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,
),
),
);
}
Expand All @@ -75,7 +81,6 @@ class SharingIntentListenerState extends ConsumerState<SharingIntentListener> {
@override
void dispose() {
intentDataStreamSubscription.cancel();
intentDataTextStreamSubscription.cancel();
super.dispose();
}

Expand Down
23 changes: 19 additions & 4 deletions lib/view/splash_page/splash_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,25 @@ class SplashPageState extends ConsumerState<SplashPage> {

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(
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fe4e615

Please sign in to comment.