From 77f06005e5cbce5b789cfce67046f63c86aec92f Mon Sep 17 00:00:00 2001 From: Henry-Hiles Date: Thu, 26 Nov 2026 01:06:47 -0500 Subject: [PATCH] swap sharing library, simplify code --- ios/Runner.xcodeproj/project.pbxproj | 30 ++++++++++---------- ios/ShareExtension/ShareViewController.swift | 4 +-- lib/controllers/share_request.dart | 30 ++++++++------------ lib/widgets/rooms/share_sheet.dart | 15 ++++------ pubspec.lock | 16 +++++------ pubspec.yaml | 2 +- 6 files changed, 43 insertions(+), 54 deletions(-) diff --git a/ios/Runner.xcodeproj/project.pbxproj b/ios/Runner.xcodeproj/project.pbxproj index ebe6013..0fe5f5c 100644 --- a/ios/Runner.xcodeproj/project.pbxproj +++ b/ios/Runner.xcodeproj/project.pbxproj @@ -19,7 +19,7 @@ 5A4E00000000000000000008 /* ShareViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5A4E00000000000000000001 /* ShareViewController.swift */; }; 5A4E00000000000000000009 /* MainInterface.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 5A4E00000000000000000007 /* MainInterface.storyboard */; }; 5A4E0000000000000000000A /* ShareExtension.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = 5A4E00000000000000000005 /* ShareExtension.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; - 5A4E0000000000000000000B /* receive-sharing-intent in Frameworks */ = {isa = PBXBuildFile; productRef = 5A4E00000000000000000015 /* receive-sharing-intent */; }; + 5A4E0000000000000000000B /* better-share-handler-models in Frameworks */ = {isa = PBXBuildFile; productRef = 5A4E00000000000000000015 /* better-share-handler-models */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -109,7 +109,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 5A4E0000000000000000000B /* receive-sharing-intent in Frameworks */, + 5A4E0000000000000000000B /* better-share-handler-models in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -245,7 +245,7 @@ ); name = ShareExtension; packageProductDependencies = ( - 5A4E00000000000000000015 /* receive-sharing-intent */, + 5A4E00000000000000000015 /* better-share-handler-models */, ); productName = ShareExtension; productReference = 5A4E00000000000000000005 /* ShareExtension.appex */; @@ -285,7 +285,7 @@ mainGroup = 97C146E51CF9000F007C117D; packageReferences = ( 781AD8BC2B33823900A9FFBB /* XCLocalSwiftPackageReference "FlutterGeneratedPluginSwiftPackage" */, - 5A4E00000000000000000014 /* XCLocalSwiftPackageReference "receive_sharing_intent" */, + 5A4E00000000000000000014 /* XCLocalSwiftPackageReference "better_share_handler" */, ); productRefGroup = 97C146EF1CF9000F007C117D /* Products */; projectDirPath = ""; @@ -474,7 +474,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 13.0; + IPHONEOS_DEPLOYMENT_TARGET = 14.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SUPPORTED_PLATFORMS = iphoneos; @@ -602,7 +602,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 13.0; + IPHONEOS_DEPLOYMENT_TARGET = 14.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -653,7 +653,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 13.0; + IPHONEOS_DEPLOYMENT_TARGET = 14.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SUPPORTED_PLATFORMS = iphoneos; @@ -721,7 +721,7 @@ DEVELOPMENT_TEAM = PK66NJM372; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = ShareExtension/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 13.0; + IPHONEOS_DEPLOYMENT_TARGET = 14.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", @@ -748,7 +748,7 @@ DEVELOPMENT_TEAM = PK66NJM372; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = ShareExtension/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 13.0; + IPHONEOS_DEPLOYMENT_TARGET = 14.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", @@ -775,7 +775,7 @@ DEVELOPMENT_TEAM = PK66NJM372; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = ShareExtension/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 13.0; + IPHONEOS_DEPLOYMENT_TARGET = 14.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", @@ -842,9 +842,9 @@ isa = XCLocalSwiftPackageReference; relativePath = Flutter/ephemeral/Packages/FlutterGeneratedPluginSwiftPackage; }; - 5A4E00000000000000000014 /* XCLocalSwiftPackageReference "receive_sharing_intent" */ = { + 5A4E00000000000000000014 /* XCLocalSwiftPackageReference "better_share_handler" */ = { isa = XCLocalSwiftPackageReference; - relativePath = "Flutter/ephemeral/Packages/.packages/receive_sharing_intent-1.9.0"; + relativePath = "Flutter/ephemeral/Packages/.packages/better_share_handler-1.1.1"; }; /* End XCLocalSwiftPackageReference section */ @@ -853,10 +853,10 @@ isa = XCSwiftPackageProductDependency; productName = FlutterGeneratedPluginSwiftPackage; }; - 5A4E00000000000000000015 /* receive-sharing-intent */ = { + 5A4E00000000000000000015 /* better-share-handler-models */ = { isa = XCSwiftPackageProductDependency; - package = 5A4E00000000000000000014 /* XCLocalSwiftPackageReference "receive_sharing_intent" */; - productName = "receive-sharing-intent"; + package = 5A4E00000000000000000014 /* XCLocalSwiftPackageReference "better_share_handler" */; + productName = "better-share-handler-models"; }; /* End XCSwiftPackageProductDependency section */ }; diff --git a/ios/ShareExtension/ShareViewController.swift b/ios/ShareExtension/ShareViewController.swift index 40809ea..76f4931 100644 --- a/ios/ShareExtension/ShareViewController.swift +++ b/ios/ShareExtension/ShareViewController.swift @@ -1,5 +1,5 @@ -import receive_sharing_intent +import better_share_handler_models // Saves what was shared to the App Group, then opens Nexus, which asks which // room to send it to. See ShareRequestController. -class ShareViewController: RSIShareViewController {} +class ShareViewController: ShareHandlerIosViewController {} diff --git a/lib/controllers/share_request.dart b/lib/controllers/share_request.dart index 6919167..ce7a9ca 100644 --- a/lib/controllers/share_request.dart +++ b/lib/controllers/share_request.dart @@ -1,27 +1,21 @@ import "dart:io"; -import "package:fast_immutable_collections/fast_immutable_collections.dart"; +import "package:better_share_handler/better_share_handler.dart"; import "package:flutter_riverpod/flutter_riverpod.dart"; -import "package:receive_sharing_intent/receive_sharing_intent.dart"; -class ShareRequestController extends Notifier?> { +class ShareRequestController extends Notifier { @override - IList? build() { + SharedMedia? build() { if (!(Platform.isAndroid || Platform.isIOS)) return null; - void receive(List files) { - final shared = files - // Android reports opened Matrix links as URLs too, which - // LinkRequestController handles - .where((file) => !(Platform.isAndroid && file.type == .url)) - .toIList(); - if (shared.isNotEmpty) state = shared; - } - - final sharing = ReceiveSharingIntent.instance; - final subscription = sharing.getMediaStream().listen(receive); + final sharing = ShareHandler.instance; + final subscription = sharing.sharedMediaStream.listen( + (media) => state = media, + ); ref.onDispose(subscription.cancel); - sharing.getInitialMedia().then(receive).ignore(); + sharing.getInitialSharedMedia().then((media) { + if (media != null) state = media; + }).ignore(); return null; } @@ -29,11 +23,11 @@ class ShareRequestController extends Notifier?> { void consume() { state = null; // So the same share isn't received again once the app is reopened - ReceiveSharingIntent.instance.reset().ignore(); + ShareHandler.instance.resetInitialSharedMedia().ignore(); } static final provider = - NotifierProvider?>( + NotifierProvider( ShareRequestController.new, ); } diff --git a/lib/widgets/rooms/share_sheet.dart b/lib/widgets/rooms/share_sheet.dart index ecd2df6..d448194 100644 --- a/lib/widgets/rooms/share_sheet.dart +++ b/lib/widgets/rooms/share_sheet.dart @@ -1,5 +1,4 @@ -import "dart:io"; - +import "package:better_share_handler/better_share_handler.dart"; import "package:collection/collection.dart"; import "package:fast_immutable_collections/fast_immutable_collections.dart"; import "package:file_selector/file_selector.dart"; @@ -17,9 +16,8 @@ import "package:nexus/helpers/extensions/weighted_search.dart"; import "package:nexus/main.dart"; import "package:nexus/models/composer_params.dart"; import "package:nexus/widgets/avatars/avatar_or_hash.dart"; -import "package:receive_sharing_intent/receive_sharing_intent.dart"; -class const ShareSheet(final IList files, {super.key}) +class const ShareSheet(final SharedMedia media, {super.key}) extends HookConsumerWidget { @override Widget build(BuildContext context, WidgetRef ref) { @@ -42,12 +40,9 @@ class const ShareSheet(final IList files, {super.key}) (room) => [(room.name, 2), (room.canonicalAlias, 1)], ); - bool isText(SharedMediaFile file) => - file.type == .url || - (file.type == .text && !File(file.path).existsSync()); - - final text = files.where(isText).map((file) => file.path).join("\n"); - final file = files.firstWhereOrNull((file) => !isText(file)); + final text = media.content ?? ""; + // The composer takes one attachment + final file = media.attachments?.nonNulls.firstOrNull; Future shareTo(String roomId) async { final container = ProviderScope.containerOf(context); diff --git a/pubspec.lock b/pubspec.lock index ee3b70e..a9cf736 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -225,6 +225,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.5.1" + better_share_handler: + dependency: "direct main" + description: + name: better_share_handler + sha256: "20af88c551b5c76fdaadb053a8cffe2cc0d5da56c8e7b847642a512c4f6ae293" + url: "https://pub.dev" + source: hosted + version: "1.1.1" boolean_selector: dependency: transitive description: @@ -1394,14 +1402,6 @@ packages: url: "https://pub.dev" source: hosted version: "3.2.2" - receive_sharing_intent: - dependency: "direct main" - description: - name: receive_sharing_intent - sha256: "72f229a38f2910029c11d840770c173b27072e348ef3376130b37514bc4556f6" - url: "https://pub.dev" - source: hosted - version: "1.9.0" record_use: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 464f300..3407eae 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -120,7 +120,7 @@ dependencies: path: packages/location better_player: 1.38.0 audioplayers: 6.8.1 - receive_sharing_intent: 1.9.0 + better_share_handler: 1.1.1 dev_dependencies: flutter_test: sdk: flutter