swap sharing library, simplify code
This commit is contained in:
parent
7bae610c05
commit
77f06005e5
6 changed files with 43 additions and 54 deletions
|
|
@ -19,7 +19,7 @@
|
||||||
5A4E00000000000000000008 /* ShareViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5A4E00000000000000000001 /* ShareViewController.swift */; };
|
5A4E00000000000000000008 /* ShareViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5A4E00000000000000000001 /* ShareViewController.swift */; };
|
||||||
5A4E00000000000000000009 /* MainInterface.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 5A4E00000000000000000007 /* MainInterface.storyboard */; };
|
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, ); }; };
|
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 */
|
/* End PBXBuildFile section */
|
||||||
|
|
||||||
/* Begin PBXContainerItemProxy section */
|
/* Begin PBXContainerItemProxy section */
|
||||||
|
|
@ -109,7 +109,7 @@
|
||||||
isa = PBXFrameworksBuildPhase;
|
isa = PBXFrameworksBuildPhase;
|
||||||
buildActionMask = 2147483647;
|
buildActionMask = 2147483647;
|
||||||
files = (
|
files = (
|
||||||
5A4E0000000000000000000B /* receive-sharing-intent in Frameworks */,
|
5A4E0000000000000000000B /* better-share-handler-models in Frameworks */,
|
||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
};
|
};
|
||||||
|
|
@ -245,7 +245,7 @@
|
||||||
);
|
);
|
||||||
name = ShareExtension;
|
name = ShareExtension;
|
||||||
packageProductDependencies = (
|
packageProductDependencies = (
|
||||||
5A4E00000000000000000015 /* receive-sharing-intent */,
|
5A4E00000000000000000015 /* better-share-handler-models */,
|
||||||
);
|
);
|
||||||
productName = ShareExtension;
|
productName = ShareExtension;
|
||||||
productReference = 5A4E00000000000000000005 /* ShareExtension.appex */;
|
productReference = 5A4E00000000000000000005 /* ShareExtension.appex */;
|
||||||
|
|
@ -285,7 +285,7 @@
|
||||||
mainGroup = 97C146E51CF9000F007C117D;
|
mainGroup = 97C146E51CF9000F007C117D;
|
||||||
packageReferences = (
|
packageReferences = (
|
||||||
781AD8BC2B33823900A9FFBB /* XCLocalSwiftPackageReference "FlutterGeneratedPluginSwiftPackage" */,
|
781AD8BC2B33823900A9FFBB /* XCLocalSwiftPackageReference "FlutterGeneratedPluginSwiftPackage" */,
|
||||||
5A4E00000000000000000014 /* XCLocalSwiftPackageReference "receive_sharing_intent" */,
|
5A4E00000000000000000014 /* XCLocalSwiftPackageReference "better_share_handler" */,
|
||||||
);
|
);
|
||||||
productRefGroup = 97C146EF1CF9000F007C117D /* Products */;
|
productRefGroup = 97C146EF1CF9000F007C117D /* Products */;
|
||||||
projectDirPath = "";
|
projectDirPath = "";
|
||||||
|
|
@ -474,7 +474,7 @@
|
||||||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
||||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||||
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
|
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
|
||||||
MTL_ENABLE_DEBUG_INFO = NO;
|
MTL_ENABLE_DEBUG_INFO = NO;
|
||||||
SDKROOT = iphoneos;
|
SDKROOT = iphoneos;
|
||||||
SUPPORTED_PLATFORMS = iphoneos;
|
SUPPORTED_PLATFORMS = iphoneos;
|
||||||
|
|
@ -602,7 +602,7 @@
|
||||||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
||||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||||
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
|
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
|
||||||
MTL_ENABLE_DEBUG_INFO = YES;
|
MTL_ENABLE_DEBUG_INFO = YES;
|
||||||
ONLY_ACTIVE_ARCH = YES;
|
ONLY_ACTIVE_ARCH = YES;
|
||||||
SDKROOT = iphoneos;
|
SDKROOT = iphoneos;
|
||||||
|
|
@ -653,7 +653,7 @@
|
||||||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
||||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||||
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
|
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
|
||||||
MTL_ENABLE_DEBUG_INFO = NO;
|
MTL_ENABLE_DEBUG_INFO = NO;
|
||||||
SDKROOT = iphoneos;
|
SDKROOT = iphoneos;
|
||||||
SUPPORTED_PLATFORMS = iphoneos;
|
SUPPORTED_PLATFORMS = iphoneos;
|
||||||
|
|
@ -721,7 +721,7 @@
|
||||||
DEVELOPMENT_TEAM = PK66NJM372;
|
DEVELOPMENT_TEAM = PK66NJM372;
|
||||||
GENERATE_INFOPLIST_FILE = YES;
|
GENERATE_INFOPLIST_FILE = YES;
|
||||||
INFOPLIST_FILE = ShareExtension/Info.plist;
|
INFOPLIST_FILE = ShareExtension/Info.plist;
|
||||||
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
|
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
|
||||||
LD_RUNPATH_SEARCH_PATHS = (
|
LD_RUNPATH_SEARCH_PATHS = (
|
||||||
"$(inherited)",
|
"$(inherited)",
|
||||||
"@executable_path/Frameworks",
|
"@executable_path/Frameworks",
|
||||||
|
|
@ -748,7 +748,7 @@
|
||||||
DEVELOPMENT_TEAM = PK66NJM372;
|
DEVELOPMENT_TEAM = PK66NJM372;
|
||||||
GENERATE_INFOPLIST_FILE = YES;
|
GENERATE_INFOPLIST_FILE = YES;
|
||||||
INFOPLIST_FILE = ShareExtension/Info.plist;
|
INFOPLIST_FILE = ShareExtension/Info.plist;
|
||||||
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
|
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
|
||||||
LD_RUNPATH_SEARCH_PATHS = (
|
LD_RUNPATH_SEARCH_PATHS = (
|
||||||
"$(inherited)",
|
"$(inherited)",
|
||||||
"@executable_path/Frameworks",
|
"@executable_path/Frameworks",
|
||||||
|
|
@ -775,7 +775,7 @@
|
||||||
DEVELOPMENT_TEAM = PK66NJM372;
|
DEVELOPMENT_TEAM = PK66NJM372;
|
||||||
GENERATE_INFOPLIST_FILE = YES;
|
GENERATE_INFOPLIST_FILE = YES;
|
||||||
INFOPLIST_FILE = ShareExtension/Info.plist;
|
INFOPLIST_FILE = ShareExtension/Info.plist;
|
||||||
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
|
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
|
||||||
LD_RUNPATH_SEARCH_PATHS = (
|
LD_RUNPATH_SEARCH_PATHS = (
|
||||||
"$(inherited)",
|
"$(inherited)",
|
||||||
"@executable_path/Frameworks",
|
"@executable_path/Frameworks",
|
||||||
|
|
@ -842,9 +842,9 @@
|
||||||
isa = XCLocalSwiftPackageReference;
|
isa = XCLocalSwiftPackageReference;
|
||||||
relativePath = Flutter/ephemeral/Packages/FlutterGeneratedPluginSwiftPackage;
|
relativePath = Flutter/ephemeral/Packages/FlutterGeneratedPluginSwiftPackage;
|
||||||
};
|
};
|
||||||
5A4E00000000000000000014 /* XCLocalSwiftPackageReference "receive_sharing_intent" */ = {
|
5A4E00000000000000000014 /* XCLocalSwiftPackageReference "better_share_handler" */ = {
|
||||||
isa = XCLocalSwiftPackageReference;
|
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 */
|
/* End XCLocalSwiftPackageReference section */
|
||||||
|
|
||||||
|
|
@ -853,10 +853,10 @@
|
||||||
isa = XCSwiftPackageProductDependency;
|
isa = XCSwiftPackageProductDependency;
|
||||||
productName = FlutterGeneratedPluginSwiftPackage;
|
productName = FlutterGeneratedPluginSwiftPackage;
|
||||||
};
|
};
|
||||||
5A4E00000000000000000015 /* receive-sharing-intent */ = {
|
5A4E00000000000000000015 /* better-share-handler-models */ = {
|
||||||
isa = XCSwiftPackageProductDependency;
|
isa = XCSwiftPackageProductDependency;
|
||||||
package = 5A4E00000000000000000014 /* XCLocalSwiftPackageReference "receive_sharing_intent" */;
|
package = 5A4E00000000000000000014 /* XCLocalSwiftPackageReference "better_share_handler" */;
|
||||||
productName = "receive-sharing-intent";
|
productName = "better-share-handler-models";
|
||||||
};
|
};
|
||||||
/* End XCSwiftPackageProductDependency section */
|
/* End XCSwiftPackageProductDependency section */
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -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
|
// Saves what was shared to the App Group, then opens Nexus, which asks which
|
||||||
// room to send it to. See ShareRequestController.
|
// room to send it to. See ShareRequestController.
|
||||||
class ShareViewController: RSIShareViewController {}
|
class ShareViewController: ShareHandlerIosViewController {}
|
||||||
|
|
|
||||||
|
|
@ -1,27 +1,21 @@
|
||||||
import "dart:io";
|
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:flutter_riverpod/flutter_riverpod.dart";
|
||||||
import "package:receive_sharing_intent/receive_sharing_intent.dart";
|
|
||||||
|
|
||||||
class ShareRequestController extends Notifier<IList<SharedMediaFile>?> {
|
class ShareRequestController extends Notifier<SharedMedia?> {
|
||||||
@override
|
@override
|
||||||
IList<SharedMediaFile>? build() {
|
SharedMedia? build() {
|
||||||
if (!(Platform.isAndroid || Platform.isIOS)) return null;
|
if (!(Platform.isAndroid || Platform.isIOS)) return null;
|
||||||
|
|
||||||
void receive(List<SharedMediaFile> files) {
|
final sharing = ShareHandler.instance;
|
||||||
final shared = files
|
final subscription = sharing.sharedMediaStream.listen(
|
||||||
// Android reports opened Matrix links as URLs too, which
|
(media) => state = media,
|
||||||
// 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);
|
|
||||||
ref.onDispose(subscription.cancel);
|
ref.onDispose(subscription.cancel);
|
||||||
sharing.getInitialMedia().then(receive).ignore();
|
sharing.getInitialSharedMedia().then((media) {
|
||||||
|
if (media != null) state = media;
|
||||||
|
}).ignore();
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
@ -29,11 +23,11 @@ class ShareRequestController extends Notifier<IList<SharedMediaFile>?> {
|
||||||
void consume() {
|
void consume() {
|
||||||
state = null;
|
state = null;
|
||||||
// So the same share isn't received again once the app is reopened
|
// So the same share isn't received again once the app is reopened
|
||||||
ReceiveSharingIntent.instance.reset().ignore();
|
ShareHandler.instance.resetInitialSharedMedia().ignore();
|
||||||
}
|
}
|
||||||
|
|
||||||
static final provider =
|
static final provider =
|
||||||
NotifierProvider<ShareRequestController, IList<SharedMediaFile>?>(
|
NotifierProvider<ShareRequestController, SharedMedia?>(
|
||||||
ShareRequestController.new,
|
ShareRequestController.new,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
import "dart:io";
|
import "package:better_share_handler/better_share_handler.dart";
|
||||||
|
|
||||||
import "package:collection/collection.dart";
|
import "package:collection/collection.dart";
|
||||||
import "package:fast_immutable_collections/fast_immutable_collections.dart";
|
import "package:fast_immutable_collections/fast_immutable_collections.dart";
|
||||||
import "package:file_selector/file_selector.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/main.dart";
|
||||||
import "package:nexus/models/composer_params.dart";
|
import "package:nexus/models/composer_params.dart";
|
||||||
import "package:nexus/widgets/avatars/avatar_or_hash.dart";
|
import "package:nexus/widgets/avatars/avatar_or_hash.dart";
|
||||||
import "package:receive_sharing_intent/receive_sharing_intent.dart";
|
|
||||||
|
|
||||||
class const ShareSheet(final IList<SharedMediaFile> files, {super.key})
|
class const ShareSheet(final SharedMedia media, {super.key})
|
||||||
extends HookConsumerWidget {
|
extends HookConsumerWidget {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
|
|
@ -42,12 +40,9 @@ class const ShareSheet(final IList<SharedMediaFile> files, {super.key})
|
||||||
(room) => [(room.name, 2), (room.canonicalAlias, 1)],
|
(room) => [(room.name, 2), (room.canonicalAlias, 1)],
|
||||||
);
|
);
|
||||||
|
|
||||||
bool isText(SharedMediaFile file) =>
|
final text = media.content ?? "";
|
||||||
file.type == .url ||
|
// The composer takes one attachment
|
||||||
(file.type == .text && !File(file.path).existsSync());
|
final file = media.attachments?.nonNulls.firstOrNull;
|
||||||
|
|
||||||
final text = files.where(isText).map((file) => file.path).join("\n");
|
|
||||||
final file = files.firstWhereOrNull((file) => !isText(file));
|
|
||||||
|
|
||||||
Future<void> shareTo(String roomId) async {
|
Future<void> shareTo(String roomId) async {
|
||||||
final container = ProviderScope.containerOf(context);
|
final container = ProviderScope.containerOf(context);
|
||||||
|
|
|
||||||
16
pubspec.lock
16
pubspec.lock
|
|
@ -225,6 +225,14 @@ packages:
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.5.1"
|
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:
|
boolean_selector:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|
@ -1394,14 +1402,6 @@ packages:
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "3.2.2"
|
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:
|
record_use:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|
|
||||||
|
|
@ -120,7 +120,7 @@ dependencies:
|
||||||
path: packages/location
|
path: packages/location
|
||||||
better_player: 1.38.0
|
better_player: 1.38.0
|
||||||
audioplayers: 6.8.1
|
audioplayers: 6.8.1
|
||||||
receive_sharing_intent: 1.9.0
|
better_share_handler: 1.1.1
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue